Skip to content

Continue to run despite unsupported language #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions interpreter/core/respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ def respond(interpreter):
language
] = create_code_interpreter(config)
code_interpreter = interpreter._code_interpreters[language]

# Yield a message, such that the user can stop code execution if they want to
try:
yield {"executing": {"code": code, "language": language}}
except GeneratorExit:
# The user might exit here.
# We need to tell python what we (the generator) should do if they exit
break

if interpreter.run_code_promt:
# Yield each line, also append it to last messages' output
interpreter.messages[-1]["output"] = ""
for line in code_interpreter.run(code):
yield line
if "output" in line:
output = interpreter.messages[-1]["output"]
output += "\n" + line["output"]

# Truncate output
output = truncate_output(output, interpreter.max_output)

interpreter.messages[-1]["output"] = output.strip()
# Vision
if "image" in line:
base64_image = line["image"]
interpreter.messages[-1][
"image"
] = f"data:image/jpeg;base64,{base64_image}"
else:
# This still prints the code but don't allow code to run. Let's Open-Interpreter know through output message
error_output = f"Error: Open Interpreter does not currently support {language}."
Expand All @@ -150,34 +178,8 @@ def respond(interpreter):
# Truncate output
output = truncate_output(output, interpreter.max_output)
interpreter.messages[-1]["output"] = output.strip()
break

# Yield a message, such that the user can stop code execution if they want to
try:
yield {"executing": {"code": code, "language": language}}
except GeneratorExit:
# The user might exit here.
# We need to tell python what we (the generator) should do if they exit
break

# Yield each line, also append it to last messages' output
interpreter.messages[-1]["output"] = ""
for line in code_interpreter.run(code):
yield line
if "output" in line:
output = interpreter.messages[-1]["output"]
output += "\n" + line["output"]

# Truncate output
output = truncate_output(output, interpreter.max_output)

interpreter.messages[-1]["output"] = output.strip()
# Vision
if "image" in line:
base64_image = line["image"]
interpreter.messages[-1][
"image"
] = f"data:image/jpeg;base64,{base64_image}"

yield {"output": output.strip()}

except:
output = traceback.format_exc()
Expand Down
10 changes: 8 additions & 2 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ def terminal_interface(interpreter, message):

scan_code(code, language, interpreter)

interpreter.run_code_promt = False
response = input(
" Would you like to run this code? (y/n)\n\n "
)
print("") # <- Aesthetic choice

if response.strip().lower() == "y":
interpreter.run_code_promt = True

if interpreter.run_code_promt:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an unnecessary condition.

We can just set the property to true and follow the code path in this condition without needing to check the value of the property we just set.

Copy link
Collaborator Author

@Notnaton Notnaton Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a second check in respond.py
We need to know if we run the code or not and disable the code_interpreter.
https://github.com/KillianLucas/open-interpreter/pull/741/files#diff-1f2d9ffe69c9b4ee7009e36234869f2a03f0af75f0bef3a1f5b8dac2acbd736eR149

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for that we need to set the interpreter.run_code_promt (which I just noticed has a typo, can we make that interpreter.run_code_prompt), but we don’t need this if statement because at this point in the code that property can only have one value because we just set it a couple of lines above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to stop it running the code regardless of y/n. It just didn't output the result when saying n.
I'll double check and come back to this after work 👍

# Create a new, identical block where the code will actually be run
# Conveniently, the chunk includes everything we need to do this:
active_block = CodeBlock()
Expand All @@ -191,10 +195,12 @@ def terminal_interface(interpreter, message):
interpreter.messages.append(
{
"role": "user",
"message": "I have declined to run this code.",
"message": "I have declined to run this code, continue with the next step.",
}
)
break
yield {
"output": "continue if not finished. User declined to run the code"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prompt here could be better, I am not good at this. This seems to work ok for 7B models

}

# Output
if "output" in chunk:
Expand Down