Skip to content

Commit

Permalink
BUG Add limit_to_domains to APIChain based tools (#13367)
Browse files Browse the repository at this point in the history
- **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
https://github.com/langchain-ai/langchain/blob/fc886cc3039c2479bb13287f48fcbdb097a44c70/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.
  • Loading branch information
fielding authored Nov 15, 2023
1 parent 91443ca commit 37eb44c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libs/langchain/langchain/agents/load_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ def _get_llm_math(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(
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.",
Expand All @@ -159,7 +163,10 @@ def _get_open_meteo_api(llm: BaseLanguageModel) -> BaseTool:
def _get_news_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
news_api_key = kwargs["news_api_key"]
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(
name="News-API",
Expand All @@ -174,6 +181,7 @@ def _get_tmdb_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
llm,
tmdb_docs.TMDB_DOCS,
headers={"Authorization": f"Bearer {tmdb_bearer_token}"},
limit_to_domains=["https://api.themoviedb.org/"],
)
return Tool(
name="TMDB-API",
Expand All @@ -188,6 +196,7 @@ def _get_podcast_api(llm: BaseLanguageModel, **kwargs: Any) -> BaseTool:
llm,
podcast_docs.PODCAST_DOCS,
headers={"X-ListenAPI-Key": listen_api_key},
limit_to_domains=["https://listen-api.listennotes.com/"],
)
return Tool(
name="Podcast-API",
Expand Down

0 comments on commit 37eb44c

Please sign in to comment.