Update app.py
Browse files
app.py
CHANGED
|
@@ -6,35 +6,42 @@ from smolagents import CodeAgent, HfApiModel, VisitWebpageTool
|
|
| 6 |
|
| 7 |
# Model ve Token Ayarları
|
| 8 |
token = os.getenv("HF_TOKEN")
|
|
|
|
| 9 |
model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct", token=token)
|
| 10 |
|
| 11 |
class AlfredAgent:
|
| 12 |
def __init__(self):
|
| 13 |
-
#
|
| 14 |
-
CUSTOM_SYSTEM_PROMPT = """You are a
|
| 15 |
-
Solve the given task by writing Python code.
|
| 16 |
-
You have access to a web search tool and a tool to visit webpages.
|
| 17 |
-
|
| 18 |
{{managed_agents_descriptions}}
|
| 19 |
{{authorized_imports}}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
self.agent = CodeAgent(
|
| 25 |
tools=[VisitWebpageTool()],
|
| 26 |
model=model,
|
| 27 |
-
max_steps=
|
| 28 |
add_base_tools=True,
|
| 29 |
-
additional_authorized_imports=['requests', 'bs4', 'pandas', 'json', 'math', 're'
|
| 30 |
system_prompt=CUSTOM_SYSTEM_PROMPT
|
| 31 |
)
|
| 32 |
|
| 33 |
def __call__(self, question: str) -> str:
|
| 34 |
try:
|
| 35 |
-
# Modelin
|
| 36 |
result = self.agent.run(question)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
return "Unknown"
|
| 40 |
|
|
|
|
| 6 |
|
| 7 |
# Model ve Token Ayarları
|
| 8 |
token = os.getenv("HF_TOKEN")
|
| 9 |
+
# 1. Modeli Qwen olarak değiştiriyoruz (Kota engeline takılmaz)
|
| 10 |
model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct", token=token)
|
| 11 |
|
| 12 |
class AlfredAgent:
|
| 13 |
def __init__(self):
|
| 14 |
+
# En basit, kütüphanenin en sevdiği prompt yapısı
|
| 15 |
+
CUSTOM_SYSTEM_PROMPT = """You are a GAIA expert. Solve the task using Python code.
|
|
|
|
|
|
|
|
|
|
| 16 |
{{managed_agents_descriptions}}
|
| 17 |
{{authorized_imports}}
|
| 18 |
|
| 19 |
+
Rules:
|
| 20 |
+
1. Use web_search or visit_webpage for information.
|
| 21 |
+
2. If you find a file (audio/video), search for its name on the web to get details.
|
| 22 |
+
3. The LAST LINE of your code must be the final answer variable.
|
| 23 |
+
4. Final answer must be short (e.g., '15', 'Paris')."""
|
| 24 |
|
| 25 |
self.agent = CodeAgent(
|
| 26 |
tools=[VisitWebpageTool()],
|
| 27 |
model=model,
|
| 28 |
+
max_steps=12, # Adım sayısını 12'de tutalım ki model yorulmasın
|
| 29 |
add_base_tools=True,
|
| 30 |
+
additional_authorized_imports=['requests', 'bs4', 'pandas', 'json', 'math', 're'],
|
| 31 |
system_prompt=CUSTOM_SYSTEM_PROMPT
|
| 32 |
)
|
| 33 |
|
| 34 |
def __call__(self, question: str) -> str:
|
| 35 |
try:
|
| 36 |
+
# Modelin doğal akışını bozmadan çalıştır
|
| 37 |
result = self.agent.run(question)
|
| 38 |
+
ans = str(result).strip()
|
| 39 |
+
|
| 40 |
+
# Sadece basit bir temizlik (Eğer çok uzunsa son satırı al)
|
| 41 |
+
if len(ans) > 50 and "\n" in ans:
|
| 42 |
+
ans = ans.split('\n')[-1].replace("Final Answer:", "").strip()
|
| 43 |
+
|
| 44 |
+
return ans[:50]
|
| 45 |
except Exception as e:
|
| 46 |
return "Unknown"
|
| 47 |
|