File size: 10,173 Bytes
544270e 803677d 544270e 8d2de79 803677d 544270e 803677d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# 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
|