s1144662 commited on
Commit
64ddbbc
·
verified ·
1 Parent(s): 9967c7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -5,7 +5,7 @@ import pandas as pd
5
  from typing import Optional
6
  from smolagents import CodeAgent, OpenAIServerModel, tool
7
 
8
- # --- 搜尋工具 ---
9
  try:
10
  from duckduckgo_search import DDGS
11
  except ImportError:
@@ -22,12 +22,12 @@ def web_search(query: str) -> str:
22
  """
23
  print(f"🕵️ [Debug] Searching: {query}")
24
  try:
25
- # 使用 backend='html' 比較穩定
26
  with DDGS() as ddgs:
27
- results = ddgs.text(query, max_results=3, backend="html")
28
 
29
  if not results:
30
- return "No results."
31
 
32
  formatted = []
33
  for r in results:
@@ -49,7 +49,8 @@ class GroqAgent:
49
  self.agent = None
50
  return
51
 
52
- # 🔥 改用 DeepSeek R1 (70B)
 
53
  model = OpenAIServerModel(
54
  model_id="deepseek-r1-distill-llama-70b",
55
  api_base="https://api.groq.com/openai/v1",
@@ -68,11 +69,12 @@ class GroqAgent:
68
  return "Error: GROQ_API_KEY not configured."
69
 
70
  try:
71
- # 針對 R1 模型的提示詞
72
  prompt = f"""
73
  Answer the question concisely.
74
- 1. Use 'web_search' for facts.
75
- 2. If search fails, guess immediately.
 
76
 
77
  Question: {question}
78
  """
 
5
  from typing import Optional
6
  from smolagents import CodeAgent, OpenAIServerModel, tool
7
 
8
+ # --- 搜尋工具 (DeepSeek R1 專用修復版) ---
9
  try:
10
  from duckduckgo_search import DDGS
11
  except ImportError:
 
22
  """
23
  print(f"🕵️ [Debug] Searching: {query}")
24
  try:
25
+ # 使用 backend='html' 來繞過 IP 封鎖
26
  with DDGS() as ddgs:
27
+ results = ddgs.text(query, max_results=4, backend="html")
28
 
29
  if not results:
30
+ return "No results found. The search tool is being rate-limited."
31
 
32
  formatted = []
33
  for r in results:
 
49
  self.agent = None
50
  return
51
 
52
+ # 🔥 關鍵修:使用 DeepSeek R1 (70B)
53
+ # 它的推理能力比 Llama 3.3 強,非常適合解決這種邏輯題
54
  model = OpenAIServerModel(
55
  model_id="deepseek-r1-distill-llama-70b",
56
  api_base="https://api.groq.com/openai/v1",
 
69
  return "Error: GROQ_API_KEY not configured."
70
 
71
  try:
72
+ # 針對 DeepSeek R1 的思維鏈提示詞
73
  prompt = f"""
74
  Answer the question concisely.
75
+ 1. Use 'web_search' to find facts.
76
+ 2. If search fails or returns no results, use your internal knowledge to GUESS immediately.
77
+ 3. Do not try to search more than once if it fails.
78
 
79
  Question: {question}
80
  """