@@ -2131,13 +2131,15 @@ def create_completion(stop):
2131
2131
)
2132
2132
2133
2133
# TODO: support stream mode
2134
- function_call_dict : Union [Dict [str , str ], Dict [Literal ["function_call" ], llama_types .ChatCompletionRequestAssistantMessageFunctionCall ]] = {
2135
- "function_call" : {
2136
- "name" : tool_calls [0 ]["function" ]["name" ],
2137
- "arguments" : tool_calls [0 ]["function" ]["arguments" ],
2138
- } if len (tool_calls ) > 0 and tools is None else None ,
2139
- "tool_calls" : tool_calls if len (tool_calls ) > 0 and tools is not None else None ,
2140
- }
2134
+ function_call_dict : Union [Dict [str , str ], Dict [Literal ["function_call" ], llama_types .ChatCompletionRequestAssistantMessageFunctionCall ]] = {}
2135
+ if len (tool_calls ) > 0 :
2136
+ if tools is not None :
2137
+ function_call_dict ["tool_calls" ] = tool_calls
2138
+ else :
2139
+ function_call_dict ["function_call" ] = {
2140
+ "name" : tool_calls [0 ]["function" ]["name" ],
2141
+ "arguments" : tool_calls [0 ]["function" ]["arguments" ],
2142
+ }
2141
2143
completion ["usage" ]["completion_tokens" ] = completion_tokens
2142
2144
return llama_types .CreateChatCompletionResponse (
2143
2145
id = "chat" + completion ["id" ],
@@ -2151,7 +2153,6 @@ def create_completion(stop):
2151
2153
"message" : {
2152
2154
"role" : "assistant" ,
2153
2155
"content" : None if content == "" else content ,
2154
- "tool_calls" : tool_calls if tools is not None else None ,
2155
2156
** function_call_dict ,
2156
2157
},
2157
2158
"finish_reason" : "tool_calls" if len (tool_calls ) > 0 else "stop" ,
0 commit comments