Skip to main content
Version: 2.0.0

Submitting feedback

When monitoring your production generative data with our SDK, you may need to capture feedback about the quality of your generative output.

The Feedback SDK is a tiny browser library that complements our SDK.

Package properties:

It links user feedback to your generative AI output and then submits that feedback to our service. The library is written in TypeScript.

Browsers only

We provide support for this library on most evergreen browsers. This package will likely not work on Node.JS, Deno, or Bun. If you want to submit feedback from mobile or desktop clients, we recommend directly using our API.

Installation

Install our npm package with the following command:

bash
npm i @gentrace/browser

Usage

The library needs to be configured with your account's client token, which is available in our application UI. The client token is a 40 character Base62 string that looks structurally different from our API keys. Namely, client tokens are not prefixed with gen_key.

We recommend setting the token as a build-time environment variable.

🛑No API Keys

Do not use an API key. The feedback routes will not authorize correctly and you risk leaking your credentials in your client bundles.

Here's an example of initializing the library with the client token loaded from an environment variable and submitting feedback.

typescript
import { Configuration, FeedbackApi } from "@gentrace/browser";
 
const config = new Configuration({
clientToken: process.env.GENTRACE_CLIENT_TOKEN,
});
 
const api = new FeedbackApi(config);

When your client directly provides feedback or performs a behavior that provides signal about the AI performance (e.g. accepting an AI suggestion, modifying AI output), invoke the following method to submit feedback.

typescript
import { Configuration, FeedbackApi } from "@gentrace/browser";
 
const config = new Configuration({
clientToken: process.env.GENTRACE_CLIENT_TOKEN,
});
 
const api = new FeedbackApi(config);
 
const response = await api.feedbackPost({
// Your server must pass down the pipeline run ID that was provided when you
// created the generation with the Monitoring SDK.
pipelineRunId: "c6e188ad-dd5c-4036-aa07-dee4534fd3cf",
 
// This score must be a value between 0.0 and 1.0, inclusive.
score: 0.1,
// The time must be formatted as an ISO 8601 date string. You can invoke
// toISOString() on a Date object in your browser to receive the correct
// value.
recordedTime: "2023-04-01T16:18:37.153Z",
 
// You can pass any unstructured details about the feedback here.
details: "This is not representative of how I normally talk.",
});

OpenAPI

We used the OpenAPI generator to create this library. Our OpenAPI specification repository and feedback browser SDK repository are available under the MIT license.

Direct API usage

If you need to submit user feedback and the client is not a browser (e.g. iOS, Android), you can send an API request directly to our feedback endpoint.

Check out our API reference for details on constructing the HTTP request.

fetch() example

You can directly use fetch() to submit feedback. With this code, you don't need to install our browser library.

No types

By not installing the browser library, you lose helpful TypeScript types.

typescript
const feedbackRequestOptions = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
// Create a client token for your organization by visiting
// the following link
// -> https://gentrace.ai/settings/client-tokens
authorization: 'Bearer <40 character Base62 string>'
},
body: JSON.stringify({
pipelineRunId: '<pipeline run UUID>',
score: 0, // Value between 0 and 1
recordedTime: '2023-06-29T17:36:12.548Z',
details: '<string describing the details of the feedback>'
})
};
 
fetch('https://gentrace.ai/api/v1/feedback', feedbackRequestOptions)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));