Skip to content

Commit 22496ce

Browse files
authored
Merge pull request openai#107 from openai/update-docs-for-entity-tags-and-annotations
[docs] Update docs on entity tags and annotations
2 parents 1913e50 + 2f23b67 commit 22496ce

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

docs/guides/accept-rich-user-input.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ To enable entity tagging as @-mentions in the composer, configure [`entities.onT
182182

183183
It should return a list of [Entity](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entity/) objects that match the query string.
184184

185+
If you want to hint that @-mentions are available, enable the composer `@` button by setting [`entities.showComposerMenu`](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#showcomposermenu). When clicked, it inserts `@` into the composer and opens the tag search menu automatically.
186+
185187
```ts
186188
const chatkit = useChatKit({
187189
// ...
@@ -204,6 +206,8 @@ const chatkit = useChatKit({
204206
},
205207
]
206208
},
209+
// Optional: show the "@" button in the composer for added discoverability.
210+
showComposerMenu: true,
207211
},
208212
})
209213
```

docs/guides/add-annotations.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,53 @@ Provide the model with citable evidence via tools to receive citation annotation
1313

1414
No additional server-side wiring is required beyond calling `stream_agent_response`. If the model emits citation annotations from tool usage, ChatKit will forward them automatically as `Annotation` objects on the corresponding content parts.
1515

16+
### Customize how citations are converted
17+
18+
Sometimes the default rendering for model-emitted citations is not very helpful. For example, file citations may not include enough metadata for ChatKit to show a meaningful default title or description. You can pass a custom [`ResponseStreamConverter`](../../api/chatkit/agents/#chatkit.agents.ResponseStreamConverter) and override:
19+
20+
- `file_citation_to_annotation`
21+
- `container_file_citation_to_annotation`
22+
- `url_citation_to_annotation`
23+
24+
Here is a minimal example that enriches file citations with a more helpful title/description using an internal mapping:
25+
26+
```python
27+
from chatkit.agents import ResponseStreamConverter, stream_agent_response
28+
from chatkit.types import Annotation, FileSource
29+
30+
31+
class MyResponseStreamConverter(ResponseStreamConverter):
32+
def __init__(self, file_lookup: dict[str, dict[str, str]]):
33+
super().__init__()
34+
self._file_lookup = file_lookup
35+
36+
async def file_citation_to_annotation(self, citation):
37+
info = self._file_lookup.get(citation.file_id, {})
38+
return Annotation(
39+
source=FileSource(
40+
filename=info.get("filename", citation.file_id),
41+
title=info.get("title"),
42+
description=info.get("description"),
43+
),
44+
index=citation.index,
45+
)
46+
47+
48+
converter = MyResponseStreamConverter(
49+
file_lookup={
50+
"file_123": {
51+
"filename": "q1_report.pdf",
52+
"title": "Q1 Report",
53+
"description": "Quarterly performance summary",
54+
}
55+
}
56+
)
57+
58+
stream_agent_response(..., converter=converter)
59+
```
60+
61+
You can also return an `EntitySource` instead of a `FileSource` to control the inline label, handle clicks, and customize the popover preview. For more on entity annotations (including `interactive` click/preview hooks), see [Annotating with custom entities](#annotating-with-custom-entities) below.
62+
1663

1764
## Attach sources manually
1865

0 commit comments

Comments
 (0)