vioott commited on
Commit
48d9602
·
1 Parent(s): a204d40

fix(api): ensure fallback to third API key is properly handled

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -20,7 +20,7 @@ def genai_configuration():
20
  return
21
 
22
  except Exception:
23
- print("⚠️ Falha com a chave principal, tentando chave reserva 1.")
24
 
25
  try:
26
  genai.configure(api_key=os.environ['GOOGLE_API_KEY_2'])
@@ -28,22 +28,23 @@ def genai_configuration():
28
  # Testa se a chave reserva 1 está disponível
29
  test_model = genai.GenerativeModel("gemini-1.5-flash")
30
  test_model.start_chat().send_message("ping")
31
-
32
  return
33
 
34
  except Exception:
35
- print("⚠️ Falha com a chave reserva 1, tentando chave reserva 2.")
36
 
37
- genai.configure(api_key=os.environ['GOOGLE_API_KEY_3'])
 
38
 
39
- # Testa se a chave reserva 2 está disponível
40
- test_model = genai.GenerativeModel("gemini-1.5-flash")
41
- test_model.start_chat().send_message("ping")
42
 
43
- return
44
 
45
- except Exception:
46
- print("❌ Todas as chaves falharam.")
47
 
48
 
49
  genai_configuration()
 
20
  return
21
 
22
  except Exception:
23
+ print("⚠️ Falha com a chave principal, tentando chave reserva 1.")
24
 
25
  try:
26
  genai.configure(api_key=os.environ['GOOGLE_API_KEY_2'])
 
28
  # Testa se a chave reserva 1 está disponível
29
  test_model = genai.GenerativeModel("gemini-1.5-flash")
30
  test_model.start_chat().send_message("ping")
31
+
32
  return
33
 
34
  except Exception:
35
+ print("⚠️ Falha com a chave reserva 1, tentando chave reserva 2.")
36
 
37
+ try:
38
+ genai.configure(api_key=os.environ['GOOGLE_API_KEY_3'])
39
 
40
+ # Testa se a chave reserva 2 está disponível
41
+ test_model = genai.GenerativeModel("gemini-1.5-flash")
42
+ test_model.start_chat().send_message("ping")
43
 
44
+ return
45
 
46
+ except Exception:
47
+ print("❌ Todas as chaves falharam.")
48
 
49
 
50
  genai_configuration()