File size: 1,576 Bytes
461adca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Test script to verify Google Genai API integration
"""
import os
from google import genai
from google.genai import types


def test_gemini_api():
    """Test the new Gemini API"""
    api_key = os.environ.get("GEMINI_API_KEY")
    
    if not api_key:
        print("⚠️  GEMINI_API_KEY not found in environment variables")
        print("Set it in your .env file to test Gemini integration")
        return False
    
    try:
        client = genai.Client(api_key=api_key)
        
        # Test with a simple prompt
        contents = [
            types.Content(
                role="user",
                parts=[
                    types.Part.from_text(text="Say 'Hello from Gemini!' in JSON format: {\"message\": \"...\"}"),
                ],
            ),
        ]
        
        generate_content_config = types.GenerateContentConfig(
            temperature=0,
            max_output_tokens=100,
            response_mime_type="application/json",
        )

        print("🔄 Testing Gemini API connection...")
        response = client.models.generate_content(
            model="gemini-2.0-flash-exp",
            contents=contents,
            config=generate_content_config,
        )
        
        print("✅ Gemini API test successful!")
        print(f"Response: {response.text}")
        return True
        
    except Exception as e:
        print(f"❌ Gemini API test failed: {str(e)}")
        return False


if __name__ == "__main__":
    print("=" * 60)
    print("Google Gemini API Test")
    print("=" * 60)
    test_gemini_api()