mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-16 17:53:37 +00:00
langchain[patch]: Minor Fix: Enable Passing custom_headers for Authentication in GraphQL Agent/Tool (#16413)
- **Description:** This PR aims to enhance the `langchain` library by enabling the support for passing `custom_headers` in the `GraphQLAPIWrapper` usage within `langchain/agents/load_tools.py`. While the `GraphQLAPIWrapper` from the `langchain_community` module is inherently capable of handling `custom_headers`, its current invocation in `load_tools.py` does not facilitate this functionality. This limitation restricts the use of the `graphql` tool with databases or APIs that require token-based authentication. The absence of support for `custom_headers` in this context also leads to a lack of error messages when attempting to interact with secured GraphQL endpoints, making debugging and troubleshooting more challenging. This update modifies the `load_tools` function to correctly handle `custom_headers`, thereby allowing secure and authenticated access to GraphQL services requiring tokens. Example usage after the proposed change: ```python tools = load_tools( ["graphql"], graphql_endpoint="https://your-graphql-endpoint.com/graphql", custom_headers={"Authorization": f"Token {api_token}"}, ) ``` - **Issue:** None, - **Dependencies:** None, - **Twitter handle:** None
This commit is contained in:
parent
5c6e123757
commit
80fcc50c65
@ -353,9 +353,7 @@ def _get_scenexplain(**kwargs: Any) -> BaseTool:
|
||||
|
||||
|
||||
def _get_graphql_tool(**kwargs: Any) -> BaseTool:
|
||||
graphql_endpoint = kwargs["graphql_endpoint"]
|
||||
wrapper = GraphQLAPIWrapper(graphql_endpoint=graphql_endpoint)
|
||||
return BaseGraphQLTool(graphql_wrapper=wrapper)
|
||||
return BaseGraphQLTool(graphql_wrapper=GraphQLAPIWrapper(**kwargs))
|
||||
|
||||
|
||||
def _get_openweathermap(**kwargs: Any) -> BaseTool:
|
||||
@ -455,7 +453,7 @@ _EXTRA_OPTIONAL_TOOLS: Dict[str, Tuple[Callable[[KwArg(Any)], BaseTool], List[st
|
||||
),
|
||||
"stackexchange": (_get_stackexchange, []),
|
||||
"sceneXplain": (_get_scenexplain, []),
|
||||
"graphql": (_get_graphql_tool, ["graphql_endpoint"]),
|
||||
"graphql": (_get_graphql_tool, ["graphql_endpoint", "custom_headers"]),
|
||||
"openweathermap-api": (_get_openweathermap, ["openweathermap_api_key"]),
|
||||
"dataforseo-api-search": (
|
||||
_get_dataforseo_api_search,
|
||||
|
Loading…
Reference in New Issue
Block a user