WeavelClient
WeavelClient acts as the entry point for logging conversational data to the Weavel server.
Every requests with WeavelClient are queued and sent to the server in a batch. This reduces the latency and the number of requests to the server.
Initialize
from weavel import create_client
client = create_client()
Methods
open_trace
Parameter | Type | Optional | Description |
---|---|---|---|
user_id | string | no | The user's identifier. |
trace_id | string | no | The conversation's identifier. |
timestamp | datetime | yes | The timestamp from which the trace should start. |
metadata | Dict[str, Any] | yes | The metadata to be sent to the server. |
Example Usage
trace = client.open_trace(
user_id="<YOUR_UNIQUE_USER_ID>",
trace_id="<YOUR_UNIQUE_TRACE_ID>",
timestamp=datetime.now(),
metadata={
"character": "John",
"page": "settings"
})
open_trace
returns a Trace object, and logs the start of a conversation to the Weavel server.
Adding Metadata
We recommend using the metadata parameter to include information about the conversation, such as the character name who participated in conversation or the webpage where the conversation started.
This metadata will be automatically analyzed and visualized on the Weavel platform.
resume_trace
Parameter | Type | Optional | Description |
---|---|---|---|
user_id | string | no | The user's identifier. |
trace_id | string | no | The conversation's identifier. |
Example Usage
trace = client.resume_trace(
user_id="<YOUR_UNIQUE_USER_ID>",
trace_id="<YOUR_UNIQUE_TRACE_ID>",
)
resume_trace
returns a Trace object.
You can use this method to resume a conversation that was previously started with the open_trace
method.
track
Parameter | Type | Optional | Description |
---|---|---|---|
user_id | string | no | The user's identifier. |
event_name | string | no | The name of the tracked event. |
properties | Dict[str, Any] | no | Properties of the tracked event. |
Example Usage
client.track(
user_id="<YOUR_UNIQUE_USER_ID>",
event_name="paid",
properties={
"amount": "100"
}
)
Use this event to track events such as button clicks, page views, successful payments, etc.
You can think of this as a way to log events that are not part of a conversation.
log_message_metadata
Parameter | Type | Optional | Description |
---|---|---|---|
trace_data_id | string | no | The message's identifier. |
metadata | Dict[str, Any] | no | Properties of the tracked event. |
timestamp | datetime | yes | The timestamp. |
Example Usage
trace.log_message_metadata(
trace_data_id="message_1",
metadata={
"feedback": "like"
}
)
trace.log_message_metadata(
trace_data_id="message_2",
metadata={
"feedback": "dislike"
}
)
You can add metadata to the message by using the log_message_metadata
method.
This is recommended for logging user feedback on AI responses, such as when a user clicks like or dislike buttons.
identify
Parameter | Type | Optional | Description |
---|---|---|---|
user_id | string | no | The user's identifier. |
properties | Dict[str, Any] | no | Properties of the user. |
Example Usage
client.identify(
user_id="<YOUR_UNIQUE_USER_ID>",
properties={
"email": "user@email.com",
"name": "John Doe",
"age": "25",
}
)
Use the identify method to identify a user and send user properties such as email, name, and age, etc.
This information will be automatically analyzed and visualized on the Weavel platform.