Skip to content

Commit b6caf05

Browse files
authored
add _detect_tool on multi_role_play, fix #614 (#615)
1 parent 50d63af commit b6caf05

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
gradio==4.8
22
modelscope-agent==0.4.1
3-
modelscope_studio
3+
modelscope_studio==0.5.2

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)