Spaces:
Runtime error
Runtime error
Update helper.py
Browse files
helper.py
CHANGED
|
@@ -232,23 +232,16 @@ from langchain_community.tools import WikipediaQueryRun
|
|
| 232 |
from langchain_community.utilities import WikipediaAPIWrapper
|
| 233 |
from langchain.tools import Tool # Ensure Tool is imported
|
| 234 |
|
|
|
|
| 235 |
def get_wikipedia_tool() -> Tool:
|
| 236 |
"""
|
| 237 |
Creates and returns a LangChain Tool for querying Wikipedia.
|
| 238 |
"""
|
| 239 |
-
# Initialize the Wikipedia API Wrapper
|
| 240 |
-
# Configure the wrapper to control how much content is returned.
|
| 241 |
-
# 'top_k_results': Number of search results to return.
|
| 242 |
-
# 'doc_content_chars_max': Maximum number of characters from the page content.
|
| 243 |
-
# Setting this to a reasonable limit (e.g., 2000-4000)
|
| 244 |
-
# is crucial for token management, as Wikipedia articles can be very long.
|
| 245 |
-
# Adjust based on your LLM's context window and typical use cases.
|
| 246 |
wikipedia_api_wrapper = WikipediaAPIWrapper(
|
| 247 |
-
top_k_results=3,
|
| 248 |
-
doc_content_chars_max=2000
|
| 249 |
)
|
| 250 |
|
| 251 |
-
# Initialize the Wikipedia tool with the wrapper
|
| 252 |
wikipedia_query_tool = WikipediaQueryRun(api_wrapper=wikipedia_api_wrapper)
|
| 253 |
|
| 254 |
return Tool(
|
|
@@ -277,7 +270,7 @@ def get_wikipedia_tool() -> Tool:
|
|
| 277 |
**Output:**
|
| 278 |
The tool returns a string containing snippets of relevant Wikipedia articles.
|
| 279 |
The output is limited in length to save tokens. If the answer is not found in the snippet,
|
| 280 |
-
you might need to refine your query or consider using a broader search
|
| 281 |
""",
|
| 282 |
func=wikipedia_query_tool.run,
|
| 283 |
)
|
|
|
|
| 232 |
from langchain_community.utilities import WikipediaAPIWrapper
|
| 233 |
from langchain.tools import Tool # Ensure Tool is imported
|
| 234 |
|
| 235 |
+
|
| 236 |
def get_wikipedia_tool() -> Tool:
|
| 237 |
"""
|
| 238 |
Creates and returns a LangChain Tool for querying Wikipedia.
|
| 239 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
wikipedia_api_wrapper = WikipediaAPIWrapper(
|
| 241 |
+
top_k_results=3,
|
| 242 |
+
doc_content_chars_max=2000
|
| 243 |
)
|
| 244 |
|
|
|
|
| 245 |
wikipedia_query_tool = WikipediaQueryRun(api_wrapper=wikipedia_api_wrapper)
|
| 246 |
|
| 247 |
return Tool(
|
|
|
|
| 270 |
**Output:**
|
| 271 |
The tool returns a string containing snippets of relevant Wikipedia articles.
|
| 272 |
The output is limited in length to save tokens. If the answer is not found in the snippet,
|
| 273 |
+
you might need to refine your query or **consider using 'tavily_search' or other available tools for a broader search.**
|
| 274 |
""",
|
| 275 |
func=wikipedia_query_tool.run,
|
| 276 |
)
|