Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
|
| 3 |
|
| 4 |
@tool
|
| 5 |
def calculate_math(expression: str) -> str:
|
|
@@ -17,20 +17,15 @@ def calculate_math(expression: str) -> str:
|
|
| 17 |
|
| 18 |
class CourseEvaluationAgent:
|
| 19 |
def __init__(self):
|
| 20 |
-
print("[Agent System] Booting Engine...")
|
| 21 |
|
| 22 |
-
# FIX: We
|
| 23 |
-
#
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
model_id="meta-llama/Llama-3.3-70B-Instruct",
|
| 27 |
-
custom_client={"model_type": "hf_hub"}
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
# Build the functional CodeAgent
|
| 31 |
self.agent = CodeAgent(
|
| 32 |
tools=[DuckDuckGoSearchTool(), calculate_math],
|
| 33 |
-
|
| 34 |
max_steps=5, # Prevents long execution delays or infinite loops
|
| 35 |
verbosity_level=1
|
| 36 |
)
|
|
@@ -41,13 +36,12 @@ class CourseEvaluationAgent:
|
|
| 41 |
"Do not include unnecessary conversational filler."
|
| 42 |
)
|
| 43 |
|
| 44 |
-
# Modify structural templates cleanly without breaking expected input variables
|
| 45 |
if "system_prompt" in self.agent.prompt_templates:
|
| 46 |
self.agent.prompt_templates["system_prompt"] += extra_instructions
|
| 47 |
|
| 48 |
def run_task(self, question: str) -> str:
|
| 49 |
try:
|
| 50 |
-
#
|
| 51 |
output = self.agent.run(question)
|
| 52 |
return str(output).strip()
|
| 53 |
except Exception as e:
|
|
|
|
| 1 |
import os
|
| 2 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
|
| 3 |
|
| 4 |
@tool
|
| 5 |
def calculate_math(expression: str) -> str:
|
|
|
|
| 17 |
|
| 18 |
class CourseEvaluationAgent:
|
| 19 |
def __init__(self):
|
| 20 |
+
print("[Agent System] Booting Engine using direct Hub pipeline...")
|
| 21 |
|
| 22 |
+
# FIX: We bypass all model objects/classes completely.
|
| 23 |
+
# In this smolagents version, passing the model ID as a string parameter
|
| 24 |
+
# to 'model_id=' tells the CodeAgent constructor to directly instantiate
|
| 25 |
+
# its own internal client, safely avoiding the abstract ApiModel constraint.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
self.agent = CodeAgent(
|
| 27 |
tools=[DuckDuckGoSearchTool(), calculate_math],
|
| 28 |
+
model_id="meta-llama/Llama-3.3-70B-Instruct",
|
| 29 |
max_steps=5, # Prevents long execution delays or infinite loops
|
| 30 |
verbosity_level=1
|
| 31 |
)
|
|
|
|
| 36 |
"Do not include unnecessary conversational filler."
|
| 37 |
)
|
| 38 |
|
|
|
|
| 39 |
if "system_prompt" in self.agent.prompt_templates:
|
| 40 |
self.agent.prompt_templates["system_prompt"] += extra_instructions
|
| 41 |
|
| 42 |
def run_task(self, question: str) -> str:
|
| 43 |
try:
|
| 44 |
+
# Run calculation directly
|
| 45 |
output = self.agent.run(question)
|
| 46 |
return str(output).strip()
|
| 47 |
except Exception as e:
|