import json
import os
from pathlib import Path
import httpx

with httpx.Client(
    base_url="https://api.blatent.ai",
    headers={"Authorization": f"Bearer {os.environ['BLATENT_API_KEY']}"},
    timeout=195,
) as client:
    registration = client.post("/v1/schemas", json={
        "name": "support/triage",
        "version": "0.0.1",
        "schema": json.loads(Path("triage.schema.json").read_text(encoding="utf-8")),
    })
    registration.raise_for_status()
    schema_id = registration.json()["schema_id"]

    for message in [
        "The invoice was charged twice. Can you help me get the duplicate charge refunded?",
        "The app crashes every time I open my settings."
    ]:
        response = client.post("/v1/resolve", json={
            "input": message, "schema_id": schema_id,
        })
        response.raise_for_status()
        print(json.dumps(response.json()["output"]))
