Skip to content

Commit

Permalink
Fixed KeyError from OpenInterpreter#21
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Sep 2, 2023
1 parent b5f7514 commit 5a03f72
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@ def respond(self):
})
return

# If we couldn't parse its arguments, we need to try again.
if "parsed_arguments" not in self.messages[-1]["function_call"]:
print("> Function call could not be parsed.\n\nPlease open an issue on Github (openinterpreter.com, click Github) and paste the following:")
print("\n", self.messages[-1]["function_call"], "\n")
time.sleep(2)
print("Informing the language model and continuing...")

# Reiterate what we need to the language model:
self.messages.append({
"role": "function",
"name": "run_code",
"content": """Your function call could not be parsed. Please use ONLY the `run_code` function, which takes two parameters: `code` and `language`. Your response should be formatted as a JSON."""
})

# Go around again
self.respond()
return

# Create or retrieve a Code Interpreter for this language
language = self.messages[-1]["function_call"]["parsed_arguments"][
"language"]
Expand Down

0 comments on commit 5a03f72

Please sign in to comment.