Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,25 +47,28 @@ class BasicAgent:
|
|
| 47 |
def __init__(self):
|
| 48 |
print("BasicAgent initialized.")
|
| 49 |
|
| 50 |
-
# 1. Kiểm tra nghiêm ngặt
|
| 51 |
-
|
| 52 |
-
if not
|
| 53 |
raise ValueError(
|
| 54 |
-
"\n❌ LỖI NGHIÊM TRỌNG: Không tìm thấy
|
| 55 |
-
"👉 Cách khắc phục:
|
| 56 |
-
"
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
else:
|
| 59 |
-
print(f"✅ Đã nhận
|
| 60 |
|
| 61 |
search_tool = DuckDuckGoSearchTool()
|
| 62 |
visit_tool = VisitWebpageTool()
|
| 63 |
|
| 64 |
-
# 2. Setup LLM sử dụng API
|
| 65 |
self.model = OpenAIServerModel(
|
| 66 |
-
model_id="
|
| 67 |
-
api_base="https://api
|
| 68 |
-
api_key=
|
| 69 |
)
|
| 70 |
|
| 71 |
# Setup CodeAgent
|
|
@@ -139,6 +142,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 139 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 140 |
continue
|
| 141 |
|
|
|
|
| 142 |
local_file_path = None
|
| 143 |
if file_name and str(file_name).strip() and str(file_name) != "None":
|
| 144 |
file_url = f"{api_url}/files/{task_id}"
|
|
@@ -175,7 +179,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 175 |
"Submitted Answer": f"AGENT ERROR: {e}"
|
| 176 |
})
|
| 177 |
|
| 178 |
-
# Nghỉ 2 giây sau mỗi câu hỏi để tránh
|
| 179 |
time.sleep(2)
|
| 180 |
|
| 181 |
if not answers_payload:
|
|
|
|
| 47 |
def __init__(self):
|
| 48 |
print("BasicAgent initialized.")
|
| 49 |
|
| 50 |
+
# 1. Kiểm tra nghiêm ngặt GROQ_API_KEY
|
| 51 |
+
groq_key = os.environ.get("GROQ_API_KEY")
|
| 52 |
+
if not groq_key:
|
| 53 |
raise ValueError(
|
| 54 |
+
"\n❌ LỖI NGHIÊM TRỌNG: Không tìm thấy GROQ_API_KEY trong môi trường Space!\n"
|
| 55 |
+
"👉 Cách khắc phục:\n"
|
| 56 |
+
" 1. Vào trang https://console.groq.com/keys để tạo API Key miễn phí.\n"
|
| 57 |
+
" 2. Vào tab Settings của Space -> Variables and secrets -> New secret.\n"
|
| 58 |
+
" 3. Đặt Name là 'GROQ_API_KEY', dán mã key của bạn vào Value rồi Save.\n"
|
| 59 |
+
" 4. Bấm Factory Reboot (ở mục Danger Zone) để Space nạp biến mới."
|
| 60 |
)
|
| 61 |
else:
|
| 62 |
+
print(f"✅ Đã nhận GROQ_API_KEY thành công (Độ dài: {len(groq_key)} ký tự).")
|
| 63 |
|
| 64 |
search_tool = DuckDuckGoSearchTool()
|
| 65 |
visit_tool = VisitWebpageTool()
|
| 66 |
|
| 67 |
+
# 2. Setup LLM sử dụng API siêu tốc của Groq (Mô hình Llama 3.3 70B)
|
| 68 |
self.model = OpenAIServerModel(
|
| 69 |
+
model_id="llama-3.3-70b-versatile",
|
| 70 |
+
api_base="https://api.groq.com/openai/v1",
|
| 71 |
+
api_key=groq_key
|
| 72 |
)
|
| 73 |
|
| 74 |
# Setup CodeAgent
|
|
|
|
| 142 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 143 |
continue
|
| 144 |
|
| 145 |
+
# Xử lý tải file đính kèm với hàm retry chống lỗi 429
|
| 146 |
local_file_path = None
|
| 147 |
if file_name and str(file_name).strip() and str(file_name) != "None":
|
| 148 |
file_url = f"{api_url}/files/{task_id}"
|
|
|
|
| 179 |
"Submitted Answer": f"AGENT ERROR: {e}"
|
| 180 |
})
|
| 181 |
|
| 182 |
+
# Nghỉ 2 giây sau mỗi câu hỏi để tránh bị máy chủ chấm điểm chặn IP
|
| 183 |
time.sleep(2)
|
| 184 |
|
| 185 |
if not answers_payload:
|