Spaces:
Sleeping
Sleeping
Update BasicAgent.py
Browse files- BasicAgent.py +23 -6
BasicAgent.py
CHANGED
@@ -1,16 +1,33 @@
|
|
1 |
-
import smolagents
|
2 |
-
from smolagents import CodeAgent, HfApiModel, InferenceClientModel, WebSearchTool
|
3 |
import numpy, math, xlrd, os
|
4 |
|
5 |
#model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
6 |
-
model_id = 'meta-llama/Llama-3.3-70B-Instruct'
|
|
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
#agent.run(
|
16 |
# "At what temperature and for how long should I bake French baguettes made with type 65 flour?",
|
|
|
1 |
+
#import smolagentsfrom smolagents import CodeAgent, HfApiModel, InferenceClientModel, WebSearchTool
|
|
|
2 |
import numpy, math, xlrd, os
|
3 |
|
4 |
#model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
5 |
+
#model_id = 'meta-llama/Llama-3.3-70B-Instruct'
|
6 |
+
|
7 |
+
#model = HfApiModel(model_id=model_id, token="HUGGINGFACEHUB_API_TOKEN")
|
8 |
|
9 |
+
#agent = CodeAgent(tools=[], model=model, add_base_tools=True)
|
10 |
+
|
11 |
+
#max_steps=5
|
12 |
+
#import os
|
13 |
+
from smolagents import CodeAgent, HfApiModel, InferenceClientModel, WebSearchTool
|
14 |
|
15 |
+
class BasicAgent:
|
16 |
+
"""Adapts smolagents.CodeAgent to the HF course template API."""
|
17 |
+
def __init__(self):
|
18 |
+
model_id = "meta-llama/Meta-Llama-3-70B-Instruct" # correct repo name
|
19 |
+
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") # read real secret
|
20 |
+
if not hf_token:
|
21 |
+
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
|
22 |
|
23 |
+
model = HfApiModel(model_id=model_id, token=hf_token)
|
24 |
+
# add_base_tools=True already gives you search, python, etc.
|
25 |
+
self.agent = CodeAgent(tools=[], model=model, add_base_tools=True)
|
26 |
|
27 |
+
def __call__(self, question: str) -> str:
|
28 |
+
"""ONE question in → ONE pure-text answer out."""
|
29 |
+
# ↓ Replace .run with whatever method actually returns the answer string.
|
30 |
+
return self.agent.run(question)
|
31 |
|
32 |
#agent.run(
|
33 |
# "At what temperature and for how long should I bake French baguettes made with type 65 flour?",
|