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

import os
import sentry_sdk
import asyncio

from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage, SystemMessage, AIMessage


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

chat = ChatAnthropic(model="claude-haiku-4-5")

async def main():
    # Turn 1
    sentry_sdk.ai.set_conversation_id("conv-a")
    messages = [
        SystemMessage(content="You are a helpful assistant."),
        HumanMessage(content="What is the capital of France?"),
    ]
    response = await chat.ainvoke(messages)
    print(f"Turn 1 Response: {response.content}")

    # Turn 2
    sentry_sdk.ai.set_conversation_id("conv-b")
    messages = [
        SystemMessage(content="You are a math tutor."),
        HumanMessage(content="What is 2 + 2?"),
    ]
    response = await chat.ainvoke(messages)
    print(f"Turn 2 Response: {response.content}")

    # Turn 3
    sentry_sdk.ai.set_conversation_id("conv-a")
    messages = [
        SystemMessage(content="You are a helpful assistant."),
        HumanMessage(content="What is the capital of France?"),
        AIMessage(content="The capital of France is Paris."),
        HumanMessage(content="What about Germany?"),
    ]
    response = await chat.ainvoke(messages)
    print(f"Turn 3 Response: {response.content}")

    # Turn 4
    sentry_sdk.ai.set_conversation_id("conv-b")
    messages = [
        SystemMessage(content="You are a math tutor."),
        HumanMessage(content="What is 2 + 2?"),
        AIMessage(content="2 + 2 equals 4."),
        HumanMessage(content="What about 3 + 3?"),
    ]
    response = await chat.ainvoke(messages)
    print(f"Turn 4 Response: {response.content}")

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