llama-index tools openapi integration
Project description
OpenAPI Tool
pip install llama-index-tools-openapi
This tool loads an OpenAPI spec and allow the Agent to retrieve endpoints and details about endpoints. The RequestsToolSpec can also be loaded into the agent to allow the agent to hit the necessary endpoints with a REST request.
Usage
This tool has more extensive example usage documented in a Jupyter notebook here
Here's an example usage of the OpenAPIToolSpec.
from llama_index.tools.openapi import OpenAPIToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
f = requests.get(
"https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/openai.com/1.2.0/openapi.yaml"
).text
open_api_spec = yaml.safe_load(f)
# OR
open_spec = OpenAPIToolSpec(
url="https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/openai.com/1.2.0/openapi.yaml"
)
tool_spec = OpenAPIToolSpec(open_api_spec)
agent = FunctionAgent(
tools=tool_spec.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
print(await agent.run("What is the base url for the API"))
print(await agent.run("What parameters does the x endpoint need?"))
load_openapi_spec: Returns the parsed OpenAPI spec that the class was initialized with
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_openapi-0.5.0.tar.gz.
File metadata
- Download URL: llama_index_tools_openapi-0.5.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea6623cb4004b4da62b7a3ca40164f7a838303456ccbae9bef05270dd1ead2ce
|
|
| MD5 |
2d3785b45b52a7dfb5b99928c88248df
|
|
| BLAKE2b-256 |
f88e91e9a6929a93f28b5ac7e3570dcd4d2d8bd595032cb512c7e2f98389bdd0
|
File details
Details for the file llama_index_tools_openapi-0.5.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_tools_openapi-0.5.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09087bdbc7fc00e30b973cdfe705ac895b92d0374e1db1f354d0b76710d44c96
|
|
| MD5 |
98aa1c69a05a2997139a76a2b5b57e09
|
|
| BLAKE2b-256 |
81baa13e9f82da143ca69129af05aa63308eba623a8731344e4a885d10b02c1e
|