> ## Documentation Index
> Fetch the complete documentation index at: https://docs.freeplay.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Customer Feedback & Events

> Log customer feedback and events associated with LLM completions.

Freeplay lets you log customer feedback, client events, and any other customer experience-related metadata associated with any LLM completion. This can be useful to tie feedback from your application back to Freeplay creating a feedback loop, whether for explicit signals like a feedback score, or implicit signals like a request to regenerate a completion or edits to a draft.

**Customer Feedback supports arbitrary key-value pairs and accepts any string, boolean, integer or float**.

There is one special key-value pair to consider:

The key `freeplay_feedback` is a special case to capture your primary positive/negative user feedback signals from customers. It accepts only the following string values:

* `positive` will render a 👍 in the UI
* `negative` will render as a 👎 in the UI

## Methods Overview

| Method Name | Parameters                               | Description                                         |
| ----------- | ---------------------------------------- | --------------------------------------------------- |
| `update`    | `completion_id`: string `feedback`: dict | Log feedback associated with a specified completion |

## Log Customer Feedback

<CodeGroup>
  ```python python theme={null}
  # create a session which will create a UID
  session = fpClient.sessions.create()

  # record the results
  payload = RecordPayload(
      project_id=project_id,
      all_messages=all_messages,
      inputs=prompt_vars,
      session_info=session.session_info,
      prompt_version_info=prompt_info,
      call_info=CallInfo.from_prompt_info(prompt_info, start_time=s, end_time=e),
  )
  # this will create the completion id needed for the logging of customer feedback
  completion_info = fpClient.recordings.create(payload)

  # add some customer feedback
  fpClient.customer_feedback.update(
      completion_id=completion_info.completion_id,
      feedback={'freeplay_feedback': 'positive',
                'link_clicked': True}
  )
  ```

  ```typescript typescript theme={null}
  // create a session
  let session = fpClient.sessions.create({});

  // record the interaction with Freeplay
  const completionInfo = await fpClient.recordings.create({
      projectId,
      allMessages: messages,
      inputs: promptVars,
      sessionInfo: getSessionInfo(session),
      promptVersionInfo: formattedPrompt.promptInfo,
      callInfo: getCallInfo(formattedPrompt.promptInfo, start, end),
  });

  // record customer feedback
  await fpClient.customerFeedback.update({
      completionId: completionInfo.completionId,
      customerFeedback: {
          "freeplay_feedback": "positive",
          "link_click": true
      },
  });
  ```

  ```java java theme={null}
  fpClient.recordings().create(
    new RecordInfo(projectId, allMessages)
    .inputs(variables)
    .sessionInfo(sessionInfo)
    .promptVersionInfo(formattedPrompt.getPromptInfo())
    .callInfo(callInfo))
    .thenCompose(recordResponse ->
                 fpClient.customerFeedback().update(
                   projectId,
                   recordResponse.getCompletionId(),
                   Map.of("helpful", "thumbsup")
                 )
                 .thenApply(feedbackResponse -> recordResponse)
                );
  ```

  ```kotlin kotlin theme={null}
  // build the final record payload
  val recordResponse = fpClient.recordings().create(
    RecordInfo(
      projectId,
      allMessages
    ).inputs(variables)
      .sessionInfo(session.sessionInfo)
      .promptVersionInfo(prompt.promptInfo)
      .callInfo(callInfo)
  ).await()

  // log customer feedback
  val feedbackResponse = fpClient.customerFeedback().update(
    recordResponse.completionId,
    mapOf("freeplay_feedback" to "positive")
  ).await()
  ```
</CodeGroup>
