Metadata-Version: 2.4
Name: letterbook-ai-chat
Version: 1.0.0
Summary: Python SDK for sending AI chat turns to Letterbook for issue detection
Author: Letterbook
License: MIT
Keywords: ai,chat,helpdesk,letterbook,support
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.8
Provides-Extra: otel
Requires-Dist: opentelemetry-api<1.34,>=1.0; (python_version < '3.9') and extra == 'otel'
Requires-Dist: opentelemetry-api<1.42,>=1.0; (python_version >= '3.9' and python_version < '3.10') and extra == 'otel'
Requires-Dist: opentelemetry-api<2.0,>=1.0; (python_version >= '3.10') and extra == 'otel'
Description-Content-Type: text/markdown

# Letterbook AI Chat Python SDK

Send AI chat turns to Letterbook so customer issues can be detected from the full conversation.

Each call captures one turn in the conversation. It does not create a ticket by itself. Letterbook queues the turns, waits for the conversation to go quiet, scans the transcript on the backend with an LLM, and creates a ticket only when it finds a relevant customer issue.

```python
import letterbook

result = letterbook.record_turn(
    user_id="user123",
    event="user_message",
    model="gpt_4",
    input="The checkout page is broken and I was charged twice.",
    output="I am sorry, I cannot fix billing issues from here.",
    convo_id="conv789",
    customer_email="customer@example.com",
    debounce_seconds=300,
    properties={
        "system_prompt": "you are a helpful assistant",
        "experiment": "experiment_a",
    },
    attachments=[
        {
            "type": "text",
            "name": "Additional Info",
            "value": "A very long document",
            "role": "input",
        }
    ],
)

print(result.queued, result.evaluation_after_seconds)
```

Set `LETTERBOOK_API_KEY`, or instantiate `letterbook.Letterbook(api_key=...)` for explicit configuration.
Set `debounce_seconds` to control how long Letterbook waits after the last message before evaluating the conversation.
If OpenTelemetry is configured in your app, the SDK automatically propagates the active trace context with each capture request. You can install `letterbook-ai-chat[otel]` if your app does not already include OpenTelemetry.

If `customer_email` is omitted, the SDK looks for `properties["customer_email"]`, `properties["email"]`, or an email-shaped `user_id`.
Email is only required if Letterbook promotes the capture to a ticket.

`letterbook.capture_turn(...)` and `letterbook.capture(...)` are deprecated compatibility aliases for `letterbook.record_turn(...)`.
