Spaces:
Sleeping
Sleeping
Update BasicAgent.py
Browse files- BasicAgent.py +14 -31
BasicAgent.py
CHANGED
@@ -1,57 +1,40 @@
|
|
1 |
-
import smolagents
|
2 |
-
import
|
3 |
-
from typing import Union
|
4 |
from smolagents import (
|
5 |
tool,
|
6 |
CodeAgent,
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
PythonInterpreterTool,
|
11 |
-
FinalAnswerTool,
|
12 |
-
DuckDuckGoSearchTool,
|
13 |
-
GoogleSearchTool
|
14 |
-
)
|
15 |
|
16 |
-
#*
|
17 |
-
|
18 |
-
#
|
19 |
class newAgent:
|
20 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
21 |
def __init__(self):
|
22 |
-
model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
23 |
-
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
24 |
if not hf_token:
|
25 |
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
|
26 |
-
|
27 |
-
system_prompt=(
|
28 |
"You are an agent that answers exam questions. "
|
29 |
"Your answers should contain exactly what is asked for in the question. "
|
30 |
"Be exact and concise in your answers. "
|
31 |
"Do not add explanations or additional information. "
|
32 |
"If asked for a list, provide ONLY the items requested separated by commas."
|
33 |
-
|
34 |
)
|
35 |
-
#*
|
36 |
-
model = HfApiModel(model_id=model_id, token=hf_token)
|
37 |
|
38 |
-
#
|
|
|
|
|
39 |
tools = [FinalAnswerTool()]
|
40 |
self.agent = CodeAgent(
|
41 |
tools=tools,
|
42 |
model=model,
|
43 |
add_base_tools=True,
|
44 |
-
max_steps=3
|
45 |
)
|
46 |
|
47 |
def __call__(self, question: str) -> str:
|
48 |
"""ONE question in → ONE pure-text answer out."""
|
49 |
-
#↓ Replace .run with whatever method actually returns the answer string.
|
50 |
result = self.agent.run(question)
|
51 |
-
return result
|
52 |
-
|
53 |
-
#answer = self.run
|
54 |
-
|
55 |
-
#agent.run(
|
56 |
-
# "At what temperature and for how long should I bake French baguettes made with type 65 flour?",
|
57 |
-
#)
|
|
|
1 |
+
import smolagents
|
2 |
+
import os
|
|
|
3 |
from smolagents import (
|
4 |
tool,
|
5 |
CodeAgent,
|
6 |
+
InferenceClientModel, # This is the correct model class to use
|
7 |
+
FinalAnswerTool
|
8 |
+
)
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
10 |
class newAgent:
|
11 |
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
12 |
def __init__(self):
|
13 |
+
model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
14 |
+
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
15 |
if not hf_token:
|
16 |
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
|
17 |
+
|
18 |
+
system_prompt = (
|
19 |
"You are an agent that answers exam questions. "
|
20 |
"Your answers should contain exactly what is asked for in the question. "
|
21 |
"Be exact and concise in your answers. "
|
22 |
"Do not add explanations or additional information. "
|
23 |
"If asked for a list, provide ONLY the items requested separated by commas."
|
|
|
24 |
)
|
|
|
|
|
25 |
|
26 |
+
# CORRECTED: Use InferenceClientModel instead of HfApiModel
|
27 |
+
model = InferenceClientModel(model_id=model_id, token=hf_token)
|
28 |
+
|
29 |
tools = [FinalAnswerTool()]
|
30 |
self.agent = CodeAgent(
|
31 |
tools=tools,
|
32 |
model=model,
|
33 |
add_base_tools=True,
|
34 |
+
max_steps=3
|
35 |
)
|
36 |
|
37 |
def __call__(self, question: str) -> str:
|
38 |
"""ONE question in → ONE pure-text answer out."""
|
|
|
39 |
result = self.agent.run(question)
|
40 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|