Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tongyx361/execode
Execute code in text efficiently and safely.
https://github.com/tongyx361/execode
Last synced: about 2 months ago
JSON representation
Execute code in text efficiently and safely.
- Host: GitHub
- URL: https://github.com/tongyx361/execode
- Owner: tongyx361
- License: mit
- Created: 2024-06-17T20:11:10.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-06-19T08:03:22.000Z (6 months ago)
- Last Synced: 2024-06-19T23:26:59.044Z (6 months ago)
- Language: Jupyter Notebook
- Homepage: https://tongyx361.github.io/execode/
- Size: 351 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Execode
## Installation
For common users/developers, please just run the following command the
install the package:``` shell
pip install -e "."
```For intended contributors, we recommend installing the package with the
`dev` extras:``` shell
pip install -e ".[dev]"
pre-commit install
```## API Reference
``` python
from execode import *
```------------------------------------------------------------------------
### CodeExecCfg
> CodeExecCfg (input_begin:str='```python', input_end:str='```',
> output_code_prefix:str='print(',
> output_begin:str='```output', output_end:str='```',
> timeout:int=5, n_call_max:int=2,
> trunc_len:tuple[int,int]=(50, 50), elipsis:str='...')*Configuration for code execution.*
| | **Type** | **Default** | **Details** |
|--------------------|----------|------------------------------------|------------------------------------------------------------------------|
| input_begin | str | `python | | | input_end | str |` | |
| output_code_prefix | str | print( | Prefix of code that will be executed to display the output. |
| output_begin | str | `output | | | output_end | str |` | |
| timeout | int | 5 | Timeout in seconds for code execution. |
| n_call_max | int | 2 | The maximum number of calls to the code execution function. |
| trunc_len | tuple | (50, 50) | The maximum lengths to truncate the output into the beginning and end. |
| elipsis | str | … | The elipsis to use when truncating the output. |------------------------------------------------------------------------
#### CodeExecCfg.load_from_id_or_path
> CodeExecCfg.load_from_id_or_path (tool_config:str='python')
*Load the configuration from the ID or path.*
| | **Type** | **Default** | **Details** |
|-------------|-----------------|-------------|---------------------------------------------------------|
| tool_config | str | python | ID / Path to file of the code executeion configuration. |
| **Returns** | **CodeExecCfg** | | **The code execution configuration object.** |------------------------------------------------------------------------
#### CodeExecCfg.no_cells_todo
> CodeExecCfg.no_cells_todo (text:str)
*Judge if there are no code cells to execute.*
------------------------------------------------------------------------
#### CodeExecCfg.extract_cells
> CodeExecCfg.extract_cells (text:str)
*Extract code cells from the text.*
| | **Type** | **Details** |
|-------------|----------|--------------------------------------|
| text | str | The text to extract code cells from. |
| **Returns** | **list** | **The extracted code cells.** |------------------------------------------------------------------------
#### CodeExecCfg.wrap_output
> CodeExecCfg.wrap_output (output:str)
*Return `f"{self.output_begin}\n{output}\n{self.output_end}"`*
------------------------------------------------------------------------
### exec_cells
> exec_cells (cells:list[str])
*Execute the code cells like a notebook and return the stdout and stderr
of the last cell. Modified from -
https://github.com/Kipok/NeMo-Skills/blob/6a909ec0974340b02a1083dce90e79bea30ecb60/nemo_skills/code_execution/sandbox.py#L168-L233 -
https://github.com/deepseek-ai/DeepSeek-Math/blob/b8b0f8ce093d80bf8e9a641e44142f06d092c305/evaluation/infer/run_tool_integrated_eval.py#L163-L180*| | **Type** | **Details** |
|-------------|-----------|----------------------------|
| cells | list | The code cells to execute. |
| **Returns** | **tuple** | |