File size: 617 Bytes
4416e3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
from dotenv import load_dotenv
import google.generativeai as genai

load_dotenv()
api_key = os.getenv("GOOGLE_API_KEY")

if not api_key:
    print("Error: No API key found in .env")
else:
    try:
        genai.configure(api_key=api_key)
        # Try a model that was listed
        model = genai.GenerativeModel('gemini-flash-latest')
        print("Attempting to generate content with gemini-flash-latest...")
        response = model.generate_content("Say hello")
        print("Success! Response:", response.text)
    except Exception as e:
        print(f"Failed to call API: {e}")