@@ -83,22 +83,19 @@ class GLM4_5AgentTemplate(BaseAgentTemplate):
83
83
@staticmethod
84
84
def _find_function_call (single_content : str ) -> Optional ['Function' ]:
85
85
from swift .llm .infer import Function
86
- single_content = single_content .replace ('<tool_call>' , '' ).strip ()
87
86
func_name_match = re .match (r'^([^\n<]+)' , single_content )
88
87
if not func_name_match :
89
88
return None
90
89
func_name = func_name_match .group (1 ).strip ()
91
- arg_key_pattern = re .compile (r'<arg_key>(.*?)</arg_key>' , re .DOTALL )
92
- arg_value_pattern = re .compile (r'<arg_value>(.*?)</arg_value>' , re .DOTALL )
93
- keys = arg_key_pattern .findall (single_content )
94
- values = arg_value_pattern .findall (single_content )
90
+ keys = re .findall (r'<arg_key>(.*?)</arg_key>' , single_content , re .DOTALL )
91
+ values = re .findall (r'<arg_value>(.*?)</arg_value>' , single_content , re .DOTALL )
95
92
if len (keys ) != len (values ):
96
93
return None
97
94
args = {k .strip (): v .strip () for k , v in zip (keys , values )}
98
95
return Function (name = func_name , arguments = json .dumps (args , ensure_ascii = False ))
99
96
100
97
def get_toolcall (self , response : str ) -> List ['Function' ]:
101
- toolcall_list = response . replace ( '<|observation|>' , '' ). split ( ' </tool_call>' )
98
+ toolcall_list = re . findall ( r'<tool_call>(.*?) </tool_call>', response , re . DOTALL )
102
99
functions = []
103
100
for toolcall in toolcall_list :
104
101
function = self ._find_function_call (toolcall )
0 commit comments