s1144662 commited on
Commit
8ce9d0c
·
verified ·
1 Parent(s): af0914d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -6,12 +6,12 @@ import time
6
  from typing import Optional
7
  from smolagents import CodeAgent, OpenAIServerModel, tool
8
 
9
- # --- 搜尋工具 (修正安裝指令版) ---
10
  try:
11
  from duckduckgo_search import DDGS
12
  except ImportError:
13
  import os
14
- # 修正:這裡必須完整的套件名稱
15
  os.system('pip install duckduckgo-search')
16
  from duckduckgo_search import DDGS
17
 
@@ -24,17 +24,18 @@ def web_search(query: str) -> str:
24
  """
25
  print(f"🕵️ [Debug] Searching: {query}")
26
  try:
27
- # 強制冷靜 1 秒
28
  time.sleep(1.0)
29
 
30
  with DDGS() as ddgs:
31
- # 使用 lite 模式繞過封鎖
32
  results = list(ddgs.text(query, max_results=1, backend="lite"))
33
 
34
  if not results:
35
  return "No results. Guess answer."
36
 
37
- # 截斷內容,節省 Token
 
38
  first = results[0]
39
  summary = f"Title: {first.get('title','')}\nInfo: {first.get('body','')}"
40
  return summary[:400]
@@ -54,6 +55,7 @@ class GroqAgent:
54
  self.agent = None
55
  return
56
 
 
57
  model = OpenAIServerModel(
58
  model_id="llama-3.3-70b-versatile",
59
  api_base="https://api.groq.com/openai/v1",
@@ -72,7 +74,7 @@ class GroqAgent:
72
  return "Error: GROQ_API_KEY not configured."
73
 
74
  try:
75
- # 強制冷靜 2 秒
76
  time.sleep(2.0)
77
 
78
  prompt = f"""
@@ -139,8 +141,8 @@ def run_and_submit_all(profile: Optional[gr.OAuthProfile] = None):
139
  except Exception as e:
140
  return f"Submit error: {str(e)}", pd.DataFrame(logs)
141
 
142
- with gr.Blocks(title="Final Agent (Fixed Import)") as demo:
143
- gr.Markdown("# 🚀 Final Agent (Fixed Import)")
144
  with gr.Row():
145
  gr.LoginButton()
146
  btn = gr.Button("Run Evaluation", variant="primary")
 
6
  from typing import Optional
7
  from smolagents import CodeAgent, OpenAIServerModel, tool
8
 
9
+ # --- 搜尋工具 (修正安裝指令 + 省流量版) ---
10
  try:
11
  from duckduckgo_search import DDGS
12
  except ImportError:
13
  import os
14
+ # 修正:使正確的套件名稱進行安裝
15
  os.system('pip install duckduckgo-search')
16
  from duckduckgo_search import DDGS
17
 
 
24
  """
25
  print(f"🕵️ [Debug] Searching: {query}")
26
  try:
27
+ # 強制冷靜 1 秒,保護新 Key
28
  time.sleep(1.0)
29
 
30
  with DDGS() as ddgs:
31
+ # 使用 lite 模式,只抓 1 筆
32
  results = list(ddgs.text(query, max_results=1, backend="lite"))
33
 
34
  if not results:
35
  return "No results. Guess answer."
36
 
37
+ # 關鍵保命符:截斷內容
38
+ # 只回傳前 400 字,避免瞬間 Token 爆量導致卡死
39
  first = results[0]
40
  summary = f"Title: {first.get('title','')}\nInfo: {first.get('body','')}"
41
  return summary[:400]
 
55
  self.agent = None
56
  return
57
 
58
+ # 使用 Llama 3.3 70B
59
  model = OpenAIServerModel(
60
  model_id="llama-3.3-70b-versatile",
61
  api_base="https://api.groq.com/openai/v1",
 
74
  return "Error: GROQ_API_KEY not configured."
75
 
76
  try:
77
+ # 強制冷靜 2 秒,避免觸發 RPM 限制
78
  time.sleep(2.0)
79
 
80
  prompt = f"""
 
141
  except Exception as e:
142
  return f"Submit error: {str(e)}", pd.DataFrame(logs)
143
 
144
+ with gr.Blocks(title="Final Agent (New Key + Token Safe)") as demo:
145
+ gr.Markdown("# 🚀 Final Agent (New Key)")
146
  with gr.Row():
147
  gr.LoginButton()
148
  btn = gr.Button("Run Evaluation", variant="primary")