This repository was archived by the owner on Dec 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 502
Expand file tree
/
Copy pathverify_models.py
More file actions
144 lines (111 loc) · 4.31 KB
/
verify_models.py
File metadata and controls
144 lines (111 loc) · 4.31 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
"""
Utility script to verify available Gemini models and test API connectivity.
This script helps users:
1. Verify their API key is working
2. See all available models
3. Test a specific model
Usage:
python verify_models.py
Set your API key as environment variable:
export GEMINI_API_KEY="your-api-key-here"
Or the script will prompt you for it.
"""
import os
import sys
def main():
"""Main function to verify models and API connectivity."""
try:
import google.generativeai as genai
except ImportError:
print("ERROR: google-generativeai package not installed.")
print("\nNote: This is the DEPRECATED SDK.")
print("Please install the NEW SDK instead:")
print(" pip install google-genai")
print("\nOr to use this deprecated SDK:")
print(" pip install google-generativeai")
sys.exit(1)
# Get API key
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
print("API key not found in environment variable GEMINI_API_KEY")
api_key = input("Please enter your API key: ").strip()
if not api_key:
print("ERROR: No API key provided.")
print("\nGet your API key from: https://aistudio.google.com/app/apikey")
sys.exit(1)
# Configure the SDK
try:
genai.configure(api_key=api_key)
print("✓ API key configured successfully\n")
except Exception as e:
print(f"ERROR: Failed to configure API key: {e}")
sys.exit(1)
# List available models
print("=" * 70)
print("AVAILABLE MODELS FOR CONTENT GENERATION")
print("=" * 70)
try:
models_found = False
for model in genai.list_models():
if 'generateContent' in model.supported_generation_methods:
models_found = True
print(f"\n📌 {model.name}")
print(f" Display Name: {model.display_name}")
print(f" Description: {model.description}")
print(f" Input Token Limit: {model.input_token_limit:,}")
print(f" Output Token Limit: {model.output_token_limit:,}")
if not models_found:
print("No models found with generateContent capability.")
except Exception as e:
print(f"\nERROR: Failed to list models: {e}")
print("\nPossible causes:")
print(" - Invalid API key")
print(" - Network connectivity issues")
print(" - API service temporarily unavailable")
sys.exit(1)
print("\n" + "=" * 70)
# Test a specific model
print("\nTESTING MODEL CONNECTIVITY")
print("=" * 70)
test_model_name = "gemini-1.5-flash"
try:
print(f"\nTesting model: {test_model_name}")
model = genai.GenerativeModel(test_model_name)
response = model.generate_content("Say 'Hello, World!' and nothing else.")
print(f"✓ Model test successful!")
print(f"Response: {response.text}")
except Exception as e:
print(f"\n✗ Model test failed: {e}")
sys.exit(1)
print("\n" + "=" * 70)
print("IMPORTANT NOTICE: DEPRECATED SDK")
print("=" * 70)
print("""
This SDK is DEPRECATED and will reach End-of-Life on November 30, 2025.
Please migrate to the new Google Generative AI SDK:
1. Uninstall old SDK: pip uninstall google-generativeai
2. Install new SDK: pip install google-genai
3. Follow migration guide: https://ai.google.dev/gemini-api/docs/migrate
For support and questions: https://discuss.ai.google.dev/c/gemini-api/4
""")
print("\n" + "=" * 70)
print("COMMON MODEL NAMES FOR THIRD-PARTY TOOLS")
print("=" * 70)
print("""
Use these model names in your VSCode extensions or other tools:
Recommended for most use cases:
• gemini-2.0-flash (newest model, fast)
• gemini-1.5-flash (fast, efficient)
• gemini-1.5-pro (more capable for complex tasks)
Latest versions (auto-updated):
• gemini-1.5-flash-latest
• gemini-1.5-pro-latest
❌ INVALID model names (will cause errors):
• Gemini-3-Pro-Preview (does not exist)
• gemini-3.0 (does not exist)
• gpt-4 (wrong API, that's OpenAI)
""")
print("\n✓ All checks passed!")
if __name__ == "__main__":
main()