#!/usr/bin/env python3
"""
Generated test file for Multi-Turn LLM Test
Framework: langchain
Execution mode: sync
Streaming: yes"""

import os
import sentry_sdk

from langchain_openai import ChatOpenAI
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 = ChatOpenAI(model="gpt-5-nano")

def main():
    # Turn 1
    messages = [
        SystemMessage(content="You are a helpful assistant."),
        HumanMessage(content="What is the capital of France?"),
    ]
    chunks = []
    for chunk in chat.stream(messages):
        chunks.append(chunk.content)
    response_content = "".join(chunks)
    print(f"Turn 1 Response: {response_content}")

    # Turn 2
    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 is the population of that city?"),
    ]
    chunks = []
    for chunk in chat.stream(messages):
        chunks.append(chunk.content)
    response_content = "".join(chunks)
    print(f"Turn 2 Response: {response_content}")

    # Turn 3
    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 is the population of that city?"),
        AIMessage(content="Paris has a population of approximately 2.2 million people in the city proper."),
        HumanMessage(content="What about the metropolitan area?"),
    ]
    chunks = []
    for chunk in chat.stream(messages):
        chunks.append(chunk.content)
    response_content = "".join(chunks)
    print(f"Turn 3 Response: {response_content}")

if __name__ == "__main__":
    with sentry_sdk.start_transaction(op="test", name="Multi-Turn LLM Test"):
        main()
    sentry_sdk.flush(timeout=5)
