mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-13 10:26:26 +00:00
BUG Add limit_to_domains to APIChain based tools (#13367)
- **Description:** Adds `limit_to_domains` param to the APIChain based
tools (open_meteo, TMDB, podcast_docs, and news_api)
- **Issue:** I didn't open an issue, but after upgrading to 0.0.328
using these tools would throw an error.
- **Dependencies:** N/A
- **Tag maintainer:** @baskaryan
**Note**: I included the trailing / simply because the docs here did
fc886cc303/docs/docs/use_cases/apis.ipynb (L246)
, but I checked the code and it is using `urlparse`. SoI followed the
docs since it comes down to stylee.
This commit is contained in:
parent
91443cacdb
commit
37eb44c591
@ -142,7 +142,11 @@ def _get_llm_math(llm: BaseLanguageModel) -> BaseTool:
|
|||||||
|
|
||||||
|
|
||||||
def _get_open_meteo_api(llm: BaseLanguageModel) -> BaseTool:
|
def _get_open_meteo_api(llm: BaseLanguageModel) -> BaseTool:
|
||||||
chain = APIChain.from_llm_and_api_docs(llm, open_meteo_docs.OPEN_METEO_DOCS)
|
chain = APIChain.from_llm_and_api_docs(
|
||||||
|
llm,
|
||||||
|
open_meteo_docs.OPEN_METEO_DOCS,
|
||||||
|
limit_to_domains=["https://api.open-meteo.com/"],
|
||||||
|
)
|
||||||
return Tool(
|
return Tool(
|
||||||
name="Open-Meteo-API",
|
name="Open-Meteo-API",
|
||||||
description="Useful for when you want to get weather information from the OpenMeteo API. The input should be a question in natural language that this API can answer.",
|
description="Useful for when you want to get weather information from the OpenMeteo API. The input should be a question in natural language that this API can answer.",
|
||||||
@ -159,7 +163,10 @@ _LLM_TOOLS: Dict[str, Callable[[BaseLanguageModel], BaseTool]] = {
|
|||||||
def _get_news_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
|
def _get_news_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
|
||||||
news_api_key = kwargs["news_api_key"]
|
news_api_key = kwargs["news_api_key"]
|
||||||
chain = APIChain.from_llm_and_api_docs(
|
chain = APIChain.from_llm_and_api_docs(
|
||||||
llm, news_docs.NEWS_DOCS, headers={"X-Api-Key": news_api_key}
|
llm,
|
||||||
|
news_docs.NEWS_DOCS,
|
||||||
|
headers={"X-Api-Key": news_api_key},
|
||||||
|
limit_to_domains=["https://newsapi.org/"],
|
||||||
)
|
)
|
||||||
return Tool(
|
return Tool(
|
||||||
name="News-API",
|
name="News-API",
|
||||||
@ -174,6 +181,7 @@ def _get_tmdb_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
|
|||||||
llm,
|
llm,
|
||||||
tmdb_docs.TMDB_DOCS,
|
tmdb_docs.TMDB_DOCS,
|
||||||
headers={"Authorization": f"Bearer {tmdb_bearer_token}"},
|
headers={"Authorization": f"Bearer {tmdb_bearer_token}"},
|
||||||
|
limit_to_domains=["https://api.themoviedb.org/"],
|
||||||
)
|
)
|
||||||
return Tool(
|
return Tool(
|
||||||
name="TMDB-API",
|
name="TMDB-API",
|
||||||
@ -188,6 +196,7 @@ def _get_podcast_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
|
|||||||
llm,
|
llm,
|
||||||
podcast_docs.PODCAST_DOCS,
|
podcast_docs.PODCAST_DOCS,
|
||||||
headers={"X-ListenAPI-Key": listen_api_key},
|
headers={"X-ListenAPI-Key": listen_api_key},
|
||||||
|
limit_to_domains=["https://listen-api.listennotes.com/"],
|
||||||
)
|
)
|
||||||
return Tool(
|
return Tool(
|
||||||
name="Podcast-API",
|
name="Podcast-API",
|
||||||
|
Loading…
Reference in New Issue
Block a user