Skip to content

Commit 39624a7

Browse files
committed
Remove broken hallucination catches
1 parent 8a6dc59 commit 39624a7

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

interpreter/core/llm/run_tool_calling_llm.py

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,35 @@ def run_tool_calling_llm(llm, request_params):
247247
else:
248248
yield {"type": "message", "content": delta["content"]}
249249

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+
250273
if (
251274
accumulated_deltas.get("function_call")
252275
and "arguments" in accumulated_deltas["function_call"]
253276
and accumulated_deltas["function_call"]["arguments"]
254277
):
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"]:
259279
arguments = accumulated_deltas["function_call"]["arguments"]
260280
arguments = parse_partial_json(arguments)
261281

@@ -285,43 +305,6 @@ def run_tool_calling_llm(llm, request_params):
285305
if llm.interpreter.verbose:
286306
print("Arguments not a dict.")
287307

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-
325308
if os.getenv("INTERPRETER_REQUIRE_AUTHENTICATION", "False").lower() == "true":
326309
print("function_call_detected", function_call_detected)
327310
print("accumulated_review", accumulated_review)

0 commit comments

Comments
 (0)