@@ -214,7 +214,7 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
214214 other_llm_name = AGENT_LLM_MODEL [agent_name ]['llm' ] if agent_name in AGENT_LLM_MODEL and \
215215 AGENT_LLM_MODEL [agent_name ][
216216 'replace_default' ] and llm_setting is not None else use_llm_name
217- use_api_secret = llm_setting [use_llm_name ]['ApiSecret' ] if "ApiSecret" in llm_setting [use_llm_name ] else None
217+ use_api_secret = llm_setting [use_llm_name ]['ApiSecret' ] if llm_setting and "ApiSecret" in llm_setting [use_llm_name ] else None
218218 print ("Agent_name" , agent_name , 'default: llm:' , use_llm_name , "url:" , use_url , "model" , use_model , "other LLM" , other_llm_name )
219219 if other_llm_name is not None and use_llm_name != other_llm_name :
220220 use_message_count = AGENT_LLM_MODEL [agent_name ]['use_message_count' ]
@@ -303,6 +303,18 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
303303 del config ['agent_name' ]
304304 if "api_type" in config :
305305 del config ['api_type' ]
306+
307+ tools = []
308+ if "functions" in config :
309+ functions = config .pop ("functions" )
310+ for function in functions :
311+ tools .append ({
312+ "type" : "function" ,
313+ "function" : function
314+ })
315+ if len (tools ) > 0 :
316+ config ['tools' ] = tools
317+
306318 openai_completion = (
307319 openai .ChatCompletion
308320 if config ["model" ].replace ("gpt-35-turbo" , "gpt-3.5-turbo" ) in cls .chat_models
@@ -313,6 +325,14 @@ def _get_response(cls, config: Dict, raise_on_ratelimit_or_timeout=False, use_ca
313325 response = openai_completion .create (** config )
314326 else :
315327 response = openai_completion .create (request_timeout = request_timeout , ** config )
328+ if "tool_calls" in response .choices [0 ].message and len (response .choices [0 ].message .tool_calls ) > 0 :
329+ tool_calls = response .choices [0 ].message .pop ("tool_calls" )
330+ function_call = tool_calls [0 ]
331+ response .choices [0 ].message ['function_call' ] = {
332+ "name" : function_call .function .name ,
333+ "arguments" : function_call .function .arguments
334+ }
335+ response .choices [0 ]['finish_reason' ] = "function_call"
316336
317337 except (
318338 ServiceUnavailableError ,
0 commit comments