#!/usr/bin/env python3
"""
Generated test file for Conversation ID LLM Test
Framework: google-genai
Execution mode: async
Streaming: no"""

import os
import sentry_sdk
import asyncio

from google import genai


sentry_sdk.init(
    dsn=os.environ.get("SENTRY_DSN"),
    traces_sample_rate=1.0,
    send_default_pii=True,
    stream_gen_ai_spans=True,
)

# Initialize Google GenAI client
client = genai.Client(
    api_key=os.environ["GOOGLE_GENAI_API_KEY"],
)

async def main():
    # Turn 1
    sentry_sdk.ai.set_conversation_id("conv-a")
    

    try:
        response = await client.aio.models.generate_content(
            model="gemini-2.5-flash-lite",
            contents="What is the capital of France?",
            config=genai.types.GenerateContentConfig(
                system_instruction="You are a helpful assistant.",
            ),
        )
        print(f"Turn 1 Response: {response.text}")
    except Exception as e:
        sentry_sdk.capture_exception(e)
        print(f"Error: {e}")

    # Turn 2
    sentry_sdk.ai.set_conversation_id("conv-b")
    

    try:
        response = await client.aio.models.generate_content(
            model="gemini-2.5-flash-lite",
            contents="What is 2 + 2?",
            config=genai.types.GenerateContentConfig(
                system_instruction="You are a math tutor.",
            ),
        )
        print(f"Turn 2 Response: {response.text}")
    except Exception as e:
        sentry_sdk.capture_exception(e)
        print(f"Error: {e}")

    # Turn 3
    sentry_sdk.ai.set_conversation_id("conv-a")
    

    try:
        response = await client.aio.models.generate_content(
            model="gemini-2.5-flash-lite",
            contents="What about Germany?",
            config=genai.types.GenerateContentConfig(
                system_instruction="You are a helpful assistant.",
            ),
        )
        print(f"Turn 3 Response: {response.text}")
    except Exception as e:
        sentry_sdk.capture_exception(e)
        print(f"Error: {e}")

    # Turn 4
    sentry_sdk.ai.set_conversation_id("conv-b")
    

    try:
        response = await client.aio.models.generate_content(
            model="gemini-2.5-flash-lite",
            contents="What about 3 + 3?",
            config=genai.types.GenerateContentConfig(
                system_instruction="You are a math tutor.",
            ),
        )
        print(f"Turn 4 Response: {response.text}")
    except Exception as e:
        sentry_sdk.capture_exception(e)
        print(f"Error: {e}")

if __name__ == "__main__":
    with sentry_sdk.start_transaction(op="test", name="Conversation ID LLM Test"):
        asyncio.run(main())
    sentry_sdk.flush(timeout=5)
