Need help with OpenAPI agent to call Internal/External API #8220
Replies: 2 comments 1 reply
-
can you paste the code of how you setup the tools? |
Beta Was this translation helpful? Give feedback.
-
Answer generated by a 🤖 AnswerI understand that you're having a few issues with the OpenAPI agent in LangChain. Specifically, you're having trouble with the HTTP method selection based on user input, adding a request body at runtime, and finding comprehensive documentation. Let's address these issues one by one.
from langchain.tools import OpenAPISpec, APIOperation
spec = OpenAPISpec.from_url("your_specification_url")
operation = APIOperation.from_openapi_spec(spec, "/api/terminateApi", "post")
from langchain.chains import OpenAPIEndpointChain
from langchain.requests import Requests
from langchain.llms import OpenAI
llm = OpenAI(temperature=0, max_tokens=1000)
api_chain = OpenAPIEndpointChain.from_api_operation(
operation,
llm,
requests=Requests(),
verbose=False,
return_intermediate_steps=True, # Return request and response text
)
output = api_chain("terminate", request_body={"memberId": "123"})
Remember, this is just one potential solution. If you find a better way to solve your issue or if you think this solution could be better explained in the documentation, feel free to make a pull request to update the documentation. This could help other users who might encounter the same issue in the future. Sources
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a set of APIs. These APIs are internal to my organization. I want to use the OpenAPI agent to take the user input, and call the API based on the input. I have gone through Langchain document https://python.langchain.com/docs/integrations/toolkits/openapi.
Although I created a sample OpenAPI specification file to test. My specification file contains below content -
**openapi: 3.0.0
info:
title: OpenAI API
description: APIs for terminate member
version: 2.0.0
servers:
tags:
description: The OpenAI REST API
paths:
"/api/terminateApi":
post:
operationId: terminateMember
tags:
- OpenAI
summary: Terminates a member
requestBody:
required: true
responses:
'200':
description: OK
x-oaiMeta:
name: terminate
group: terminate
path: terminate
x-oaiMeta:
groups:
title: Terminate Member
description: Used to terminate a member and returns 'Your tansaction is sucessfully completed' when the member
is successfully terminated and returns 'invalid member' if member is not terminated.**
I am a newbie so having trouble understanding the documentation. I sifted through the internet and youtube but didn't find anything helpful.
I need help with below -
Beta Was this translation helpful? Give feedback.
All reactions