File size: 736 Bytes
7c6ffa6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from google import genai

def test_gemini():
    api_key = os.environ.get("GEMINI_API_KEY", "")
    print(f"GEMINI_API_KEY from env: '{api_key[:5]}...' (len={len(api_key)})")
    
    try:
        # Initialize client (it will look at GEMINI_API_KEY automatically)
        client = genai.Client()
        # Test basic embed content
        response = client.models.embed_content(
            model="text-embedding-004",
            contents="Hello World"
        )
        print("Success! Generated embedding:")
        print(f"Vector length: {len(response.embeddings[0].values)}")
    except Exception as e:
        print(f"Failed to generate embedding with default client: {e}")

if __name__ == "__main__":
    test_gemini()