Skip to content

Commit 8b263fa

Browse files
committed
Update docs
1 parent 1e0aaa3 commit 8b263fa

1 file changed

Lines changed: 55 additions & 2 deletions

File tree

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Accept rich user input
22

3-
This guide explains how a ChatKit server accepts user input beyond plain textsuch as attachments and @-mentionsand makes it available to your inference pipeline.
3+
This guide explains how a ChatKit server accepts user input beyond plain text, such as attachments, structured follow-up answers, and @-mentions, and makes it available to your inference pipeline.
44

55
At a high level:
66

77
- Attachments let users upload files that your model can read.
8+
- Structured input lets the assistant ask for specific follow-up answers.
89
- @-mentions let users tag entities so the model does not have to guess from free text.
910

1011
## Attachments: let users upload files
@@ -228,6 +229,59 @@ async def transcribe(self, audio_input: AudioInput, context: RequestContext) ->
228229

229230
Return a `TranscriptionResult` that includes the final `text` that should appear in the composer.
230231

232+
## Structured input: ask for specific answers
233+
234+
Structured input lets your assistant ask the user for small, typed follow-up answers as part of the conversation. The prompt takes over the composer with focused controls, plus a skip option. Use structured input when the next step depends on specific choices or short fields, and free-text back-and-forth would be slower or easier to misread.
235+
236+
The server streams a [`StructuredInputItem`](../api/chatkit/types.md#chatkit.types.StructuredInputItem) during `respond`. ChatKit renders the questions in the composer area instead of the normal free-text input, then records the result on the same thread item when the user answers or skips.
237+
238+
### Stream a structured input item
239+
240+
Yield a `StructuredInputItem` from `respond` when you need the user to answer before continuing.
241+
242+
```python
243+
from datetime import datetime
244+
245+
from chatkit.types import (
246+
StructuredInputFreeform,
247+
StructuredInputItem,
248+
StructuredInputMultipleChoice,
249+
ThreadItemDoneEvent,
250+
)
251+
252+
253+
yield ThreadItemDoneEvent(
254+
item=StructuredInputItem(
255+
id=self.store.generate_item_id("message", thread, context),
256+
thread_id=thread.id,
257+
created_at=datetime.now(),
258+
inputs=[
259+
StructuredInputMultipleChoice(
260+
id="priority",
261+
question="What priority should I use?",
262+
options=["Low", "Medium", "High"],
263+
),
264+
StructuredInputFreeform(
265+
id="notes",
266+
question="Any extra context?",
267+
description="Optional details to include.",
268+
),
269+
],
270+
)
271+
)
272+
return
273+
```
274+
275+
Use [`StructuredInputMultipleChoice`](../api/chatkit/types.md#chatkit.types.StructuredInputMultipleChoice) for choice prompts and [`StructuredInputFreeform`](../api/chatkit/types.md#chatkit.types.StructuredInputFreeform) for short text answers. Set `multiple=True` on multiple-choice input when the user may submit more than one value.
276+
277+
After the user submits or skips, ChatKit records the result on the structured input item.
278+
279+
### Convert structured input submissions into model input
280+
281+
The default [`ThreadItemConverter`](../api/chatkit/agents.md#chatkit.agents.ThreadItemConverter) includes structured input items in model input. It describes the prompt status and each answer as answered, skipped, or unanswered.
282+
283+
If your model needs a different format, override `ThreadItemConverter.structured_input_to_input` before calling `Runner.run_streamed`.
284+
231285
## @-mentions: tag entities in user messages
232286

233287
Enable @-mentions so users can tag entities (like documents, tickets, or users) instead of pasting raw identifiers. Mentions travel through ChatKit as structured tags so the model can resolve entities instead of guessing from free text.
@@ -361,4 +415,3 @@ Clicks and hover previews apply to the tagged entities shown in past user messag
361415

362416
- `entities.onClick` fires when a user clicks a tag in the transcript. Handle navigation or open a detail view. See the [onClick option](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onclick).
363417
- `entities.onRequestPreview` runs when the user hovers or taps a tag that has `interactive: true`. Return a `BasicRoot` widget; you can build one with `WidgetTemplate.build_basic(...)` if you are building the preview widgets server-side. See the [onRequestPreview option](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/entitiesoption/#onrequestpreview).
364-

0 commit comments

Comments
 (0)