openai/chatkit-python

Public

mirrored from https://github.com/openai/chatkit-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/guides/handle-feedback.md

41lines · modeblame

1d06e8a7Jiwon Kim6 months ago1# Handle feedback
2
3## Enable feedback actions on the client
4
5Collect 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
8const chatkit = useChatKit({
9// ...
10threadItemActions: {
11feedback: true,
12},
13})
14```
15
16## Implement `add_feedback` on your server
17
18Override the `add_feedback` method on your server to persist the signal anywhere you like.
19
20```python
21from chatkit.server import ChatKitServer
22from chatkit.types import FeedbackKind
23
24class MyChatKitServer(ChatKitServer[RequestContext]):
25async def add_feedback(
26self,
27thread_id: str,
28item_ids: list[str],
29feedback: FeedbackKind,
30context: RequestContext,
31) -> None:
32# Example: write to your analytics/QA store
33await record_feedback(
34thread_id=thread_id,
35item_ids=item_ids,
36sentiment=feedback,
37user_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.