remove code runs
Browse files
InterpreterAtomicFlow.py
CHANGED
|
@@ -31,10 +31,9 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 31 |
|
| 32 |
*Output Interface*:
|
| 33 |
- `interpreter_output`: output of the code interpreter
|
| 34 |
-
- `code_runs`: whether the code runs successfully or not
|
| 35 |
|
| 36 |
*Configuration Parameters*:
|
| 37 |
-
-
|
| 38 |
|
| 39 |
**Full credits to open-interpreter (https://github.com/KillianLucas/open-interpreter)
|
| 40 |
for the usage of code interpreters (package `code_interpreters`) and the function truncate_output()**
|
|
@@ -103,7 +102,7 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 103 |
def _call(self):
|
| 104 |
""" This method runs the code interpreter and returns the output. (runs the code interpreter and returns the output.)
|
| 105 |
"""
|
| 106 |
-
|
| 107 |
output = ""
|
| 108 |
try:
|
| 109 |
code_interpreter = self._code_interpreters[self.flow_state["language"]]
|
|
@@ -111,15 +110,14 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 111 |
for line in code_interpreter.run(code):
|
| 112 |
if "output" in line:
|
| 113 |
output += "\n" + line["output"]
|
| 114 |
-
code_runs = line.get("code_runs", True)
|
| 115 |
# Truncate output
|
| 116 |
output = truncate_output(output, self.max_output)
|
| 117 |
output = output.strip()
|
| 118 |
except:
|
| 119 |
output = traceback.format_exc()
|
| 120 |
output = output.strip()
|
| 121 |
-
|
| 122 |
-
return output
|
| 123 |
|
| 124 |
def run(
|
| 125 |
self,
|
|
@@ -135,8 +133,7 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 135 |
output = self._call()
|
| 136 |
|
| 137 |
response = {
|
| 138 |
-
"interpreter_output": output
|
| 139 |
-
"code_runs": output[1]
|
| 140 |
}
|
| 141 |
|
| 142 |
reply = self.package_output_message(
|
|
|
|
| 31 |
|
| 32 |
*Output Interface*:
|
| 33 |
- `interpreter_output`: output of the code interpreter
|
|
|
|
| 34 |
|
| 35 |
*Configuration Parameters*:
|
| 36 |
+
- max_output: maximum number of characters to display in the output
|
| 37 |
|
| 38 |
**Full credits to open-interpreter (https://github.com/KillianLucas/open-interpreter)
|
| 39 |
for the usage of code interpreters (package `code_interpreters`) and the function truncate_output()**
|
|
|
|
| 102 |
def _call(self):
|
| 103 |
""" This method runs the code interpreter and returns the output. (runs the code interpreter and returns the output.)
|
| 104 |
"""
|
| 105 |
+
|
| 106 |
output = ""
|
| 107 |
try:
|
| 108 |
code_interpreter = self._code_interpreters[self.flow_state["language"]]
|
|
|
|
| 110 |
for line in code_interpreter.run(code):
|
| 111 |
if "output" in line:
|
| 112 |
output += "\n" + line["output"]
|
|
|
|
| 113 |
# Truncate output
|
| 114 |
output = truncate_output(output, self.max_output)
|
| 115 |
output = output.strip()
|
| 116 |
except:
|
| 117 |
output = traceback.format_exc()
|
| 118 |
output = output.strip()
|
| 119 |
+
|
| 120 |
+
return output
|
| 121 |
|
| 122 |
def run(
|
| 123 |
self,
|
|
|
|
| 133 |
output = self._call()
|
| 134 |
|
| 135 |
response = {
|
| 136 |
+
"interpreter_output": output,
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
reply = self.package_output_message(
|
InterpreterAtomicFlow.yaml
CHANGED
|
@@ -9,4 +9,3 @@ input_interface:
|
|
| 9 |
|
| 10 |
output_interface:
|
| 11 |
- interpreter_output
|
| 12 |
-
- code_runs
|
|
|
|
| 9 |
|
| 10 |
output_interface:
|
| 11 |
- interpreter_output
|
|
|
code_interpreters/languages/python.py
CHANGED
|
@@ -154,4 +154,4 @@ def wrap_in_try_except(code):
|
|
| 154 |
parsed_code.body = [try_except]
|
| 155 |
|
| 156 |
# Convert the modified AST back to source code
|
| 157 |
-
return ast.unparse(parsed_code)
|
|
|
|
| 154 |
parsed_code.body = [try_except]
|
| 155 |
|
| 156 |
# Convert the modified AST back to source code
|
| 157 |
+
return ast.unparse(parsed_code)
|
code_interpreters/subprocess_code_interpreter.py
CHANGED
|
@@ -64,7 +64,7 @@ class SubprocessCodeInterpreter(BaseCodeInterpreter):
|
|
| 64 |
if not self.process:
|
| 65 |
self.start_process()
|
| 66 |
except:
|
| 67 |
-
yield {"output": traceback.format_exc()
|
| 68 |
return
|
| 69 |
|
| 70 |
|
|
@@ -83,7 +83,7 @@ class SubprocessCodeInterpreter(BaseCodeInterpreter):
|
|
| 83 |
# For UX, I like to hide this if it happens once. Obviously feels better to not see errors
|
| 84 |
# Most of the time it doesn't matter, but we should figure out why it happens frequently with:
|
| 85 |
# applescript
|
| 86 |
-
yield {"output": traceback.format_exc()
|
| 87 |
yield {"output": f"Retrying... ({retry_count}/{max_retries})"}
|
| 88 |
yield {"output": "Restarting process."}
|
| 89 |
|
|
@@ -91,7 +91,7 @@ class SubprocessCodeInterpreter(BaseCodeInterpreter):
|
|
| 91 |
|
| 92 |
retry_count += 1
|
| 93 |
if retry_count > max_retries:
|
| 94 |
-
yield {"output": "Maximum retries reached. Could not execute code."
|
| 95 |
return
|
| 96 |
|
| 97 |
while True:
|
|
|
|
| 64 |
if not self.process:
|
| 65 |
self.start_process()
|
| 66 |
except:
|
| 67 |
+
yield {"output": traceback.format_exc()}
|
| 68 |
return
|
| 69 |
|
| 70 |
|
|
|
|
| 83 |
# For UX, I like to hide this if it happens once. Obviously feels better to not see errors
|
| 84 |
# Most of the time it doesn't matter, but we should figure out why it happens frequently with:
|
| 85 |
# applescript
|
| 86 |
+
yield {"output": traceback.format_exc()}
|
| 87 |
yield {"output": f"Retrying... ({retry_count}/{max_retries})"}
|
| 88 |
yield {"output": "Restarting process."}
|
| 89 |
|
|
|
|
| 91 |
|
| 92 |
retry_count += 1
|
| 93 |
if retry_count > max_retries:
|
| 94 |
+
yield {"output": "Maximum retries reached. Could not execute code."}
|
| 95 |
return
|
| 96 |
|
| 97 |
while True:
|
run.py
CHANGED
|
@@ -64,7 +64,7 @@ if __name__ == "__main__":
|
|
| 64 |
|
| 65 |
#6. ~~~ Get the data ~~~
|
| 66 |
code = """
|
| 67 |
-
print("
|
| 68 |
"""
|
| 69 |
input_data = {
|
| 70 |
"language": "Python",
|
|
|
|
| 64 |
|
| 65 |
#6. ~~~ Get the data ~~~
|
| 66 |
code = """
|
| 67 |
+
print("hi)
|
| 68 |
"""
|
| 69 |
input_data = {
|
| 70 |
"language": "Python",
|