-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
community: Add "headers" parameter support to OpenAPI tools #29007
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
- **Description:** This PR is intended to allow OpenAPI agent to use request headers. It adds the following: * request tool now supports passing of the headers parameter. Headers are optional not to introduce breaking changes. Request headers are merged with headers passed to RequestWrapper class overwriting duplicate names. * OpenAPI planner prompts were updated to support new parameter. * `reduce_openapi_spec` now has new optional parameter "remove_optional", which allows to control whether optional parameters will be added to reduced API specification. This is required for the API I am integrating langchain with and often needed in real world cases.
Example repo which uses new features, although client code won't differ from the current version except for new parameter in the reduce_openapi_spec function https://github.com/unkindypie/langchain-playground/blob/master/openapi_agent.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I'm wary of the current implementation because all LLMs currently using the requests tools will need to begin populating (empty) headers in their tool calls.
Is it desirable for the LLM to generate headers? Curious about the context. If they can be programmatically generated outside the LLM, we have a guide on passing those to tools here.
@@ -23,7 +23,9 @@ class ReducedOpenAPISpec: | |||
endpoints: List[Tuple[str, str, dict]] | |||
|
|||
|
|||
def reduce_openapi_spec(spec: dict, dereference: bool = True) -> ReducedOpenAPISpec: | |||
def reduce_openapi_spec( | |||
spec: dict, dereference: bool = True, remove_optional: bool = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does defaulting to False change behavior for existing users?
Currently we are effectively removing optional by checking parameter.get("required")
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, False will behave as it was working before my changes and True will keep the optional params which is really useful in my case
Currently we are effectively removing optional by checking parameter.get("required"), right?
Right, we just remove anything which is not required at the moment
Yes, but in theory nothing should change as the description of the tool is updated. I've tried on my end and it worked on GPT 4.0
It's desirable in my case because headers must be passed only in a certain case based on description of a header which an LLM should determine, here is an example from our Swagger, but thank you for sharing. |
@ccurme Also regarding filling out empty headers problem, for this purpose I've made it default to {}, so there must be no changes required for the existing code and also LLMs can just omit and don't pass it, and the code will still work |
It adds the following:
reduce_openapi_spec
now has new optional parameter "remove_optional", which allows to control whether optional parameters will be added to reduced API specification. This is required for the API I am integrating langchain with and often needed in real world scenarios.