Docs
SDKs
WeavelClient

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

ParameterTypeOptionalDescription
user_idstringnoThe user's identifier.
trace_idstringnoThe conversation's identifier.
timestampdatetimeyesThe timestamp from which the trace should start.
metadataDict[str, Any]yesThe 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

ParameterTypeOptionalDescription
user_idstringnoThe user's identifier.
trace_idstringnoThe 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

ParameterTypeOptionalDescription
user_idstringnoThe user's identifier.
event_namestringnoThe name of the tracked event.
propertiesDict[str, Any]noProperties 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

ParameterTypeOptionalDescription
trace_data_idstringnoThe message's identifier.
metadataDict[str, Any]noProperties of the tracked event.
timestampdatetimeyesThe 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

ParameterTypeOptionalDescription
user_idstringnoThe user's identifier.
propertiesDict[str, Any]noProperties 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.