Python#
The assistant can execute Python code blocks.
It uses IPython to do so, and persists the IPython instance between calls to give a REPL-like experience.
Instructions
Use this tool to execute Python code in an interactive IPython session.
It responds with the execution output and final result.
### When to use the python tool
Use `python` for computation, structured data, and file-processing automation.
Prefer it over the shell for pure computation or when you need persistent
state or Python libraries.
Examples
Result of the last expression will be returned
| User |
What is 2 + 2? |
| Assistant |
|
| System |
Executed code block. |
Write a function and call it
| User |
compute fib 10 |
| Assistant |
To compute the 10th Fibonacci number, we can run the following code: |
| System |
Executed code block. |
- class gptme.tools.python.TeeIO
- __init__(original_stream)
- write(s)
Write string to file.
Returns the number of characters written, which is always equal to the length of the string.
- gptme.tools.python.execute_python(code: str | None, args: list[str] | None, kwargs: dict[str, str] | None) Generator[Message, None, None]
Executes a python codeblock and returns the output.