Spaces:
Sleeping
Sleeping
bug fix and minor changes
Browse files- Webserch_tool.py +5 -5
- other_tools.py +24 -9
Webserch_tool.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
from langchain_community.tools import DuckDuckGoSearchRun
|
| 2 |
|
| 3 |
-
search_tool = DuckDuckGoSearchRun()
|
| 4 |
-
results = search_tool.invoke("Who's the current President of France?")
|
| 5 |
-
print(results)
|
| 6 |
|
| 7 |
from langchain.tools import Tool
|
| 8 |
import random
|
|
@@ -11,7 +11,7 @@ import os
|
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
load_dotenv()
|
| 13 |
weather_API_key = os.getenv("OPENWEATHER_KEY")
|
| 14 |
-
print(f'weather_API_key: {weather_API_key}')
|
| 15 |
def get_weather_info(location: str) -> str:
|
| 16 |
"""Fetches weather information for a given location."""
|
| 17 |
try:
|
|
|
|
| 1 |
+
# from langchain_community.tools import DuckDuckGoSearchRun
|
| 2 |
|
| 3 |
+
# search_tool = DuckDuckGoSearchRun()
|
| 4 |
+
# results = search_tool.invoke("Who's the current President of France?")
|
| 5 |
+
# print(results)
|
| 6 |
|
| 7 |
from langchain.tools import Tool
|
| 8 |
import random
|
|
|
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
load_dotenv()
|
| 13 |
weather_API_key = os.getenv("OPENWEATHER_KEY")
|
| 14 |
+
#print(f'weather_API_key: {weather_API_key}')
|
| 15 |
def get_weather_info(location: str) -> str:
|
| 16 |
"""Fetches weather information for a given location."""
|
| 17 |
try:
|
other_tools.py
CHANGED
|
@@ -34,15 +34,30 @@ def square_root(a: float) -> float | complex:
|
|
| 34 |
return cmath.sqrt(a)
|
| 35 |
|
| 36 |
from langchain_community.document_loaders import WikipediaLoader
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
from langchain_community.document_loaders import ArxivLoader
|
| 48 |
@tool(description="Search Arxiv for a query and return maximum 3 result.")
|
|
|
|
| 34 |
return cmath.sqrt(a)
|
| 35 |
|
| 36 |
from langchain_community.document_loaders import WikipediaLoader
|
| 37 |
+
|
| 38 |
+
@tool(description="Search Wikipedia for a query and return up to 2 results.")
|
| 39 |
+
def wiki_search(query: str) -> dict:
|
| 40 |
+
print(f"Searching Wikipedia for: {query}")
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# Load up to 2 documents from Wikipedia
|
| 44 |
+
search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
|
| 45 |
+
|
| 46 |
+
# Format the output for each document
|
| 47 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 48 |
+
[
|
| 49 |
+
f'<Document source="{doc.metadata.get("source", "")}" page="{doc.metadata.get("page", "")}">\n{doc.page_content}\n</Document>'
|
| 50 |
+
for doc in search_docs
|
| 51 |
+
]
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
print(f"Here are the outputs:\n{formatted_search_docs}")
|
| 55 |
+
return {"wiki_results": formatted_search_docs}
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"Error occurred: {e}")
|
| 59 |
+
return {"wiki_results": f"None found for {query}, use the results from the other tools or similar questions obtained earlier."}
|
| 60 |
+
|
| 61 |
|
| 62 |
from langchain_community.document_loaders import ArxivLoader
|
| 63 |
@tool(description="Search Arxiv for a query and return maximum 3 result.")
|