Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi toolkit does not replace variable values from API specification parameters #28896

Open
5 tasks done
sumeetk8 opened this issue Dec 24, 2024 · 0 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@sumeetk8
Copy link

sumeetk8 commented Dec 24, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

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

try:
    response = waapi_agent.invoke(user_query)
    print(f"Response: {response}")
except Exception as e:
    print(f"An error occurred: {e}")

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

OS: Windows
OS Version: 10.0.26100
Python Version: 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)]

Package Information

langchain_core: 0.3.28
langchain: 0.3.13
langchain_community: 0.3.13
langsmith: 0.2.4
langchain_mistralai: 0.2.4
langchain_openai: 0.2.14
langchain_text_splitters: 0.3.4

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 2.2.1
openai: 1.58.1
orjson: 3.10.12
packaging: 24.2
pydantic: 2.10.4
pydantic-settings: 2.7.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
tenacity: 9.0.0
tiktoken: 0.8.0
tokenizers: 0.21.0
typing-extensions: 4.12.2

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant