tools = [ { "type": "function", "function": { "name": "run_command", "description": f"Execute shell code on the user's system. The user's current system is {client_system}, the shell is {shell}, and the path is {current_dir}. If necessary, try to use the shell to perform complex tasks (e.g., calculations). If the shell code execution fails or returns unexpected results, you can directly call this function again to try other shell code until the expected result is obtained. If there is no way to obtain the expected result, please explain it to the user.", "parameters": { "type": "object", "properties": { "command": { "type": "string", "description": f"Execute {shell} code, such as 'curl -o ./baidu.html https://www.baidu.com', allowing the use of all shell syntax and functions! This includes all potentially destructive operations!", } }, "required": [] }, } }, ]
# 检查是否需要调用函数 ifhasattr(message, "tool_calls") and message.tool_calls: for tool_call in message.tool_calls: # 解析函数调用 if tool_call.function.name == "run_command": function_args = json.loads(tool_call.function.arguments)