Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,27 +29,35 @@ def wikipedia_search(query: str) -> str:
|
|
| 29 |
|
| 30 |
# --- Basic Agent Definition ---
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def __call__(self, question: str) -> str:
|
| 37 |
-
print(f"Agent received question: {question[:50]}...")
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
model=LiteLLMModel(
|
| 45 |
-
model_id=
|
| 46 |
-
api_base=
|
| 47 |
),
|
| 48 |
max_steps=15,
|
| 49 |
verbosity_level=2,
|
| 50 |
)
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 55 |
"""
|
|
|
|
| 29 |
|
| 30 |
# --- Basic Agent Definition ---
|
| 31 |
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
|
| 32 |
+
def web_search(query: str):
|
| 33 |
+
"""Search the web for information."""
|
| 34 |
+
return DuckDuckGoSearchRun().run(query)
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
def wikipedia_search(query: str):
|
| 37 |
+
"""Search Wikipedia for information."""
|
| 38 |
+
return wikipedia.run(query)
|
| 39 |
|
| 40 |
+
class BasicAgent:
|
| 41 |
+
def __init__(self, model_id="ollama/qwen2:7b", api_base="http://192.168.1.77:11434"):
|
| 42 |
+
print('BasicAgent initialized.')
|
| 43 |
+
self.tool_node = ToolNode([web_search, wikipedia_search])
|
| 44 |
+
self.agent = ToolCallingAgent(
|
| 45 |
+
tools=[self.tool_node],
|
| 46 |
model=LiteLLMModel(
|
| 47 |
+
model_id=model_id,
|
| 48 |
+
api_base=api_base
|
| 49 |
),
|
| 50 |
max_steps=15,
|
| 51 |
verbosity_level=2,
|
| 52 |
)
|
| 53 |
|
| 54 |
+
def __call__(self, question: str) -> str:
|
| 55 |
+
print(f"Agent received question: {question[:50]}...")
|
| 56 |
+
try:
|
| 57 |
+
return self.agent.run(question)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"Error in agent: {e}")
|
| 60 |
+
return f"AGENT ERROR: {e}"
|
| 61 |
|
| 62 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 63 |
"""
|