Update InterpreterAtomicFlow.py
Browse files- InterpreterAtomicFlow.py +9 -6
InterpreterAtomicFlow.py
CHANGED
|
@@ -45,17 +45,19 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 45 |
self.flow_state["language"] = language
|
| 46 |
self.flow_state["code"] = code
|
| 47 |
|
| 48 |
-
def
|
| 49 |
"""
|
| 50 |
-
|
| 51 |
-
pass input data into flow state
|
| 52 |
-
|
| 53 |
-
should call something like self._update_flow_state()
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
assert "language" in input_data, "attribute 'language' not in input data."
|
| 57 |
assert "code" in input_data, "attribute 'code' not in input data."
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# code in Jupyter notebook that starts with '!' is actually shell command.
|
| 60 |
if input_data["language"] == "python" and input_data["code"].startswith("!"):
|
| 61 |
input_data["language"] = "shell"
|
|
@@ -93,6 +95,7 @@ class InterpreterAtomicFlow(AtomicFlow):
|
|
| 93 |
def run(
|
| 94 |
self,
|
| 95 |
input_data: Dict[str, Any]):
|
|
|
|
| 96 |
self._process_input_data(input_data)
|
| 97 |
response = self._call()
|
| 98 |
return {"interpreter_output": response}
|
|
|
|
| 45 |
self.flow_state["language"] = language
|
| 46 |
self.flow_state["code"] = code
|
| 47 |
|
| 48 |
+
def _check_input(self, input_data: Dict[str, Any]):
|
| 49 |
"""
|
| 50 |
+
Sanity check of input data
|
|
|
|
|
|
|
|
|
|
| 51 |
"""
|
| 52 |
+
# ~~~ Sanity check of input_data ~~~
|
| 53 |
assert "language" in input_data, "attribute 'language' not in input data."
|
| 54 |
assert "code" in input_data, "attribute 'code' not in input data."
|
| 55 |
|
| 56 |
+
|
| 57 |
+
def _process_input_data(self, input_data: Dict[str, Any]):
|
| 58 |
+
"""
|
| 59 |
+
Allocate interpreter if any, pass input data into flow state
|
| 60 |
+
"""
|
| 61 |
# code in Jupyter notebook that starts with '!' is actually shell command.
|
| 62 |
if input_data["language"] == "python" and input_data["code"].startswith("!"):
|
| 63 |
input_data["language"] = "shell"
|
|
|
|
| 95 |
def run(
|
| 96 |
self,
|
| 97 |
input_data: Dict[str, Any]):
|
| 98 |
+
self._check_input(input_data)
|
| 99 |
self._process_input_data(input_data)
|
| 100 |
response = self._call()
|
| 101 |
return {"interpreter_output": response}
|