Skip to content

Adding attributes

Here we'll cover how to add attributes to a previous event. For instance, you may want to add feedback to a previous assistant message.

Identifying your events

First you will want to tag your events with an ID. This can be done with either a prompt_id or a generation_id:

const properties = { $prompt_id: "6720tb-726du-9461", $generation_id: "1532ds-243kj-3538" };

const llmFunction = (messages) => openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages
});

const completion = await trubrics.withProperties(properties, () => llmFunction(messages));

This ensures you are able to link back to the prompt and its corresponding generation.

Adding attributes

Those same ID's can then be used to add attributes. Attributes can only be added to one message at a time so be sure to only include a prompt_id OR a generation_id.

For example, to add positive feedback to the previous generation:

trubrics.addMessageAttributes({
    generation_id: "1532ds-243kj-3538",
    attributes: [
        {
            attribute_id: 7,
            value: 1
        }
    ]
});

The attribute_id can be found in your Trubrics account under Text Attributes. It is generated when you create an attribute.