Tachi67's picture
Upload 5 files
8d2de79

Table of Contents

InterpreterAtomicFlow

InterpreterAtomicFlow Objects

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).

set_up_flow_state

def set_up_flow_state()

class-specific flow state: language and code, which describes the programming language and the code to run.

__init__

code_interpreters

code_interpreters.language_map

code_interpreters.create_code_interpreter

code_interpreters.languages.javascript

preprocess_javascript

def preprocess_javascript(code)

Add active line markers Wrap in a try catch Add end of execution marker

code_interpreters.languages.shell

preprocess_shell

def preprocess_shell(code)

Add active line markers Wrap in a try except (trap in shell) Add end of execution marker

add_active_line_prints

def add_active_line_prints(code)

Add echo statements indicating line numbers to a shell string.

code_interpreters.languages.python

preprocess_python

def preprocess_python(code)

Add active line markers Wrap in a try except Add end of execution marker

add_active_line_prints

def add_active_line_prints(code)

Add print statements indicating line numbers to a python string.

AddLinePrints Objects

class AddLinePrints(ast.NodeTransformer)

Transformer to insert print statements indicating the line number before every executable line in the AST.

insert_print_statement

def insert_print_statement(line_number)

Inserts a print statement for a given line number.

process_body

def process_body(body)

Processes a block of statements, adding print calls.

visit

def visit(node)

Overridden visit to transform nodes.

code_interpreters.languages.html

code_interpreters.languages.r

R Objects

class R(SubprocessCodeInterpreter)

preprocess_code

def preprocess_code(code)

Add active line markers Wrap in a tryCatch for better error handling in R Add end of execution marker

code_interpreters.languages.powershell

preprocess_powershell

def preprocess_powershell(code)

Add active line markers Wrap in try-catch block Add end of execution marker

add_active_line_prints

def add_active_line_prints(code)

Add Write-Output statements indicating line numbers to a PowerShell script.

wrap_in_try_catch

def wrap_in_try_catch(code)

Wrap PowerShell code in a try-catch block to catch errors and display them.

code_interpreters.languages

code_interpreters.languages.applescript

AppleScript Objects

class AppleScript(SubprocessCodeInterpreter)

preprocess_code

def preprocess_code(code)

Inserts an end_of_execution marker and adds active line indicators.

add_active_line_indicators

def add_active_line_indicators(code)

Adds log commands to indicate the active line of execution in the AppleScript.

detect_active_line

def detect_active_line(line)

Detects active line indicator in the output.

detect_end_of_execution

def detect_end_of_execution(line)

Detects end of execution marker in the output.

code_interpreters.subprocess_code_interpreter

SubprocessCodeInterpreter Objects

class SubprocessCodeInterpreter(BaseCodeInterpreter)

preprocess_code

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.

code_interpreters.base_code_interpreter

BaseCodeInterpreter Objects

class BaseCodeInterpreter()

.run is a generator that yields a dict with attributes: active_line, output