#!/usr/bin/env python3
"""
Generated test file for Basic Error LLM Test
Framework: litellm
Execution mode: sync
Streaming: yes"""

import os
import sentry_sdk

import time

import litellm
from sentry_sdk.integrations.litellm import LiteLLMIntegration
from sentry_sdk.integrations.openai import OpenAIIntegration
import respx
import httpx

respx.route(host="api.anthropic.com").mock(return_value=httpx.Response(500, json={"error": {"message": "Server error", "type": "server_error"}}))
respx.mock.start()

sentry_sdk.init(
    dsn=os.environ.get("SENTRY_DSN"),
    traces_sample_rate=1.0,
    send_default_pii=True,
    stream_gen_ai_spans=True,
    integrations=[LiteLLMIntegration(include_prompts=True)],
    disabled_integrations=[OpenAIIntegration()],
)


def main():
    # Turn 1
    stream = litellm.responses(
        model="anthropic/claude-haiku-4-5",
        instructions="You are a helpful assistant.",
        input=[
        {
            "role": "user",
            "content": "What is the capital of France?"
        },
    ]
,
        stream=True,
    )

    collected_content = []
    for event in stream:
        if hasattr(event, "type") and event.type == "response.output_text.delta":
            collected_content.append(event.delta)

    full_response = "".join(collected_content)
    print(f"Turn 1 Response: {full_response}")
    time.sleep(0.1)  # sleep is necessary for LiteLLM because it needs threaded callbacks to finish

if __name__ == "__main__":
    try:
        with sentry_sdk.start_transaction(op="test", name="Basic Error LLM Test"):
            main()
    except Exception as e:
        print(f"Expected error: {type(e).__name__}: {e}")
        sentry_sdk.capture_exception(e)
    finally:
        sentry_sdk.flush(timeout=5)
