"""
Test Anthropic instrumentation against local Latitude instance.

Required env vars:
- LATITUDE_API_KEY
- LATITUDE_PROJECT_SLUG
- ANTHROPIC_API_KEY

Install: uv add anthropic
"""

import os

import anthropic
from anthropic import Anthropic

from latitude_telemetry import Latitude, capture

# Initialize telemetry pointing to local instance
latitude = Latitude(
    api_key=os.environ["LATITUDE_API_KEY"],
    project=os.environ["LATITUDE_PROJECT_SLUG"],
    instrumentations={"anthropic": anthropic},
    disable_batch=True,
)


@capture("test-anthropic-completion", {"tags": ["python", "test"], "session_id": "example"})
def test_anthropic_completion():
    client = Anthropic()

    response = client.messages.create(
        model="claude-3-5-haiku-latest",
        max_tokens=50,
        messages=[{"role": "user", "content": "Say 'Hello from Anthropic!' in exactly 5 words."}],
    )

    return response.content[0].text


if __name__ == "__main__":
    test_anthropic_completion()
    latitude.flush()
