MCPcopy Create free account
hub / github.com/OpenBMB/ToolBench / rapidapi_wrapper

Class rapidapi_wrapper

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

Source from the content-addressed store, hash-verified

53
54# rapidapi env wrapper
55class rapidapi_wrapper(base_env):
56 def __init__(self, query_json, tool_descriptions, retriever, args, process_id=0):
57 super(rapidapi_wrapper).__init__()
58
59 self.tool_root_dir = args.tool_root_dir
60 self.toolbench_key = args.toolbench_key
61 self.rapidapi_key = args.rapidapi_key
62 self.use_rapidapi_key = args.use_rapidapi_key
63 self.api_customization = args.api_customization
64 self.service_url = "http://8.130.32.149:8080/rapidapi"
65 self.max_observation_length = args.max_observation_length
66 self.observ_compress_method = args.observ_compress_method
67 self.retriever = retriever
68 self.process_id = process_id
69
70 self.tool_names = []
71 self.cate_names = []
72
73 self.input_description = query_json["query"]
74 self.functions = []
75 self.api_name_reflect = {}
76
77 if self.retriever is not None:
78 query_json = self.retrieve_rapidapi_tools(self.input_description, args.retrieved_api_nums, args.tool_root_dir)
79 data_dict = self.fetch_api_json(query_json)
80 tool_descriptions = self.build_tool_description(data_dict)
81 else:
82 data_dict = self.fetch_api_json(query_json)
83
84 for k,api_json in enumerate(data_dict["api_list"]):
85 standard_tool_name = tool_descriptions[k][0]
86 openai_function_json,cate_name, pure_api_name = self.api_json_to_openai_json(api_json,standard_tool_name)
87 self.functions.append(openai_function_json)
88
89 self.api_name_reflect[openai_function_json["name"]] = pure_api_name
90 self.tool_names.append(standard_tool_name)
91 self.cate_names.append(cate_name)
92
93 finish_func = {
94 "name": "Finish",
95 "description": "If you believe that you have obtained a result that can answer the task, please call this function to provide the final answer. Alternatively, if you recognize that you are unable to proceed with the task in the current state, call this function to restart. Remember: you must ALWAYS call this function at the end of your attempt, and the only part that will be shown to the user is the final answer, so it should contain sufficient information.",
96 "parameters": {
97 "type": "object",
98 "properties": {
99 "return_type": {
100 "type": "string",
101 "enum": ["give_answer","give_up_and_restart"],
102 },
103 "final_answer": {
104 "type": "string",
105 "description": "The final answer you want to give the user. You should have this field if \"return_type\"==\"give_answer\"",
106 }
107 },
108 "required": ["return_type"],
109 }
110 }
111
112 self.functions.append(finish_func)

Callers 1

run_single_taskMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected