SreekarB commited on
Commit
e935875
Β·
verified Β·
1 Parent(s): 75d8ea0

Update annotated_casl_app.py

Browse files
Files changed (1) hide show
  1. annotated_casl_app.py +30 -8
annotated_casl_app.py CHANGED
@@ -124,7 +124,7 @@ def call_claude_api_quick_analysis(prompt):
124
  "https://api.anthropic.com/v1/messages",
125
  headers=headers,
126
  json=data,
127
- timeout=90
128
  )
129
 
130
  if response.status_code == 200:
@@ -1290,6 +1290,9 @@ def call_claude_api_with_continuation(prompt):
1290
  if not ANTHROPIC_API_KEY:
1291
  return "❌ Claude API key not configured. Please set ANTHROPIC_API_KEY environment variable."
1292
 
 
 
 
1293
  # Define all required sections
1294
  required_sections = [
1295
  "1. SPEECH FACTORS",
@@ -1347,14 +1350,33 @@ def call_claude_api_with_continuation(prompt):
1347
  ]
1348
  }
1349
 
1350
- response = requests.post(
1351
- "https://api.anthropic.com/v1/messages",
1352
- headers=headers,
1353
- json=data,
1354
- timeout=90
1355
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1356
 
1357
- if response.status_code == 200:
1358
  response_json = response.json()
1359
  response_text = response_json['content'][0]['text']
1360
 
 
124
  "https://api.anthropic.com/v1/messages",
125
  headers=headers,
126
  json=data,
127
+ timeout=180
128
  )
129
 
130
  if response.status_code == 200:
 
1290
  if not ANTHROPIC_API_KEY:
1291
  return "❌ Claude API key not configured. Please set ANTHROPIC_API_KEY environment variable."
1292
 
1293
+ print("πŸ”„ Starting comprehensive 12-section analysis...")
1294
+ print("⏱️ This may take 3-5 minutes for complex analyses...")
1295
+
1296
  # Define all required sections
1297
  required_sections = [
1298
  "1. SPEECH FACTORS",
 
1350
  ]
1351
  }
1352
 
1353
+ # Retry logic for timeout errors
1354
+ max_retries = 3
1355
+ retry_count = 0
1356
+ response = None
1357
+
1358
+ while retry_count < max_retries:
1359
+ try:
1360
+ response = requests.post(
1361
+ "https://api.anthropic.com/v1/messages",
1362
+ headers=headers,
1363
+ json=data,
1364
+ timeout=180
1365
+ )
1366
+ break # Success, exit retry loop
1367
+ except requests.exceptions.Timeout:
1368
+ retry_count += 1
1369
+ if retry_count < max_retries:
1370
+ print(f"⏱️ Timeout occurred, retrying ({retry_count}/{max_retries})...")
1371
+ time.sleep(5) # Wait 5 seconds before retry
1372
+ else:
1373
+ print(f"❌ Max retries ({max_retries}) exceeded due to timeouts")
1374
+ return f"❌ Error: API timeout after {max_retries} attempts. The analysis request is too complex. Try using 'Targeted Analysis' for specific sections."
1375
+ except Exception as e:
1376
+ print(f"❌ API call failed: {str(e)}")
1377
+ return f"❌ Error: {str(e)}"
1378
 
1379
+ if response and response.status_code == 200:
1380
  response_json = response.json()
1381
  response_text = response_json['content'][0]['text']
1382