@@ -247,15 +247,35 @@ def run_tool_calling_llm(llm, request_params):
247
247
else :
248
248
yield {"type" : "message" , "content" : delta ["content" ]}
249
249
250
+ if (
251
+ accumulated_deltas .get ("function_call" )
252
+ and "name" in accumulated_deltas ["function_call" ]
253
+ and (
254
+ accumulated_deltas ["function_call" ]["name" ] == "python"
255
+ or accumulated_deltas ["function_call" ]["name" ] == "functions"
256
+ )
257
+ ):
258
+ if language is None :
259
+ language = "python"
260
+
261
+ # Pull the code string straight out of the "arguments" string
262
+ code_delta = accumulated_deltas ["function_call" ]["arguments" ][len (code ) :]
263
+ # Update the code
264
+ code = accumulated_deltas ["function_call" ]["arguments" ]
265
+ # Yield the delta
266
+ if code_delta :
267
+ yield {
268
+ "type" : "code" ,
269
+ "format" : language ,
270
+ "content" : code_delta ,
271
+ }
272
+
250
273
if (
251
274
accumulated_deltas .get ("function_call" )
252
275
and "arguments" in accumulated_deltas ["function_call" ]
253
276
and accumulated_deltas ["function_call" ]["arguments" ]
254
277
):
255
- if (
256
- "name" in accumulated_deltas ["function_call" ]
257
- and accumulated_deltas ["function_call" ]["name" ] == "execute"
258
- ):
278
+ if "arguments" in accumulated_deltas ["function_call" ]:
259
279
arguments = accumulated_deltas ["function_call" ]["arguments" ]
260
280
arguments = parse_partial_json (arguments )
261
281
@@ -285,43 +305,6 @@ def run_tool_calling_llm(llm, request_params):
285
305
if llm .interpreter .verbose :
286
306
print ("Arguments not a dict." )
287
307
288
- # THESE NEED TO BE UPDATED FOR TOOL CALLING!!!!
289
- # Common hallucinations
290
- elif "name" in accumulated_deltas ["function_call" ] and (
291
- accumulated_deltas ["function_call" ]["name" ] == "python"
292
- or accumulated_deltas ["function_call" ]["name" ] == "functions"
293
- ):
294
- if llm .interpreter .verbose :
295
- print ("Got direct python call" )
296
- if language is None :
297
- language = "python"
298
-
299
- if language is not None :
300
- # Pull the code string straight out of the "arguments" string
301
- code_delta = accumulated_deltas ["function_call" ]["arguments" ][
302
- len (code ) :
303
- ]
304
- # Update the code
305
- code = accumulated_deltas ["function_call" ]["arguments" ]
306
- # Yield the delta
307
- if code_delta :
308
- yield {
309
- "type" : "code" ,
310
- "format" : language ,
311
- "content" : code_delta ,
312
- }
313
-
314
- else :
315
- raise (Exception ("Can't parse tool output: " + str (accumulated_deltas )))
316
- # If name exists and it's not "execute" or "python" or "functions", who knows what's going on.
317
- if "name" in accumulated_deltas ["function_call" ]:
318
- yield {
319
- "type" : "code" ,
320
- "format" : "python" ,
321
- "content" : "ERROR" ,
322
- }
323
- return
324
-
325
308
if os .getenv ("INTERPRETER_REQUIRE_AUTHENTICATION" , "False" ).lower () == "true" :
326
309
print ("function_call_detected" , function_call_detected )
327
310
print ("accumulated_review" , accumulated_review )
0 commit comments