Spaces:
Sleeping
Sleeping
jesusgj
commited on
Commit
·
5291928
1
Parent(s):
4c960c7
Modified files
Browse files- agent.py +18 -1
- requirements.txt +2 -1
agent.py
CHANGED
|
@@ -8,6 +8,7 @@ from smolagents import InferenceClientModel
|
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
from markdownify import markdownify
|
| 10 |
from requests.exceptions import RequestException
|
|
|
|
| 11 |
|
| 12 |
def initialize_agent():
|
| 13 |
# Load environment variables from .env file
|
|
@@ -51,10 +52,26 @@ def initialize_agent():
|
|
| 51 |
except Exception as e:
|
| 52 |
return f"An unexpected error occurred: {str(e)}"
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# 3. Define the agents
|
| 55 |
if model:
|
| 56 |
web_agent = ToolCallingAgent(
|
| 57 |
-
tools=[WebSearchTool(), visit_webpage],
|
| 58 |
model=model,
|
| 59 |
max_steps=10,
|
| 60 |
name="web_search_agent",
|
|
|
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
from markdownify import markdownify
|
| 10 |
from requests.exceptions import RequestException
|
| 11 |
+
from langchain_community.utilities import SerpAPIWrapper
|
| 12 |
|
| 13 |
def initialize_agent():
|
| 14 |
# Load environment variables from .env file
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
return f"An unexpected error occurred: {str(e)}"
|
| 54 |
|
| 55 |
+
@tool
|
| 56 |
+
def google_search(query: str) -> str:
|
| 57 |
+
"""Searches Google for the given query and returns the results.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
query: The query to search for.
|
| 61 |
+
|
| 62 |
+
Returns:
|
| 63 |
+
The search results, or an error message if the search fails.
|
| 64 |
+
"""
|
| 65 |
+
try:
|
| 66 |
+
serpapi = SerpAPIWrapper()
|
| 67 |
+
return serpapi.run(query)
|
| 68 |
+
except Exception as e:
|
| 69 |
+
return f"Error performing Google search: {str(e)}"
|
| 70 |
+
|
| 71 |
# 3. Define the agents
|
| 72 |
if model:
|
| 73 |
web_agent = ToolCallingAgent(
|
| 74 |
+
tools=[WebSearchTool(), visit_webpage, google_search],
|
| 75 |
model=model,
|
| 76 |
max_steps=10,
|
| 77 |
name="web_search_agent",
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ huggingface_hub
|
|
| 5 |
gradio
|
| 6 |
markdownify
|
| 7 |
duckduckgo-search
|
| 8 |
-
wikipedia
|
|
|
|
|
|
| 5 |
gradio
|
| 6 |
markdownify
|
| 7 |
duckduckgo-search
|
| 8 |
+
wikipedia
|
| 9 |
+
serpapi-python
|