@@ -855,24 +855,23 @@ def generate_tool_calls_reply(
855
855
if messages is None :
856
856
messages = self ._oai_messages [sender ]
857
857
message = messages [- 1 ]
858
- if "tool_calls" in message and message ["tool_calls" ]:
859
- tool_calls = message ["tool_calls" ]
860
- tool_returns = []
861
- for tool_call in tool_calls :
862
- id = tool_call ["id" ]
863
- function_call = tool_call .get ("function" , {})
864
- func = self ._function_map .get (function_call .get ("name" , None ), None )
865
- if asyncio .coroutines .iscoroutinefunction (func ):
866
- continue
867
- _ , func_return = self .execute_function (function_call )
868
- tool_returns .append (
869
- {
870
- "tool_call_id" : id ,
871
- "role" : "tool" ,
872
- "name" : func_return .get ("name" , "" ),
873
- "content" : func_return .get ("content" , "" ),
874
- }
875
- )
858
+ tool_returns = []
859
+ for tool_call in message .get ("tool_calls" , []):
860
+ id = tool_call ["id" ]
861
+ function_call = tool_call .get ("function" , {})
862
+ func = self ._function_map .get (function_call .get ("name" , None ), None )
863
+ if asyncio .coroutines .iscoroutinefunction (func ):
864
+ continue
865
+ _ , func_return = self .execute_function (function_call )
866
+ tool_returns .append (
867
+ {
868
+ "tool_call_id" : id ,
869
+ "role" : "tool" ,
870
+ "name" : func_return .get ("name" , "" ),
871
+ "content" : func_return .get ("content" , "" ),
872
+ }
873
+ )
874
+ if len (tool_returns ) > 0 :
876
875
return True , {
877
876
"role" : "tool" ,
878
877
"tool_responses" : tool_returns ,
0 commit comments