Skip to content

Commit 18f0ae0

Browse files
committed
add _detect_tool on multi_role_play,fix #614
1 parent 50d63af commit 18f0ae0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

modelscope_agent/agents/multi_role_play.py

+20
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ def __init__(self, **kwargs):
122122

123123
super().__init__(**kwargs)
124124

125+
def _detect_tool(self, message: Union[str,
126+
dict]) -> Tuple[bool, str, str, str]:
127+
assert isinstance(message, str)
128+
text = message
129+
func_name, func_args = None, None
130+
i = text.rfind(ACTION_TOKEN)
131+
j = text.rfind(ARGS_TOKEN)
132+
k = text.rfind(OBSERVATION_TOKEN)
133+
if 0 <= i < j: # If the text has `Action` and `Action input`,
134+
if k < j: # but does not contain `Observation`,
135+
# then it is likely that `Observation` is ommited by the LLM,
136+
# because the output text may have discarded the stop word.
137+
text = text.rstrip() + OBSERVATION_TOKEN # Add it back.
138+
k = text.rfind(OBSERVATION_TOKEN)
139+
func_name = text[i + len(ACTION_TOKEN):j].strip()
140+
func_args = text[j + len(ARGS_TOKEN):k].strip()
141+
text = text[:k] # Discard '\nObservation:'.
142+
143+
return (func_name is not None), func_name, func_args, text
144+
125145
def _run(self,
126146
user_request,
127147
history: Optional[List[Dict]] = None,

0 commit comments

Comments
 (0)