llama-index tools python_file integration
Project description
Python File Tool
This tool loads a python file and extracts function names, arguments and descriptions automatically. This tool is particular useful for automatically creating custom Tool Specs when you already have well documented python functions.
Usage
This tool has more extensive example usage documented in a Jupyter notebook here
Here's an example usage of the PythonFileToolSpec.
from llama_index.tools.python_file import PythonFileToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
pyfile = PythonFileToolSpec("./numpy_linalg.py")
agent = FunctionAgent(
tools=pyfile.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
print(
await agent.run(
"""Load the eig, transpose and solve functions from the python file,
and then write a function definition using only builtin python types (List, float, Tuple)
with a short 5-10 line doc string tool prompts for the functions that only has a small description and arguments
"""
)
)
function_definitions: Get all of the function definitions from the Python file
get_function: Get a specific function definition from the Python file
get_functions: Get a list of functions from the python file
This loader is designed to be used as a way to load data as a Tool in a Agent.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_tools_python_file-0.4.0.tar.gz.
File metadata
- Download URL: llama_index_tools_python_file-0.4.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
313a52a2132c815943c28030af18391a491d90b1f84d43aaadb27eb3df06db89
|
|
| MD5 |
2c41c126fc54e324de6b16d5cf667d8c
|
|
| BLAKE2b-256 |
3a0087a1d37e623b6511b9a3b71a230b298c5c54764dcd88bf04659dc5d8d7ac
|
File details
Details for the file llama_index_tools_python_file-0.4.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_tools_python_file-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9113281689e9a46bd030409156034c6972cd0862acdd6daeff830e57d3b7430
|
|
| MD5 |
6535e9ca35b2565edf58535c2db4ffbb
|
|
| BLAKE2b-256 |
cc158b4a3830c4f41800b69570c49c34c5722accbf7c4b89888b21c25c8f0e2f
|