Spaces:
Sleeping
Sleeping
Mikkel Skovdal commited on
Commit ·
3929291
1
Parent(s): b17b706
first try gwen
Browse files- .gitignore +2 -1
- __pycache__/agent.cpython-310.pyc +0 -0
- agent.py +25 -7
- log.txt +0 -0
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
secret
|
| 2 |
test.ipynb
|
| 3 |
-
.env
|
|
|
|
|
|
| 1 |
secret
|
| 2 |
test.ipynb
|
| 3 |
+
.env
|
| 4 |
+
error.txt
|
__pycache__/agent.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ
|
|
|
agent.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
|
| 2 |
-
|
| 3 |
-
|
| 4 |
|
| 5 |
|
| 6 |
class CustomAgent:
|
|
@@ -8,12 +8,14 @@ class CustomAgent:
|
|
| 8 |
self,
|
| 9 |
model_name="Qwen/Qwen2.5-Omni-7B",
|
| 10 |
authorized_imports=["wiki", "json"],
|
| 11 |
-
max_steps=5
|
|
|
|
| 12 |
):
|
| 13 |
"""
|
| 14 |
Initialize the CustomAgent with a model and tools.
|
| 15 |
If no model is provided, a default one is used.
|
| 16 |
"""
|
|
|
|
| 17 |
model = InferenceClientModel(model_name)
|
| 18 |
search_tool = DuckDuckGoSearchTool()
|
| 19 |
|
|
@@ -25,8 +27,24 @@ class CustomAgent:
|
|
| 25 |
)
|
| 26 |
print("CustomAgent initialized.")
|
| 27 |
|
| 28 |
-
def __call__(self, question: str) -> str:
|
| 29 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
|
| 2 |
+
# import asyncio
|
| 3 |
+
import datetime
|
| 4 |
|
| 5 |
|
| 6 |
class CustomAgent:
|
|
|
|
| 8 |
self,
|
| 9 |
model_name="Qwen/Qwen2.5-Omni-7B",
|
| 10 |
authorized_imports=["wiki", "json"],
|
| 11 |
+
max_steps=5,
|
| 12 |
+
logging=False
|
| 13 |
):
|
| 14 |
"""
|
| 15 |
Initialize the CustomAgent with a model and tools.
|
| 16 |
If no model is provided, a default one is used.
|
| 17 |
"""
|
| 18 |
+
self.logging = logging
|
| 19 |
model = InferenceClientModel(model_name)
|
| 20 |
search_tool = DuckDuckGoSearchTool()
|
| 21 |
|
|
|
|
| 27 |
)
|
| 28 |
print("CustomAgent initialized.")
|
| 29 |
|
| 30 |
+
def __call__(self, question: str) -> tuple[str, str, str | Exception]:
|
| 31 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 32 |
+
try:
|
| 33 |
+
fixed_answer = self.agent.run(question)
|
| 34 |
+
|
| 35 |
+
if self.logging:
|
| 36 |
+
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 37 |
+
with open("log.txt", "a") as log_file:
|
| 38 |
+
log_file.write(f"{timestamp}: {question} -> {fixed_answer}\n")
|
| 39 |
+
|
| 40 |
+
return question, fixed_answer
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"Agent ERROR on task: {e}")
|
| 44 |
+
|
| 45 |
+
if self.logging:
|
| 46 |
+
with open("log.txt", "a") as log_file:
|
| 47 |
+
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 48 |
+
log_file.write(f"{timestamp}: {question} -> ERROR: {e}\n")
|
| 49 |
+
|
| 50 |
+
return question, e
|
log.txt
ADDED
|
File without changes
|