How to pass user feedback

When you are using Langtrace, you can pass both user id and user feedback using the with_additional_attributes function.

This helps with understanding usage patterns and measure the accuracy of your application from your user’s perspective.

Installation

Step 1: Install and initialize Langtrace SDK. Refer to the installation guide for more information.

// Must precede any llm module imports
import * as Langtrace from "@langtrase/typescript-sdk";
Langtrace.init({ api_key: "<LANGTRACE_API_KEY>" });

Usage

Step 2: See the example below to understand how to pass user feedback and user id. Make sure you use the following attributes:

  • user.id: A unique identifier for the user.
  • user.feedback.rating: A score from -1 to 1, where -1 is negative feedback, 0 is neutral, and 1 is positive feedback.
import * as Langtrace from "@langtrase/typescript-sdk";

async function apiCall() {
  return Langtrace.withAdditionalAttributes(
    () => {
      return client.chat.completions.create({
        model: "gpt-4",
        messages: [{ role: "user", content: "Hello, how to setup Langtrace?" }],
        stream: false,
      });
    },
    { "user.id": "uuid-1234", "user.feedback.rating": 1 }
  );
}

async function chatCompletion() {
  await apiCall();
}