You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/add-annotations.md
+18-4Lines changed: 18 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,14 @@ yield ThreadItemDoneEvent(
58
58
59
59
## Annotating with custom entities
60
60
61
-
Inline annotations are not yet supported for entity sources, but you can still attach `EntitySource` items as annotations so they appear in the Sources list below the message.
61
+
You can attach `EntitySource` items as annotations to show entity references inline in assistant text and in the **Sources** list below the message.
62
+
63
+
Entity annotations support a few UI-focused fields:
64
+
65
+
-`icon`: Controls the icon shown for the entity in the default inline/hover UI.
66
+
-`label`: Customizes what's shown in the default entity hover header (when you are not rendering a custom preview).
67
+
-`inline_label`: Shows a label inline instead of an icon.
68
+
-`interactive=True`: Wires the annotation to client-side callbacks (`ChatKitOptions.entities.onClick` and `ChatKitOptions.entities.onRequestPreview`).
62
69
63
70
```python
64
71
from datetime import datetime
@@ -70,15 +77,22 @@ from chatkit.types import (
70
77
ThreadItemDoneEvent,
71
78
)
72
79
80
+
text ="Here are the ACME account details for reference."
81
+
73
82
annotations = [
74
83
Annotation(
75
84
source=EntitySource(
76
85
id="customer_123",
77
86
title="ACME Corp",
78
87
description="Enterprise plan · 500 seats",
79
88
icon="suitcase",
89
+
label="Customer",
90
+
interactive=True,
91
+
# Free-form data object passed to your client-side entity callbacks
# `index` controls where the inline marker is placed in the text.
95
+
index=text.index("ACME") +len("ACME"),
82
96
)
83
97
]
84
98
@@ -89,12 +103,12 @@ yield ThreadItemDoneEvent(
89
103
created_at=datetime.now(),
90
104
content=[
91
105
AssistantMessageContent(
92
-
text="Here are the ACME account details for reference.",
106
+
text=text,
93
107
annotations=annotations,
94
108
)
95
109
],
96
110
)
97
111
)
98
112
```
99
113
100
-
Provide richer previews and navigation by handling [`entities.onRequestPreview`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onrequestpreview) and [`entities.onClick`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onclick) in ChatKit.js, using the `data` payload to pass entity information and deep link into your app.
114
+
Provide richer previews and navigation by handling [`entities.onRequestPreview`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onrequestpreview) and [`entities.onClick`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onclick) in ChatKit.js. These callbacks are only invoked for entity annotations with `interactive=True`; use the `data` payload to pass entity information and deep link into your app.
0 commit comments