Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_python_file-0.4.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_tools_python_file-0.4.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_tools_python_file-0.4.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_python_file-0.4.0.tar.gz
Algorithm Hash digest
SHA256 313a52a2132c815943c28030af18391a491d90b1f84d43aaadb27eb3df06db89
MD5 2c41c126fc54e324de6b16d5cf667d8c
BLAKE2b-256 3a0087a1d37e623b6511b9a3b71a230b298c5c54764dcd88bf04659dc5d8d7ac

See more details on using hashes here.

File details

Details for the file llama_index_tools_python_file-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_python_file-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9113281689e9a46bd030409156034c6972cd0862acdd6daeff830e57d3b7430
MD5 6535e9ca35b2565edf58535c2db4ffbb
BLAKE2b-256 cc158b4a3830c4f41800b69570c49c34c5722accbf7c4b89888b21c25c8f0e2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page