bug fix
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import requests
|
|
| 6 |
import pandas as pd
|
| 7 |
from langchain_core.messages import HumanMessage
|
| 8 |
from agent import build_graph
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -63,24 +64,32 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 63 |
|
| 64 |
# 2. Fetch Questions
|
| 65 |
print(f"Fetching questions from: {questions_url}")
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# 3. Run your Agent
|
| 86 |
results_log = []
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
from langchain_core.messages import HumanMessage
|
| 8 |
from agent import build_graph
|
| 9 |
+
import time
|
| 10 |
|
| 11 |
|
| 12 |
|
|
|
|
| 64 |
|
| 65 |
# 2. Fetch Questions
|
| 66 |
print(f"Fetching questions from: {questions_url}")
|
| 67 |
+
for i in range(5):
|
| 68 |
+
try:
|
| 69 |
+
response = requests.get(questions_url, timeout=15)
|
| 70 |
+
response.raise_for_status()
|
| 71 |
+
questions_data = response.json()
|
| 72 |
+
if not questions_data:
|
| 73 |
+
print("Fetched questions list is empty.")
|
| 74 |
+
return "Fetched questions list is empty or invalid format.", None
|
| 75 |
+
print(f"Fetched {len(questions_data)} questions.")
|
| 76 |
+
break
|
| 77 |
+
except requests.exceptions.RequestException as e:
|
| 78 |
+
print(f"Error fetching questions: {e}")
|
| 79 |
+
return f"Error fetching questions: {e}", None
|
| 80 |
+
except requests.exceptions.JSONDecodeError as e:
|
| 81 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 82 |
+
print(f"Response text: {response.text[:500]}")
|
| 83 |
+
return f"Error decoding server response for questions: {e}", None
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"An unexpected error occurred fetching questions: {e}")
|
| 86 |
+
return f"An unexpected error occurred fetching questions: {e}", None
|
| 87 |
+
except requests.exceptions.HTTPError as e:
|
| 88 |
+
if response.status_code == 429:
|
| 89 |
+
print("429 Too Many Requests. Waiting before retry...")
|
| 90 |
+
time.sleep(30) # 30秒待つ
|
| 91 |
+
else:
|
| 92 |
+
raise
|
| 93 |
|
| 94 |
# 3. Run your Agent
|
| 95 |
results_log = []
|