Spaces:
Sleeping
Sleeping
fix(api): ensure fallback to third API key is properly handled
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ def genai_configuration():
|
|
| 20 |
return
|
| 21 |
|
| 22 |
except Exception:
|
| 23 |
-
print("⚠️
|
| 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("⚠️
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 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()
|