Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -12,7 +12,7 @@ from typing import Any
|
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from google.generativeai import types, configure
|
| 14 |
|
| 15 |
-
from smolagents import InferenceClientModel, LiteLLMModel, CodeAgent, ToolCallingAgent, Tool, DuckDuckGoSearchTool
|
| 16 |
|
| 17 |
# Logging
|
| 18 |
#logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
|
|
@@ -90,8 +90,14 @@ class WikiContentFetcher(Tool):
|
|
| 90 |
class BasicAgent:
|
| 91 |
def __init__(self):
|
| 92 |
print("BasicAgent initialized.")
|
| 93 |
-
model = HF_MODEL_NAME
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
tools = [
|
| 96 |
DuckDuckGoSearchTool(),
|
| 97 |
WikiTitleFinder(),
|
|
@@ -101,7 +107,7 @@ class BasicAgent:
|
|
| 101 |
TextTransformer(),
|
| 102 |
]
|
| 103 |
self.agent = CodeAgent(
|
| 104 |
-
model=
|
| 105 |
tools=tools,
|
| 106 |
add_base_tools=False,
|
| 107 |
max_steps=10,
|
|
@@ -161,7 +167,13 @@ class BasicAgent:
|
|
| 161 |
def __call__(self, question: str) -> str:
|
| 162 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 163 |
result = self.agent.run(question)
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
return final_str
|
| 167 |
|
|
|
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from google.generativeai import types, configure
|
| 14 |
|
| 15 |
+
from smolagents import InferenceClientModel, LiteLLMModel, CodeAgent, ToolCallingAgent, Tool, DuckDuckGoSearchTool, HfApiModel
|
| 16 |
|
| 17 |
# Logging
|
| 18 |
#logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
|
|
|
|
| 90 |
class BasicAgent:
|
| 91 |
def __init__(self):
|
| 92 |
print("BasicAgent initialized.")
|
| 93 |
+
#model = HF_MODEL_NAME
|
| 94 |
+
model = HfApiModel(
|
| 95 |
+
max_tokens=2096,
|
| 96 |
+
temperature=0.5,
|
| 97 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 98 |
+
#model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 99 |
+
custom_role_conversions=None,
|
| 100 |
+
)
|
| 101 |
tools = [
|
| 102 |
DuckDuckGoSearchTool(),
|
| 103 |
WikiTitleFinder(),
|
|
|
|
| 107 |
TextTransformer(),
|
| 108 |
]
|
| 109 |
self.agent = CodeAgent(
|
| 110 |
+
model=model,
|
| 111 |
tools=tools,
|
| 112 |
add_base_tools=False,
|
| 113 |
max_steps=10,
|
|
|
|
| 167 |
def __call__(self, question: str) -> str:
|
| 168 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 169 |
result = self.agent.run(question)
|
| 170 |
+
|
| 171 |
+
if isinstance(result, dict) and "output" in result:
|
| 172 |
+
final_str = str(result["output"]).strip()
|
| 173 |
+
elif hasattr(result, "output"):
|
| 174 |
+
final_str = str(result.output).strip()
|
| 175 |
+
else:
|
| 176 |
+
final_str = str(result).strip()
|
| 177 |
|
| 178 |
return final_str
|
| 179 |
|