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.1.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.

File details

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

File metadata

File hashes

Hashes for llama_index_tools_python_file-0.4.1.tar.gz
Algorithm Hash digest
SHA256 af54f57f9d0ca486dd2d9ca3f85a389010d873825c4482cb4e6f88ffd2380a20
MD5 0bf82290acaf1ffab4fbaa8794db1c3a
BLAKE2b-256 d7a8d0e3350c17d6131c2920a5d743e00adfd8ff2abe201c99da7bafe2fc3de7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_tools_python_file-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f657abc07131d291cdd3a078f6b824e3d16fbe2335c8221d45e859ae44993d
MD5 fa8872a75f4207570360af802cb00915
BLAKE2b-256 06ce085d2ea371e5250947e543fe556e21cfe28fdd7f4149d0e9c5f303d657de

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