@@ -40,15 +40,14 @@ async def new_function(*args, **kwargs):
4040 return new_function
4141
4242
43- # Mutation on extra_params
4443def get_tools (
4544 request : Request , tool_ids : list [str ], user : UserModel , extra_params : dict
4645) -> dict [str , dict ]:
4746 tools_dict = {}
4847
4948 for tool_id in tool_ids :
50- tools = Tools .get_tool_by_id (tool_id )
51- if tools is None :
49+ tool = Tools .get_tool_by_id (tool_id )
50+ if tool is None :
5251
5352 if tool_id .startswith ("server:" ):
5453 server_idx = int (tool_id .split (":" )[1 ])
@@ -57,17 +56,17 @@ def get_tools(
5756 tool_dict = {
5857 "spec" : spec ,
5958 "callable" : callable ,
60- "toolkit_id " : tool_id ,
59+ "tool_id " : tool_id ,
6160 # Misc info
6261 "metadata" : {
6362 "file_handler" : hasattr (module , "file_handler" )
6463 and module .file_handler ,
6564 "citation" : hasattr (module , "citation" ) and module .citation ,
6665 },
6766 }
68-
67+ else :
68+ continue
6969 else :
70-
7170 module = request .app .state .TOOLS .get (tool_id , None )
7271 if module is None :
7372 module , _ = load_tools_module_by_id (tool_id )
@@ -83,7 +82,7 @@ def get_tools(
8382 ** Tools .get_user_valves_by_id_and_user_id (tool_id , user .id )
8483 )
8584
86- for spec in tools .specs :
85+ for spec in tool .specs :
8786 # TODO: Fix hack for OpenAI API
8887 # Some times breaks OpenAI but others don't. Leaving the comment
8988 for val in spec .get ("parameters" , {}).get ("properties" , {}).values ():
@@ -114,7 +113,7 @@ def get_tools(
114113 tool_dict = {
115114 "spec" : spec ,
116115 "callable" : callable ,
117- "toolkit_id " : tool_id ,
116+ "tool_id " : tool_id ,
118117 # Misc info
119118 "metadata" : {
120119 "file_handler" : hasattr (module , "file_handler" )
@@ -128,8 +127,8 @@ def get_tools(
128127 log .warning (
129128 f"Tool { function_name } already exists in another tools!"
130129 )
131- log .warning (f"Collision between { tools } and { tool_id } ." )
132- log .warning (f"Discarding { tools } .{ function_name } " )
130+ log .warning (f"Collision between { tool } and { tool_id } ." )
131+ log .warning (f"Discarding { tool } .{ function_name } " )
133132 else :
134133 tools_dict [function_name ] = tool_dict
135134
@@ -239,8 +238,9 @@ def get_callable_attributes(tool: object) -> list[Callable]:
239238
240239
241240def get_tools_specs (tool_class : object ) -> list [dict ]:
242- function_list = get_callable_attributes (tool_class )
243- function_model_list = map (function_to_pydantic_model , function_list )
241+ function_model_list = map (
242+ function_to_pydantic_model , get_callable_attributes (tool_class )
243+ )
244244 return [
245245 convert_to_openai_function (function_model )
246246 for function_model in function_model_list
0 commit comments