| # Table of Contents | |
| * [InterpreterAtomicFlow](#InterpreterAtomicFlow) | |
| * [InterpreterAtomicFlow](#InterpreterAtomicFlow.InterpreterAtomicFlow) | |
| * [set\_up\_flow\_state](#InterpreterAtomicFlow.InterpreterAtomicFlow.set_up_flow_state) | |
| * [\_\_init\_\_](#__init__) | |
| * [code\_interpreters](#code_interpreters) | |
| * [code\_interpreters.language\_map](#code_interpreters.language_map) | |
| * [code\_interpreters.create\_code\_interpreter](#code_interpreters.create_code_interpreter) | |
| * [code\_interpreters.languages.javascript](#code_interpreters.languages.javascript) | |
| * [preprocess\_javascript](#code_interpreters.languages.javascript.preprocess_javascript) | |
| * [code\_interpreters.languages.shell](#code_interpreters.languages.shell) | |
| * [preprocess\_shell](#code_interpreters.languages.shell.preprocess_shell) | |
| * [add\_active\_line\_prints](#code_interpreters.languages.shell.add_active_line_prints) | |
| * [code\_interpreters.languages.python](#code_interpreters.languages.python) | |
| * [preprocess\_python](#code_interpreters.languages.python.preprocess_python) | |
| * [add\_active\_line\_prints](#code_interpreters.languages.python.add_active_line_prints) | |
| * [AddLinePrints](#code_interpreters.languages.python.AddLinePrints) | |
| * [insert\_print\_statement](#code_interpreters.languages.python.AddLinePrints.insert_print_statement) | |
| * [process\_body](#code_interpreters.languages.python.AddLinePrints.process_body) | |
| * [visit](#code_interpreters.languages.python.AddLinePrints.visit) | |
| * [code\_interpreters.languages.html](#code_interpreters.languages.html) | |
| * [code\_interpreters.languages.r](#code_interpreters.languages.r) | |
| * [R](#code_interpreters.languages.r.R) | |
| * [preprocess\_code](#code_interpreters.languages.r.R.preprocess_code) | |
| * [code\_interpreters.languages.powershell](#code_interpreters.languages.powershell) | |
| * [preprocess\_powershell](#code_interpreters.languages.powershell.preprocess_powershell) | |
| * [add\_active\_line\_prints](#code_interpreters.languages.powershell.add_active_line_prints) | |
| * [wrap\_in\_try\_catch](#code_interpreters.languages.powershell.wrap_in_try_catch) | |
| * [code\_interpreters.languages](#code_interpreters.languages) | |
| * [code\_interpreters.languages.applescript](#code_interpreters.languages.applescript) | |
| * [AppleScript](#code_interpreters.languages.applescript.AppleScript) | |
| * [preprocess\_code](#code_interpreters.languages.applescript.AppleScript.preprocess_code) | |
| * [add\_active\_line\_indicators](#code_interpreters.languages.applescript.AppleScript.add_active_line_indicators) | |
| * [detect\_active\_line](#code_interpreters.languages.applescript.AppleScript.detect_active_line) | |
| * [detect\_end\_of\_execution](#code_interpreters.languages.applescript.AppleScript.detect_end_of_execution) | |
| * [code\_interpreters.subprocess\_code\_interpreter](#code_interpreters.subprocess_code_interpreter) | |
| * [SubprocessCodeInterpreter](#code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter) | |
| * [preprocess\_code](#code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter.preprocess_code) | |
| * [code\_interpreters.base\_code\_interpreter](#code_interpreters.base_code_interpreter) | |
| * [BaseCodeInterpreter](#code_interpreters.base_code_interpreter.BaseCodeInterpreter) | |
| <a id="InterpreterAtomicFlow"></a> | |
| # InterpreterAtomicFlow | |
| <a id="InterpreterAtomicFlow.InterpreterAtomicFlow"></a> | |
| ## InterpreterAtomicFlow Objects | |
| ```python | |
| class InterpreterAtomicFlow(AtomicFlow) | |
| ``` | |
| This flow is used to run the code passed from the caller. | |
| *Expected Input*: | |
| - `code` | |
| - `language_of_code` | |
| *Expected Output*: | |
| - `interpreter_output`: output of the code interpreter | |
| **Full credits to open-interpreter (https://github.com/KillianLucas/open-interpreter) | |
| for the usage of code interpreters (package `code_interpreters`) and the function truncate_output()** | |
| I'm extracting the code interpreter part from open-interpreter because the litellm version of open-interpreter | |
| is not compatible with that of the current version of aiflows(v.0.1.7). | |
| <a id="InterpreterAtomicFlow.InterpreterAtomicFlow.set_up_flow_state"></a> | |
| #### set\_up\_flow\_state | |
| ```python | |
| def set_up_flow_state() | |
| ``` | |
| class-specific flow state: language and code, | |
| which describes the programming language and the code to run. | |
| <a id="__init__"></a> | |
| # \_\_init\_\_ | |
| <a id="code_interpreters"></a> | |
| # code\_interpreters | |
| <a id="code_interpreters.language_map"></a> | |
| # code\_interpreters.language\_map | |
| <a id="code_interpreters.create_code_interpreter"></a> | |
| # code\_interpreters.create\_code\_interpreter | |
| <a id="code_interpreters.languages.javascript"></a> | |
| # code\_interpreters.languages.javascript | |
| <a id="code_interpreters.languages.javascript.preprocess_javascript"></a> | |
| #### preprocess\_javascript | |
| ```python | |
| def preprocess_javascript(code) | |
| ``` | |
| Add active line markers | |
| Wrap in a try catch | |
| Add end of execution marker | |
| <a id="code_interpreters.languages.shell"></a> | |
| # code\_interpreters.languages.shell | |
| <a id="code_interpreters.languages.shell.preprocess_shell"></a> | |
| #### preprocess\_shell | |
| ```python | |
| def preprocess_shell(code) | |
| ``` | |
| Add active line markers | |
| Wrap in a try except (trap in shell) | |
| Add end of execution marker | |
| <a id="code_interpreters.languages.shell.add_active_line_prints"></a> | |
| #### add\_active\_line\_prints | |
| ```python | |
| def add_active_line_prints(code) | |
| ``` | |
| Add echo statements indicating line numbers to a shell string. | |
| <a id="code_interpreters.languages.python"></a> | |
| # code\_interpreters.languages.python | |
| <a id="code_interpreters.languages.python.preprocess_python"></a> | |
| #### preprocess\_python | |
| ```python | |
| def preprocess_python(code) | |
| ``` | |
| Add active line markers | |
| Wrap in a try except | |
| Add end of execution marker | |
| <a id="code_interpreters.languages.python.add_active_line_prints"></a> | |
| #### add\_active\_line\_prints | |
| ```python | |
| def add_active_line_prints(code) | |
| ``` | |
| Add print statements indicating line numbers to a python string. | |
| <a id="code_interpreters.languages.python.AddLinePrints"></a> | |
| ## AddLinePrints Objects | |
| ```python | |
| class AddLinePrints(ast.NodeTransformer) | |
| ``` | |
| Transformer to insert print statements indicating the line number | |
| before every executable line in the AST. | |
| <a id="code_interpreters.languages.python.AddLinePrints.insert_print_statement"></a> | |
| #### insert\_print\_statement | |
| ```python | |
| def insert_print_statement(line_number) | |
| ``` | |
| Inserts a print statement for a given line number. | |
| <a id="code_interpreters.languages.python.AddLinePrints.process_body"></a> | |
| #### process\_body | |
| ```python | |
| def process_body(body) | |
| ``` | |
| Processes a block of statements, adding print calls. | |
| <a id="code_interpreters.languages.python.AddLinePrints.visit"></a> | |
| #### visit | |
| ```python | |
| def visit(node) | |
| ``` | |
| Overridden visit to transform nodes. | |
| <a id="code_interpreters.languages.html"></a> | |
| # code\_interpreters.languages.html | |
| <a id="code_interpreters.languages.r"></a> | |
| # code\_interpreters.languages.r | |
| <a id="code_interpreters.languages.r.R"></a> | |
| ## R Objects | |
| ```python | |
| class R(SubprocessCodeInterpreter) | |
| ``` | |
| <a id="code_interpreters.languages.r.R.preprocess_code"></a> | |
| #### preprocess\_code | |
| ```python | |
| def preprocess_code(code) | |
| ``` | |
| Add active line markers | |
| Wrap in a tryCatch for better error handling in R | |
| Add end of execution marker | |
| <a id="code_interpreters.languages.powershell"></a> | |
| # code\_interpreters.languages.powershell | |
| <a id="code_interpreters.languages.powershell.preprocess_powershell"></a> | |
| #### preprocess\_powershell | |
| ```python | |
| def preprocess_powershell(code) | |
| ``` | |
| Add active line markers | |
| Wrap in try-catch block | |
| Add end of execution marker | |
| <a id="code_interpreters.languages.powershell.add_active_line_prints"></a> | |
| #### add\_active\_line\_prints | |
| ```python | |
| def add_active_line_prints(code) | |
| ``` | |
| Add Write-Output statements indicating line numbers to a PowerShell script. | |
| <a id="code_interpreters.languages.powershell.wrap_in_try_catch"></a> | |
| #### wrap\_in\_try\_catch | |
| ```python | |
| def wrap_in_try_catch(code) | |
| ``` | |
| Wrap PowerShell code in a try-catch block to catch errors and display them. | |
| <a id="code_interpreters.languages"></a> | |
| # code\_interpreters.languages | |
| <a id="code_interpreters.languages.applescript"></a> | |
| # code\_interpreters.languages.applescript | |
| <a id="code_interpreters.languages.applescript.AppleScript"></a> | |
| ## AppleScript Objects | |
| ```python | |
| class AppleScript(SubprocessCodeInterpreter) | |
| ``` | |
| <a id="code_interpreters.languages.applescript.AppleScript.preprocess_code"></a> | |
| #### preprocess\_code | |
| ```python | |
| def preprocess_code(code) | |
| ``` | |
| Inserts an end_of_execution marker and adds active line indicators. | |
| <a id="code_interpreters.languages.applescript.AppleScript.add_active_line_indicators"></a> | |
| #### add\_active\_line\_indicators | |
| ```python | |
| def add_active_line_indicators(code) | |
| ``` | |
| Adds log commands to indicate the active line of execution in the AppleScript. | |
| <a id="code_interpreters.languages.applescript.AppleScript.detect_active_line"></a> | |
| #### detect\_active\_line | |
| ```python | |
| def detect_active_line(line) | |
| ``` | |
| Detects active line indicator in the output. | |
| <a id="code_interpreters.languages.applescript.AppleScript.detect_end_of_execution"></a> | |
| #### detect\_end\_of\_execution | |
| ```python | |
| def detect_end_of_execution(line) | |
| ``` | |
| Detects end of execution marker in the output. | |
| <a id="code_interpreters.subprocess_code_interpreter"></a> | |
| # code\_interpreters.subprocess\_code\_interpreter | |
| <a id="code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter"></a> | |
| ## SubprocessCodeInterpreter Objects | |
| ```python | |
| class SubprocessCodeInterpreter(BaseCodeInterpreter) | |
| ``` | |
| <a id="code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter.preprocess_code"></a> | |
| #### preprocess\_code | |
| ```python | |
| def preprocess_code(code) | |
| ``` | |
| This needs to insert an end_of_execution marker of some kind, | |
| which can be detected by detect_end_of_execution. | |
| Optionally, add active line markers for detect_active_line. | |
| <a id="code_interpreters.base_code_interpreter"></a> | |
| # code\_interpreters.base\_code\_interpreter | |
| <a id="code_interpreters.base_code_interpreter.BaseCodeInterpreter"></a> | |
| ## BaseCodeInterpreter Objects | |
| ```python | |
| class BaseCodeInterpreter() | |
| ``` | |
| .run is a generator that yields a dict with attributes: active_line, output | |