Spaces:
Sleeping
Sleeping
Hanson commited on
Commit ·
e02942a
1
Parent(s): 81917a3
update my agent with token
Browse files- app.py +12 -5
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -10,14 +10,21 @@ 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 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
|
| 14 |
+
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
# 使用免費的 AI 模型,並裝上 Google 搜尋工具
|
| 18 |
+
self.model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct")
|
| 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:
|
| 27 |
+
return f"Error: {e}"
|
| 28 |
|
| 29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 30 |
"""
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
gradio
|
| 2 |
-
requests
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
+
requests
|
| 3 |
+
smolagents
|