Python
Here we'll cover how to collect events in python. Our SDK calls are non-blocking and fast, meaning they won't get in the way of your python app's performance.
Install (requires python>3.8)
Firstly, install Trubrics in your venv
with:
Getting started in python
Track your events with:
from trubrics_beta import Trubrics
trubrics = Trubrics(api_key="TRUBRICS_API_KEY")
trubrics.track( # use track_sync for synchronous requests
event="prompt",
user_id="user_id",
properties={
"$text": "tell me a story",
"$thread_id": "1234",
"a_custom_property": "a custom value",
},
)
API key
Your trubrics API key is unique to your project. Login to Trubrics, and copy your project API key from the settings
page. This is a write only API key that allows you to push events.
Parameter | Type | Description | Required |
---|---|---|---|
user_id |
str |
The distinct ID of the user that is signed in to your app. | yes |
event |
str |
The name of the event you are tracking. This can range from "User prompt", "Sign in", "Generation", etc. | yes |
properties |
dict[str,any] |
A list of properties of the event. For example, a "Generation" event could have properties "Cost of generation" or "Prompt template". Trubrics properties are prefixed with a $ . |
no |
If you have not implemented auth, use a UUID to assign events to an anonymous user.
Trubrics properties
Any property that begins with a $
is a property recognised by Trubrics. This allows us to perform certain actions in the ingestion pipeline and backend. Here are a list of Trubrics properties:
-
$text
: events that contain a textual element should use this property, as it allows Trubrics to tag the event with text attributes during ingestion. Text attributes can be managed directly in Trubrics. -
$thread_id
: to identify when a user is interacting with an AI assistant within their session. This allows you to distinguish between non-AI assistant interactions such as "Sign In" and events within a thread such as "Prompt" and "Generation". With an LLM powered assistant, this ID should be unique for each different conversation. -
$assistant_id
: events that are made by an assistant, such as "Generation" or "Query database". Typically for LLM assistants this can be set to the model name, such as "GPT-4" or "GPT-3.5-turbo".