File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -142,10 +142,24 @@ def format_prompt_or_completion(prompt_or_completion) -> str:
142
142
else :
143
143
lines .append (f"[dim][b]{ role } :[/b] { content } [/dim]" )
144
144
if "tool_calls" in msg and msg ["tool_calls" ]:
145
- for tool_call in msg ["tool_calls" ]:
146
- lines .append (
147
- f"[b]tool call:[/b] { tool_call ['function' ]['name' ]} \n { tool_call ['function' ]['arguments' ]} "
148
- )
145
+ tool_calls_data = msg ["tool_calls" ]
146
+ if isinstance (tool_calls_data , list ) and len (tool_calls_data ) > 0 and isinstance (tool_calls_data [0 ], str ):
147
+ import json
148
+ parsed_tool_calls = []
149
+ for tc_str in tool_calls_data :
150
+ try :
151
+ parsed_tool_calls .append (json .loads (tc_str ))
152
+ except (json .JSONDecodeError , TypeError ):
153
+ parsed_tool_calls .append (tc_str )
154
+ tool_calls_data = parsed_tool_calls
155
+
156
+ for tool_call in tool_calls_data :
157
+ if isinstance (tool_call , dict ) and 'function' in tool_call :
158
+ lines .append (
159
+ f"[b]tool call:[/b] { tool_call ['function' ]['name' ]} \n { tool_call ['function' ]['arguments' ]} "
160
+ )
161
+ elif isinstance (tool_call , str ):
162
+ lines .append (f"[b]tool call:[/b] { tool_call } " )
149
163
return "\n \n " .join (lines )
150
164
return str (prompt_or_completion )
151
165
You can’t perform that action at this time.
0 commit comments