Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@
|
|
6 |
import os
|
7 |
import json
|
8 |
import requests
|
|
|
9 |
from typing import Dict, Any, List
|
10 |
|
11 |
# Импортируем агента
|
@@ -119,41 +120,48 @@ class GAIASubmitter:
|
|
119 |
print("Using cached submission response")
|
120 |
return self.cache[cache_key]
|
121 |
|
122 |
-
# Отправляем запрос на сервер
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
with open("response_content.txt", 'w', encoding='utf-8') as f:
|
129 |
-
f.write(response.text)
|
130 |
-
print("Response content saved to response_content.txt")
|
131 |
-
|
132 |
-
# Проверяем статус ответа
|
133 |
-
if response.status_code == 200:
|
134 |
-
print("Submission successful!")
|
135 |
-
result = response.json()
|
136 |
-
|
137 |
-
# Сохраняем результат для отладки
|
138 |
-
with open("results_response.txt", 'w', encoding='utf-8') as f:
|
139 |
-
json.dump(result, f, ensure_ascii=False, indent=2)
|
140 |
-
print("Results saved to results_response.txt")
|
141 |
|
142 |
-
# Сохраняем
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
print(error_msg)
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
157 |
|
158 |
def main():
|
159 |
"""
|
@@ -208,4 +216,4 @@ def main():
|
|
208 |
print(f"- {task_id}: {detail}")
|
209 |
|
210 |
if __name__ == "__main__":
|
211 |
-
main()
|
|
|
6 |
import os
|
7 |
import json
|
8 |
import requests
|
9 |
+
import time
|
10 |
from typing import Dict, Any, List
|
11 |
|
12 |
# Импортируем агента
|
|
|
120 |
print("Using cached submission response")
|
121 |
return self.cache[cache_key]
|
122 |
|
123 |
+
# Отправляем запрос на сервер с повторными попытками
|
124 |
+
max_retries = 3
|
125 |
+
for attempt in range(max_retries):
|
126 |
+
try:
|
127 |
+
print(f"Submitting answers to {API_URL} (attempt {attempt+1}/{max_retries})...")
|
128 |
+
response = requests.post(API_URL, json=submission_data, timeout=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
# Сохраняем ответ для отладки
|
131 |
+
with open("response_content.txt", 'w', encoding='utf-8') as f:
|
132 |
+
f.write(response.text)
|
133 |
+
print("Response content saved to response_content.txt")
|
134 |
|
135 |
+
# Проверяем статус ответа
|
136 |
+
if response.status_code == 200:
|
137 |
+
print("Submission successful!")
|
138 |
+
result = response.json()
|
139 |
+
|
140 |
+
# Сохраняем результат для отладки
|
141 |
+
with open("results_response.txt", 'w', encoding='utf-8') as f:
|
142 |
+
json.dump(result, f, ensure_ascii=False, indent=2)
|
143 |
+
print("Results saved to results_response.txt")
|
144 |
+
|
145 |
+
# Сохраняем в кэш
|
146 |
+
if self.use_cache:
|
147 |
+
self.cache[cache_key] = result
|
148 |
+
self._save_cache()
|
149 |
+
|
150 |
+
return result
|
151 |
+
else:
|
152 |
+
error_msg = f"HTTP error {response.status_code}: {response.text}"
|
153 |
+
print(error_msg)
|
154 |
+
|
155 |
+
except requests.exceptions.RequestException as e:
|
156 |
+
error_msg = f"Network error: {str(e)}"
|
157 |
print(error_msg)
|
158 |
+
|
159 |
+
# Экспоненциальная задержка перед следующей попыткой
|
160 |
+
delay = 2 ** attempt
|
161 |
+
print(f"Retrying in {delay} seconds...")
|
162 |
+
time.sleep(delay)
|
163 |
+
|
164 |
+
return {"error": f"All {max_retries} attempts failed"}
|
165 |
|
166 |
def main():
|
167 |
"""
|
|
|
216 |
print(f"- {task_id}: {detail}")
|
217 |
|
218 |
if __name__ == "__main__":
|
219 |
+
main()
|