File size: 1,387 Bytes
1f7ead8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import google.generativeai as genai
import sys
import os
# Add project root to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from backend.app.config import config
def find_working_model():
key = config.GEMINI_API_KEY
if not key:
print("ERROR: GEMINI_API_KEY is missing.")
return
genai.configure(api_key=key)
print("Searching for a working model...")
try:
# Iterate over all available models
for m in genai.list_models():
if 'generateContent' in m.supported_generation_methods:
print(f"Trying candidate: {m.name}...")
try:
model = genai.GenerativeModel(m.name)
# Simple test
response = model.generate_content("Test")
print(f"SUCCESS! WORKING MODEL FOUND: {m.name}")
with open("working_model.txt", "w") as f:
f.write(m.name)
print(f"Response: {response.text}")
return # Stop at first success
except Exception as e:
pass
# print(f" > Failed: {e}")
except Exception as e:
print(f"Error listing models: {e}")
if __name__ == "__main__":
find_working_model()
|