-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gemini.py
More file actions
37 lines (27 loc) · 950 Bytes
/
Copy pathtest_gemini.py
File metadata and controls
37 lines (27 loc) · 950 Bytes
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
import os
import google.generativeai as genai
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def test_gemini():
"""Test Gemini API connection"""
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key or api_key == "your-google-api-key-here":
print("❌ No Gemini API key configured")
return False
try:
# Configure Gemini
genai.configure(api_key=api_key)
# Initialize model
model = genai.GenerativeModel('gemini-2.0-flash')
# Test with a simple prompt
response = model.generate_content("Hello! Please respond with just 'Hello from Gemini!'")
print(f"✅ Gemini API working!")
print(f"Response: {response.text}")
return True
except Exception as e:
print(f"❌ Gemini API error: {str(e)}")
return False
if __name__ == "__main__":
print("Testing Gemini API connection...")
test_gemini()