File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -242,7 +242,25 @@ async def _handle_request(self, request: web.Request) -> web.Response:
242242
243243 for field in allowed_fields :
244244 if raw_msg .get (field ) is not None :
245- assistant_msg [field ] = raw_msg [field ]
245+ val = copy .deepcopy (raw_msg [field ])
246+ if field == "tool_calls" :
247+ for tc in val :
248+ if tc .get ("type" ) == "function" and "function" in tc :
249+ args = tc ["function" ].get ("arguments" )
250+ if isinstance (args , str ):
251+ try :
252+ tc ["function" ]["arguments" ] = json .loads (args )
253+ except json .JSONDecodeError :
254+ pass
255+ elif field == "function_call" :
256+ args = val .get ("arguments" )
257+ if isinstance (args , str ):
258+ try :
259+ val ["arguments" ] = json .loads (args )
260+ except json .JSONDecodeError :
261+ pass
262+
263+ assistant_msg [field ] = val
246264
247265 # Keep the latest conversation history
248266 messages = list (request_data ['messages' ])
You can’t perform that action at this time.
0 commit comments