openapi toolkit does not replace variable values from API specification parameters #28896
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
Checked other resources
Example Code
import os
import yaml
from langchain_community.agent_toolkits.openapi import planner
from langchain_openai import ChatOpenAI
from langchain_community.agent_toolkits.openapi.spec import reduce_openapi_spec
from langchain_community.utilities.requests import RequestsWrapper
from dotenv import load_dotenv
Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
Load Swagger Specification
with open("waapi.yaml", "r", encoding='utf8') as f:
raw_waapi_api_spec = yaml.load(f, Loader=yaml.Loader)
Add the host from environment variable
waapi_host = os.getenv("WAAPI_HOST")
if waapi_host:
raw_waapi_api_spec["servers"] = [{"url": waapi_host}]
Reduce the OpenAPI spec
waapi_api_spec = reduce_openapi_spec(raw_waapi_api_spec)
Define the LangChain Agent
llm = ChatOpenAI(model_name="gpt-4", temperature=0.0, api_key=OPENAI_API_KEY)
Set headers for the requests
headers = {"X-API-KEY": os.getenv("WAAPI_API_KEY")}
requests_wrapper = RequestsWrapper(headers=headers)
NOTE: set allow_dangerous_requests manually for security concern https://python.langchain.com/docs/security
waapi_agent = planner.create_openapi_agent(
waapi_api_spec,
requests_wrapper,
llm,
allow_dangerous_requests=False,
)
Interactive loop for user input
print("Interactive WAAPI Agent. Enter your query below. Press Enter on an empty line to exit.")
while True:
user_query = input("Your query: ").strip()
if not user_query:
print("Exiting the program. Goodbye!")
break
Error Message and Stack Trace (if applicable)
No response
Description
I want to use langchain to read an API specification and figure out the sequence of API calls that would be required to create a new user account based on the API spec given below -
https://waha.devlike.pro/swagger/openapi.json
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: