llama-index-tools-code-interpreter 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llama_index_tools_code_interpreter-0.0.1/PKG-INFO +51 -0
- llama_index_tools_code_interpreter-0.0.1/README.md +34 -0
- llama_index_tools_code_interpreter-0.0.1/llama_index/tools/code_interpreter/__init__.py +6 -0
- llama_index_tools_code_interpreter-0.0.1/llama_index/tools/code_interpreter/base.py +36 -0
- llama_index_tools_code_interpreter-0.0.1/pyproject.toml +49 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: llama-index-tools-code-interpreter
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: llama-index tools code_interpreter integration
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: you@example.com
|
|
8
|
+
Requires-Python: >=3.8.1,<3.12
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Requires-Dist: llama-index-core (>=0.9.32,<0.10.0)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Code Interpreter Tool
|
|
18
|
+
|
|
19
|
+
This tool can be used to run python scripts and capture the results of stdout and stderr
|
|
20
|
+
|
|
21
|
+
WARNING: This tool provides the Agent access to the `subprocess.run` command.
|
|
22
|
+
Arbitrary code execution is possible on the machine running this tool.
|
|
23
|
+
This tool is not recommended to be used in a production setting, and would require heavy sandboxing or virtual machines
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Here's an example usage of the CodeInterpreterToolSpec.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from llama_index.tools.code_interpreter import CodeInterpreterToolSpec
|
|
31
|
+
from llama_index.agent import OpenAIAgent
|
|
32
|
+
|
|
33
|
+
code_spec = CodeInterpreterToolSpec()
|
|
34
|
+
|
|
35
|
+
agent = OpenAIAgent.from_tools(code_spec.to_tool_list())
|
|
36
|
+
|
|
37
|
+
# Prime the agent to use the tool
|
|
38
|
+
agent.chat(
|
|
39
|
+
"Can you help me write some python code to pass to the code_interpreter tool"
|
|
40
|
+
)
|
|
41
|
+
agent.chat(
|
|
42
|
+
"write a python function to calculate volume of a sphere with radius 4.3cm"
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The tools available are:
|
|
47
|
+
|
|
48
|
+
`code_interpreter`: A tool to evalute a python script
|
|
49
|
+
|
|
50
|
+
This loader is designed to be used as a way to load data as a Tool in a Agent. See [here](https://github.com/emptycrown/llama-hub/tree/main) for examples.
|
|
51
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Code Interpreter Tool
|
|
2
|
+
|
|
3
|
+
This tool can be used to run python scripts and capture the results of stdout and stderr
|
|
4
|
+
|
|
5
|
+
WARNING: This tool provides the Agent access to the `subprocess.run` command.
|
|
6
|
+
Arbitrary code execution is possible on the machine running this tool.
|
|
7
|
+
This tool is not recommended to be used in a production setting, and would require heavy sandboxing or virtual machines
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Here's an example usage of the CodeInterpreterToolSpec.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from llama_index.tools.code_interpreter import CodeInterpreterToolSpec
|
|
15
|
+
from llama_index.agent import OpenAIAgent
|
|
16
|
+
|
|
17
|
+
code_spec = CodeInterpreterToolSpec()
|
|
18
|
+
|
|
19
|
+
agent = OpenAIAgent.from_tools(code_spec.to_tool_list())
|
|
20
|
+
|
|
21
|
+
# Prime the agent to use the tool
|
|
22
|
+
agent.chat(
|
|
23
|
+
"Can you help me write some python code to pass to the code_interpreter tool"
|
|
24
|
+
)
|
|
25
|
+
agent.chat(
|
|
26
|
+
"write a python function to calculate volume of a sphere with radius 4.3cm"
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The tools available are:
|
|
31
|
+
|
|
32
|
+
`code_interpreter`: A tool to evalute a python script
|
|
33
|
+
|
|
34
|
+
This loader is designed to be used as a way to load data as a Tool in a Agent. See [here](https://github.com/emptycrown/llama-hub/tree/main) for examples.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Code Interpreter tool spec."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from llama_index.core.tools.tool_spec.base import BaseToolSpec
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CodeInterpreterToolSpec(BaseToolSpec):
|
|
10
|
+
"""Code Interpreter tool spec.
|
|
11
|
+
|
|
12
|
+
WARNING: This tool provides the Agent access to the `subprocess.run` command.
|
|
13
|
+
Arbitrary code execution is possible on the machine running this tool.
|
|
14
|
+
This tool is not recommended to be used in a production setting, and would require heavy sandboxing or virtual machines
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
spec_functions = ["code_interpreter"]
|
|
19
|
+
|
|
20
|
+
def code_interpreter(self, code: str):
|
|
21
|
+
"""
|
|
22
|
+
A function to execute python code, and return the stdout and stderr
|
|
23
|
+
|
|
24
|
+
You should import any libraries that you wish to use. You have access to any libraries the user has installed.
|
|
25
|
+
|
|
26
|
+
The code passed to this functuon is executed in isolation. It should be complete at the time it is passed to this function.
|
|
27
|
+
|
|
28
|
+
You should interpret the output and errors returned from this function, and attempt to fix any problems.
|
|
29
|
+
If you cannot fix the error, show the code to the user and ask for help
|
|
30
|
+
|
|
31
|
+
It is not possible to return graphics or other complicated data from this function. If the user cannot see the output, save it to a file and tell the user.
|
|
32
|
+
"""
|
|
33
|
+
result = subprocess.run(
|
|
34
|
+
[sys.executable, "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
35
|
+
)
|
|
36
|
+
return f"StdOut:\n{result.stdout}\nStdErr:\n{result.stderr}"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[tool.codespell]
|
|
6
|
+
check-filenames = true
|
|
7
|
+
check-hidden = true
|
|
8
|
+
# Feel free to un-skip examples, and experimental, you will just need to
|
|
9
|
+
# work through many typos (--write-changes and --interactive will help)
|
|
10
|
+
skip = "*.csv,*.html,*.json,*.jsonl,*.pdf,*.txt,*.ipynb"
|
|
11
|
+
|
|
12
|
+
[tool.mypy]
|
|
13
|
+
disallow_untyped_defs = true
|
|
14
|
+
# Remove venv skip when integrated with pre-commit
|
|
15
|
+
exclude = ["_static", "build", "examples", "notebooks", "venv"]
|
|
16
|
+
ignore_missing_imports = true
|
|
17
|
+
python_version = "3.8"
|
|
18
|
+
|
|
19
|
+
[tool.poetry]
|
|
20
|
+
name = "llama-index-tools-code-interpreter"
|
|
21
|
+
version = "0.0.1"
|
|
22
|
+
description = "llama-index tools code_interpreter integration"
|
|
23
|
+
authors = ["Your Name <you@example.com>"]
|
|
24
|
+
license = "MIT"
|
|
25
|
+
readme = "README.md"
|
|
26
|
+
packages = [{include = "llama_index/"}]
|
|
27
|
+
|
|
28
|
+
[tool.poetry.dependencies]
|
|
29
|
+
python = ">=3.8.1,<3.12"
|
|
30
|
+
llama-index-core = "^0.9.32"
|
|
31
|
+
|
|
32
|
+
[tool.poetry.group.dev.dependencies]
|
|
33
|
+
black = {extras = ["jupyter"], version = "<=23.9.1,>=23.7.0"}
|
|
34
|
+
codespell = {extras = ["toml"], version = ">=v2.2.6"}
|
|
35
|
+
ipython = "8.10.0"
|
|
36
|
+
jupyter = "^1.0.0"
|
|
37
|
+
mypy = "0.991"
|
|
38
|
+
pre-commit = "3.2.0"
|
|
39
|
+
pylint = "2.15.10"
|
|
40
|
+
pytest = "7.2.1"
|
|
41
|
+
pytest-mock = "3.11.1"
|
|
42
|
+
ruff = "0.0.292"
|
|
43
|
+
tree-sitter-languages = "^1.8.0"
|
|
44
|
+
types-Deprecated = ">=0.1.0"
|
|
45
|
+
types-PyYAML = "^6.0.12.12"
|
|
46
|
+
types-protobuf = "^4.24.0.4"
|
|
47
|
+
types-redis = "4.5.5.0"
|
|
48
|
+
types-requests = "2.28.11.8" # TODO: unpin when mypy>0.991
|
|
49
|
+
types-setuptools = "67.1.0.0"
|