From 651cb6255694d0450db68b2bc7c986b478f0eb18 Mon Sep 17 00:00:00 2001 From: zz Date: Mon, 24 Apr 2023 06:02:18 +0800 Subject: [PATCH] Add support for wikipedia's lang parameter (#3383) Allow to hange the language of the wikipedia API being requested. Co-authored-by: zhuohui --- langchain/agents/load_tools.py | 2 +- langchain/utilities/wikipedia.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/langchain/agents/load_tools.py b/langchain/agents/load_tools.py index 790127ec..780501bb 100644 --- a/langchain/agents/load_tools.py +++ b/langchain/agents/load_tools.py @@ -240,7 +240,7 @@ _EXTRA_OPTIONAL_TOOLS = { "google-serper": (_get_google_serper, ["serper_api_key"]), "serpapi": (_get_serpapi, ["serpapi_api_key", "aiosession"]), "searx-search": (_get_searx_search, ["searx_host", "engines", "aiosession"]), - "wikipedia": (_get_wikipedia, ["top_k_results"]), + "wikipedia": (_get_wikipedia, ["top_k_results", "lang"]), "human": (_get_human_tool, ["prompt_func", "input_func"]), } diff --git a/langchain/utilities/wikipedia.py b/langchain/utilities/wikipedia.py index 811a6258..cc6cc6ae 100644 --- a/langchain/utilities/wikipedia.py +++ b/langchain/utilities/wikipedia.py @@ -17,6 +17,7 @@ class WikipediaAPIWrapper(BaseModel): wiki_client: Any #: :meta private: top_k_results: int = 3 + lang: str = "en" class Config: """Configuration for this pydantic object.""" @@ -29,6 +30,7 @@ class WikipediaAPIWrapper(BaseModel): try: import wikipedia + wikipedia.set_lang(values["lang"]) values["wiki_client"] = wikipedia except ImportError: raise ValueError(