mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-18 18:53:10 +00:00
community[fix] : Pass API_KEY as argument (#30272)
PR Title: community: Fix Pass API_KEY as argument PR Message: Description: This PR fixes validation error "Value error, Did not find tavily_api_key, please add an environment variable `TAVILY_API_KEY` which contains it, or pass `tavily_api_key` as a named parameter." Dependencies: No new dependencies introduced. --------- Co-authored-by: pulvedu <dustin@tavily.com> Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
5e0fa2cce5
commit
d0bfc7f820
@ -1,6 +1,6 @@
|
|||||||
"""Tool for the Tavily search API."""
|
"""Tool for the Tavily search API."""
|
||||||
|
|
||||||
from typing import Dict, List, Literal, Optional, Tuple, Type, Union
|
from typing import Any, Dict, List, Literal, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
AsyncCallbackManagerForToolRun,
|
AsyncCallbackManagerForToolRun,
|
||||||
@ -149,6 +149,15 @@ class TavilySearchResults(BaseTool): # type: ignore[override, override]
|
|||||||
api_wrapper: TavilySearchAPIWrapper = Field(default_factory=TavilySearchAPIWrapper) # type: ignore[arg-type]
|
api_wrapper: TavilySearchAPIWrapper = Field(default_factory=TavilySearchAPIWrapper) # type: ignore[arg-type]
|
||||||
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
||||||
|
|
||||||
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
|
# Create api_wrapper with tavily_api_key if provided
|
||||||
|
if "tavily_api_key" in kwargs:
|
||||||
|
kwargs["api_wrapper"] = TavilySearchAPIWrapper(
|
||||||
|
tavily_api_key=kwargs["tavily_api_key"]
|
||||||
|
)
|
||||||
|
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
|
Loading…
Reference in New Issue
Block a user