Skip to main content
This is an interactive notebook. You can run it locally or use the links below:
Automatically evaluating a generated LLM response can be difficult. To better evaluate and improve responses, you can additionally gather direct user feedback to identify problem areas. This notebook demonstrates how to collect user feedback about the responses from a custom chatbot. It uses Streamlit to build the interface and capture the LLM interactions and feedback in W&B Weave. By the end, you have a running chatbot that logs each response to Weave, along with thumbs-up or thumbs-down reactions and free-text feedback from your users, so you can review production interactions and identify areas for improvement.

Setup

First, install the required packages and set your OpenAI and W&B API keys so that the chatbot can call the OpenAI API and log calls to Weave.
Next, create a file called chatbot.py with the following contents. This file defines the Streamlit chat interface, wraps the OpenAI call with a Weave op so each response is tracked, and renders the feedback controls that attach reactions and notes back to the corresponding Weave call.
You can run this with streamlit run chatbot.py. You can now interact with this application and click the feedback buttons after each response. Visit the Weave UI to see the attached feedback. Each chat exchange is recorded as a Weave call, and any reactions or notes you submit are linked to the call that produced the response.

Explanation

The following section walks through the key Weave APIs used in the chatbot, so you can apply the same pattern to your own application. Consider the following decorated prediction function:
You can use it as usual to deliver a model response to the user:
To attach feedback, you need the call object, which you obtain by using the .call() method instead of calling the function as normal:
You need this call object to attach feedback to the specific response. After you make the call, the output of the operation is available as result. With the call object in hand, you can then record user feedback against that specific response:

Conclusion

In this tutorial, you built a chat UI with Streamlit that captures inputs and outputs in Weave, alongside thumbs-up and thumbs-down buttons to capture user feedback.