MCPcopy Create free account
hub / github.com/Mercury7353/PyBench / fc2dict

Function fc2dict

utils/output_parser.py:97–125  ·  view source on GitHub ↗
(sequence: str, spliter="<|tool_call|>")

Source from the content-addressed store, hash-verified

95 return ""
96
97def fc2dict(sequence: str, spliter="<|tool_call|>"):
98 if spliter in sequence:
99 content, tool_call_string = sequence.split(spliter, 1)
100 try:
101 # 找到第一个 { 和最后一个 }
102 start_idx = tool_call_string.find('{')
103 end_idx = tool_call_string.rfind('}')
104 if start_idx != -1 and end_idx != -1:
105 arguments_str = tool_call_string[start_idx:end_idx + 1]
106 print("Arg:",arguments_str)
107 arguments_str=arguments_str.replace("\n","\\n")
108 #code_content = extract_code_from_arguments(arguments_str)
109 tool_call_dict = {
110 "name": "execute_python",
111 "arguments": json.loads(arguments_str)
112 }
113 tool_calls = [tool_call_dict]
114 else:
115 tool_calls = []
116 return {
117 "content": content.strip(),
118 "tool_calls": tool_calls,
119 "role": "assistant",
120 }
121 except Exception as e:
122 print(f"Error: {e}")
123 return {"content": content.strip(), "role": "assistant"}
124 else:
125 return {"content": sequence.strip(), "role": "assistant"}
126
127# 示例用法
128sequence = ''&#x27;To fulfill your request, I will perform the following steps:

Callers 2

parse_code_actionFunction · 0.85
output_parser.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected