#!/usr/bin/env python3
# test_genai2.py — Testē google-genai (JAUNĀ pakete)

import os
from pathlib import Path

env_path = Path(__file__).resolve().parent / ".env"
if env_path.exists():
    with open(env_path) as f:
        for line in f:
            line = line.strip()
            if line and not line.startswith("#") and "=" in line:
                key, _, val = line.partition("=")
                os.environ.setdefault(key.strip(), val.strip())

api_key = os.getenv("GEMINI_API_KEY", "")
print(f"API Key: {api_key[:15]}...{api_key[-4:]}\n")

try:
    from google import genai
    from google.genai import types
    print("✅ google-genai instalēts!")
except ImportError:
    print("❌ google-genai NAV instalēts!")
    print("   Pievieno requirements.txt: google-genai")
    print("   Tad: Run Pip Install")
    exit(1)

try:
    client = genai.Client(api_key=api_key)
    response = client.models.generate_content(
        model="gemini-2.5-flash",
        contents="Saki 'Sveiki Latvija!' latviski vienā teikumā.",
    )
    print(f"✅ Gemini atbild: {response.text.strip()}")
    print("\n🎉 VISS STRĀDĀ! Augšupielādē gemini_client.py un restartē!")
except Exception as e:
    print(f"❌ Kļūda: {e}")
