MCPcopy
hub / github.com/OpenBMB/ToolBench / _step

Method _step

toolbench/inference/Downstream_tasks/rapidapi.py:286–388  ·  view source on GitHub ↗

Need to return an observation string and status code: 0 means normal response 1 means there is no corresponding api name 2 means there is an error in the input 3 represents the end of the generation and the final answer appears 4 means that

(self, action_name="", action_input="")

Source from the content-addressed store, hash-verified

284 return obs, code
285
286 def _step(self, action_name="", action_input=""):
287 """Need to return an observation string and status code:
288 0 means normal response
289 1 means there is no corresponding api name
290 2 means there is an error in the input
291 3 represents the end of the generation and the final answer appears
292 4 means that the model decides to pruning by itself
293 5 represents api call timeout
294 6 for 404
295 7 means not subscribed
296 8 represents unauthorized
297 9 represents too many requests
298 10 stands for rate limit
299 11 message contains "error" field
300 12 error sending request
301 """
302 if action_name == "Finish":
303 try:
304 json_data = json.loads(action_input,strict=False)
305 except:
306 json_data = {}
307 if '"return_type": "' in action_input:
308 if '"return_type": "give_answer"' in action_input:
309 return_type = "give_answer"
310 elif '"return_type": "give_up_and_restart"' in action_input:
311 return_type = "give_up_and_restart"
312 else:
313 return_type = action_input[action_input.find('"return_type": "')+len('"return_type": "'):action_input.find('",')]
314 json_data["return_type"] = return_type
315 if '"final_answer": "' in action_input:
316 final_answer = action_input[action_input.find('"final_answer": "')+len('"final_answer": "'):]
317 json_data["final_answer"] = final_answer
318 if "return_type" not in json_data.keys():
319 return "{error:\"must have \"return_type\"\"}", 2
320 if json_data["return_type"] == "give_up_and_restart":
321 return "{\"response\":\"chose to give up and restart\"}",4
322 elif json_data["return_type"] == "give_answer":
323 if "final_answer" not in json_data.keys():
324 return "{error:\"must have \"final_answer\"\"}", 2
325
326 self.success = 1 # succesfully return final_answer
327 return "{\"response\":\"successfully giving the final answer.\"}", 3
328 else:
329 return "{error:\"\"return_type\" is not a valid choice\"}", 2
330 else:
331
332 for k, function in enumerate(self.functions):
333 if function["name"].endswith(action_name):
334 pure_api_name = self.api_name_reflect[function["name"]]
335 payload = {
336 "category": self.cate_names[k],
337 "tool_name": self.tool_names[k],
338 "api_name": pure_api_name,
339 "tool_input": action_input,
340 "strip": self.observ_compress_method,
341 "toolbench_key": self.toolbench_key
342 }
343 if self.process_id == 0:

Callers 1

stepMethod · 0.95

Calls 1

get_rapidapi_responseFunction · 0.90

Tested by

no test coverage detected