Spaces:
Sleeping
Sleeping
Hanson commited on
Commit ·
204a2e7
1
Parent(s): e02942a
fix: remove hardcoded token and use env var
Browse files
app.py
CHANGED
|
@@ -10,17 +10,20 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
from smolagents import CodeAgent,
|
| 14 |
|
| 15 |
class BasicAgent:
|
| 16 |
-
def __init__(self):
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
self.search_tool = DuckDuckGoSearchTool()
|
| 20 |
self.agent = CodeAgent(tools=[self.search_tool], model=self.model)
|
| 21 |
|
| 22 |
def __call__(self, question: str) -> str:
|
| 23 |
-
# 讓 AI 開始自動查資料、思考並回答
|
| 24 |
try:
|
| 25 |
return str(self.agent.run(question))
|
| 26 |
except Exception as e:
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
| 14 |
|
| 15 |
class BasicAgent:
|
| 16 |
+
def __init__(self):
|
| 17 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 18 |
+
|
| 19 |
+
self.model = LiteLLMModel(
|
| 20 |
+
model_id="huggingface/Qwen/Qwen2.5-72B-Instruct",
|
| 21 |
+
token=hf_token # 帶入讀取到的變數
|
| 22 |
+
)
|
| 23 |
self.search_tool = DuckDuckGoSearchTool()
|
| 24 |
self.agent = CodeAgent(tools=[self.search_tool], model=self.model)
|
| 25 |
|
| 26 |
def __call__(self, question: str) -> str:
|
|
|
|
| 27 |
try:
|
| 28 |
return str(self.agent.run(question))
|
| 29 |
except Exception as e:
|