Trace
A Trace object is used to log conversational data to the Weavel server.
Methods
log_message
Parameter | Type | Optional | Description |
---|---|---|---|
type | string | no | The role of message. |
content | string | no | The message content. |
trace_data_id | string | yes | The message(trace_data) identifier |
timestamp | datetime | yes | The timestamp. |
unit_name | string | yes | The unit name. |
metadata | Dict[str, Any] | yes | The metadata to be added. |
Example Usage
trace.log_message("system", "you are a helpful assistant.")
trace.log_message("assistant", res, unit_name="test_assistant")
trace.log_message("user", user_message)
log_message
method of Trace
object is used to log messages to the Weavel server.
You can log system messages, assistant messages, and user messages.
Adding Metadata
trace.log_message(
"assistant",
assistant_message,
metadata={
"module": "planning_module",
"model": "gpt-4o",
"document_types": "medical",
"function_call": "search_document"
}
)
Including metadata is recommended if there is additional information about the AI's response.
This metadata will be automatically analyzed and visualized on the Weavel platform.
For example, you can add metadata about the AI model name, retrieved document types, used module or functions to generate the response, etc.
You can also add identifier of message by using trace_data_id
parameter, if you want to update the metadata of the message later.
log_inner_step
Parameter | Type | Optional | Description |
---|---|---|---|
content | string | no | The message content. |
timestamp | datetime | yes | The timestamp. |
unit_name | string | yes | The unit name. |
metadata | Dict[str, Any] | yes | The metadata to be added. |
You can log inner steps of a trace, other than messages, by using the log_inner_step
method.
For example, you can log the retrieved data of a RAG step before logging the generated assistant message.