MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / func

Method func

bmtools/agent/apitool.py:63–84  ·  view source on GitHub ↗
(json_args)

Source from the content-addressed store, hash-verified

61 url = root_url + func_url
62
63 def func(json_args):
64 if isinstance(json_args, str):
65 try:
66 json_args = json.loads(json_args)
67 except:
68 return "Your input can not be parsed as json, please use thought."
69 if "tool_input" in json_args:
70 json_args = json_args["tool_input"]
71
72 # if it's post put patch, then we do json
73 if method.lower() in ['post', 'put', 'patch']:
74 response = getattr(requests, method.lower())(url, json=json_args)
75 else:
76 # for other methods, we use get, and use json_args as query params
77 response = requests.get(url, params=json_args)
78 if response.status_code == 200:
79 message = response.text
80 else:
81 message = f"Error code {response.status_code}. You can try (1) Change your input (2) Call another function. (If the same error code is produced more than 4 times, please use Thought: I can not use these APIs, so I will stop. Final Answer: No Answer, please check the APIs.)"
82
83 message = message[:self.max_output_len] # TODO: not rigorous, to improve
84 return message
85
86 def convert_openapi_to_params(request_body):
87 if not request_body:

Callers 1

_runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected