diff --git a/langchain/utilities/wikipedia.py b/langchain/utilities/wikipedia.py index 5b7ab964c0..811a625855 100644 --- a/langchain/utilities/wikipedia.py +++ b/langchain/utilities/wikipedia.py @@ -3,6 +3,8 @@ from typing import Any, Dict, Optional from pydantic import BaseModel, Extra, root_validator +WIKIPEDIA_MAX_QUERY_LENGTH = 300 + class WikipediaAPIWrapper(BaseModel): """Wrapper around WikipediaAPI. @@ -37,7 +39,7 @@ class WikipediaAPIWrapper(BaseModel): def run(self, query: str) -> str: """Run Wikipedia search and get page summaries.""" - search_results = self.wiki_client.search(query) + search_results = self.wiki_client.search(query[:WIKIPEDIA_MAX_QUERY_LENGTH]) summaries = [] len_search_results = len(search_results) if len_search_results == 0: