openai/chatkit-python

Public

mirrored fromhttps://github.com/openai/chatkit-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.6.5

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/guides/handle-feedback.md

41lines · modecode

1# 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 // ...
10 threadItemActions: {
11 feedback: 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]):
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.
42