Send Generation Feedback Using Models API

Send feedback about a generative AI provider’s response using the Feedback REST endpoint or Apex class. For example, you can send feedback about a generated email containing misinformation about a product.

How It Works 

When you send a request with a prompt, the response can return one or more generation objects, each with a unique ID. Use this identifier (or your own unique identifier value) to provide feedback to the feedback REST endpoint or the feedback Apex class. This feedback can include additional details about explicit feedback or telemetry data. Feedback data is stored in Data 360.

Each feedback call requires at least two IDs: one that identifies this unique piece of feedback (id) and one that identifies the target of this feedback (generationId). You can provide information about the feedback sentiment (feedback), free-form feedback text (feedbackText), and any other use-case-specific data (appFeedback). The Models API doesn’t do any semantic validation on this information and is only meant for you to identify and filter the feedback in the datastore. The Models API doesn’t limit the size of feedbackText in a request. However, the data is truncated to 1024 characters when it’s stored in Data 360.

See Einstein Audit and Feedback Data in Salesforce Help.

REST Example 

In this example, the client sends feedback when the user specified a thumbs down for an incomplete response. The sample code shows the request body when making an HTTP POST request to the /feedback endpoint.

Sample Feedback REST Request Body
1{
2  "id": "78w60870345-2335840385-4857348-803483",
3  "generationId": "89t608-46756v66y-23r4wqxe43-096mi",
4  "feedback": "BAD",
5  "feedbackText": "The suggested summary was confusing and incomplete",
6  "source": "HUMAN"
7}

See Submit Feedback REST Endpoint.

Apex Example 

In this Apex example, the client sends feedback when the user is satisfied with the response.

Sample Feedback Call
1// Create feedback request
2aiplatform.ModelsAPI.submitFeedback_Request request = new aiplatform.ModelsAPI.submitFeedback_Request();
3
4// Provide feedback information in body
5aiplatform.ModelsAPI_FeedbackRequest feedbackRequest = new aiplatform.ModelsAPI_FeedbackRequest();
6feedbackRequest.id = '78w60870345-2335840385-4857348-803483';
7feedbackRequest.generationId = '89t608-46756v66y-23r4wqxe43-096mi';
8feedbackRequest.feedback = 'GOOD';
9feedbackRequest.feedbackText = 'The generation was helpful and did not require any changes';
10feedbackRequest.source = 'HUMAN';
11request.body = feedbackRequest;
12
13// Submit feedback
14try {
15    aiplatform.ModelsAPI modelsAPI = new aiplatform.ModelsAPI();
16    aiplatform.ModelsAPI.submitFeedback_Response response = modelsAPI.submitFeedback(request);
17    System.debug('Models API response: ' + response.Code202.message);
18
19// Handle error
20} catch(aiplatform.ModelsAPI.submitFeedback_ResponseException e) {
21    System.debug('Response code: ' + e.responseCode);
22    System.debug('The following exception occurred: ' + e);
23}

See Also