Python SDK for sending AI chat turns to Letterbook for issue detection
Project description
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.
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(...).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file letterbook_ai_chat-1.0.0.tar.gz.
File metadata
- Download URL: letterbook_ai_chat-1.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3d79bfa7d902e905884ae4d933e6c980a449f4d66939ca390f59209d536abe4
|
|
| MD5 |
d38492f0585ea030788aaec21432da4f
|
|
| BLAKE2b-256 |
2322ccdcf15377ea653155b9d48c07d413b8b0b1a193d6d700e2316592d28a99
|
File details
Details for the file letterbook_ai_chat-1.0.0-py3-none-any.whl.
File metadata
- Download URL: letterbook_ai_chat-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9d468ba69ac81d51404d0fc6ebd2efa0894d5a85575a807672b03e17f91c815
|
|
| MD5 |
c341fcb68e99943c2de7509cc5f43a18
|
|
| BLAKE2b-256 |
d1ab0d3243ce82d002963068be06bc27d836e320e02df984349f24ceef36e81e
|