openai/chatkit-python
Publicmirrored from https://github.com/openai/chatkit-pythonAvailable
docs/guides/handle-feedback.md
41lines · modeblame
1d06e8a7Jiwon Kim6 months ago | 1 | # Handle feedback |
| 2 | | |
| 3 | ## Enable feedback actions on the client | |
| 4 | | |
| 5 | Collect thumbs up/down feedback so you can flag broken answers, retrain on good ones, or alert humans. Enable the message actions in the client by setting [`threadItemActions.feedback`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/threaditemactionsoption/); ChatKit.js renders the controls and sends an `items.feedback` request when a user clicks them. | |
| 6 | | |
| 7 | ```tsx | |
| 8 | const chatkit = useChatKit({ | |
| 9 | // ... | |
| 10 | threadItemActions: { | |
| 11 | feedback: true, | |
| 12 | }, | |
| 13 | }) | |
| 14 | ``` | |
| 15 | | |
| 16 | ## Implement `add_feedback` on your server | |
| 17 | | |
| 18 | Override the `add_feedback` method on your server to persist the signal anywhere you like. | |
| 19 | | |
| 20 | ```python | |
| 21 | from chatkit.server import ChatKitServer | |
| 22 | from chatkit.types import FeedbackKind | |
| 23 | | |
| 24 | class MyChatKitServer(ChatKitServer[RequestContext]): | |
| 25 | async def add_feedback( | |
| 26 | self, | |
| 27 | thread_id: str, | |
| 28 | item_ids: list[str], | |
| 29 | feedback: FeedbackKind, | |
| 30 | context: RequestContext, | |
| 31 | ) -> None: | |
| 32 | # Example: write to your analytics/QA store | |
| 33 | await record_feedback( | |
| 34 | thread_id=thread_id, | |
| 35 | item_ids=item_ids, | |
| 36 | sentiment=feedback, | |
| 37 | user_id=context.user_id, | |
| 38 | ) | |
| 39 | ``` | |
| 40 | | |
| 41 | `item_ids` can include assistant messages, tool calls, or widgets. If you need to ignore certain items (for example, hidden system prompts), filter them here before recording. |