openai/chatkit-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

chatkit/types.py

898lines · modeblame

f688d870victor-openai9 months ago1from __future__ import annotations
2
3from datetime import datetime
4from typing import Any, Generic, Literal
5
6from pydantic import AnyUrl, BaseModel, Field
7from typing_extensions import Annotated, TypeIs, TypeVar
8
9from chatkit.errors import ErrorCode
10
11from .actions import Action
12from .widgets import WidgetComponent, WidgetRoot
13
14T = TypeVar("T")
15
16
17class Page(BaseModel, Generic[T]):
6988ea0avictor-openai9 months ago18"""Paginated collection of records returned from the API."""
19
f688d870victor-openai9 months ago20data: list[T] = []
21has_more: bool = False
22after: str | None = None
23
24
25### REQUEST TYPES
26
27
28class BaseReq(BaseModel):
6988ea0avictor-openai9 months ago29"""Base class for all request payloads."""
30
f688d870victor-openai9 months ago31metadata: dict[str, Any] = Field(default_factory=dict)
32"""Arbitrary integration-specific metadata."""
33
34
35class ThreadsGetByIdReq(BaseReq):
6988ea0avictor-openai9 months ago36"""Request to fetch a single thread by its identifier."""
37
f688d870victor-openai9 months ago38type: Literal["threads.get_by_id"] = "threads.get_by_id"
39params: ThreadGetByIdParams
40
41
42class ThreadGetByIdParams(BaseModel):
6988ea0avictor-openai9 months ago43"""Parameters for retrieving a thread by id."""
44
f688d870victor-openai9 months ago45thread_id: str
46
47
48class ThreadsCreateReq(BaseReq):
6988ea0avictor-openai9 months ago49"""Request to create a new thread from a user message."""
50
f688d870victor-openai9 months ago51type: Literal["threads.create"] = "threads.create"
52params: ThreadCreateParams
53
54
55class ThreadCreateParams(BaseModel):
6988ea0avictor-openai9 months ago56"""User input required to create a thread."""
57
f688d870victor-openai9 months ago58input: UserMessageInput
59
60
61class ThreadListParams(BaseModel):
6988ea0avictor-openai9 months ago62"""Pagination parameters for listing threads."""
63
f688d870victor-openai9 months ago64limit: int | None = None
65order: Literal["asc", "desc"] = "desc"
66after: str | None = None
67
68
69class ThreadsListReq(BaseReq):
6988ea0avictor-openai9 months ago70"""Request to list threads."""
71
f688d870victor-openai9 months ago72type: Literal["threads.list"] = "threads.list"
73params: ThreadListParams
74
75
76class ThreadsAddUserMessageReq(BaseReq):
6988ea0avictor-openai9 months ago77"""Request to append a user message to a thread."""
78
f688d870victor-openai9 months ago79type: Literal["threads.add_user_message"] = "threads.add_user_message"
80params: ThreadAddUserMessageParams
81
82
83class ThreadAddUserMessageParams(BaseModel):
6988ea0avictor-openai9 months ago84"""Parameters for adding a user message to a thread."""
85
f688d870victor-openai9 months ago86input: UserMessageInput
87thread_id: str
88
89
90class ThreadsAddClientToolOutputReq(BaseReq):
6988ea0avictor-openai9 months ago91"""Request to add a client tool's output to a thread."""
92
f688d870victor-openai9 months ago93type: Literal["threads.add_client_tool_output"] = "threads.add_client_tool_output"
94params: ThreadAddClientToolOutputParams
95
96
97class ThreadAddClientToolOutputParams(BaseModel):
6988ea0avictor-openai9 months ago98"""Parameters for recording tool output in a thread."""
99
f688d870victor-openai9 months ago100thread_id: str
101result: Any
102
103
104class ThreadsCustomActionReq(BaseReq):
6988ea0avictor-openai9 months ago105"""Request to execute a custom action within a thread."""
106
f688d870victor-openai9 months ago107type: Literal["threads.custom_action"] = "threads.custom_action"
108params: ThreadCustomActionParams
109
110
111class ThreadCustomActionParams(BaseModel):
6988ea0avictor-openai9 months ago112"""Parameters describing the custom action to execute."""
113
f688d870victor-openai9 months ago114thread_id: str
115item_id: str | None = None
116action: Action[str, Any]
117
118
119class ThreadsRetryAfterItemReq(BaseReq):
6988ea0avictor-openai9 months ago120"""Request to retry processing after a specific thread item."""
121
f688d870victor-openai9 months ago122type: Literal["threads.retry_after_item"] = "threads.retry_after_item"
123params: ThreadRetryAfterItemParams
124
125
126class ThreadRetryAfterItemParams(BaseModel):
6988ea0avictor-openai9 months ago127"""Parameters specifying which item to retry."""
128
f688d870victor-openai9 months ago129thread_id: str
130item_id: str
131
132
133class ItemsFeedbackReq(BaseReq):
6988ea0avictor-openai9 months ago134"""Request to submit feedback on specific items."""
135
f688d870victor-openai9 months ago136type: Literal["items.feedback"] = "items.feedback"
137params: ItemFeedbackParams
138
139
140class ItemFeedbackParams(BaseModel):
6988ea0avictor-openai9 months ago141"""Parameters describing feedback targets and sentiment."""
142
f688d870victor-openai9 months ago143thread_id: str
144item_ids: list[str]
145kind: FeedbackKind
146
147
148class AttachmentsDeleteReq(BaseReq):
6988ea0avictor-openai9 months ago149"""Request to remove an attachment."""
150
f688d870victor-openai9 months ago151type: Literal["attachments.delete"] = "attachments.delete"
152params: AttachmentDeleteParams
153
154
155class AttachmentDeleteParams(BaseModel):
6988ea0avictor-openai9 months ago156"""Parameters identifying an attachment to delete."""
157
f688d870victor-openai9 months ago158attachment_id: str
159
160
161class AttachmentsCreateReq(BaseReq):
6988ea0avictor-openai9 months ago162"""Request to register a new attachment."""
163
f688d870victor-openai9 months ago164type: Literal["attachments.create"] = "attachments.create"
165params: AttachmentCreateParams
166
167
168class AttachmentCreateParams(BaseModel):
6988ea0avictor-openai9 months ago169"""Metadata needed to initialize an attachment."""
170
f688d870victor-openai9 months ago171name: str
172size: int
173mime_type: str
174
175
176class ItemsListReq(BaseReq):
6988ea0avictor-openai9 months ago177"""Request to list items inside a thread."""
178
f688d870victor-openai9 months ago179type: Literal["items.list"] = "items.list"
180params: ItemsListParams
181
182
183class ItemsListParams(BaseModel):
6988ea0avictor-openai9 months ago184"""Pagination parameters for listing thread items."""
185
f688d870victor-openai9 months ago186thread_id: str
187limit: int | None = None
188order: Literal["asc", "desc"] = "desc"
189after: str | None = None
190
191
192class ThreadsUpdateReq(BaseReq):
6988ea0avictor-openai9 months ago193"""Request to update thread metadata."""
194
f688d870victor-openai9 months ago195type: Literal["threads.update"] = "threads.update"
196params: ThreadUpdateParams
197
198
199class ThreadUpdateParams(BaseModel):
6988ea0avictor-openai9 months ago200"""Parameters for updating a thread's properties."""
201
f688d870victor-openai9 months ago202thread_id: str
203title: str
204
205
206class ThreadsDeleteReq(BaseReq):
6988ea0avictor-openai9 months ago207"""Request to delete a thread."""
208
f688d870victor-openai9 months ago209type: Literal["threads.delete"] = "threads.delete"
210params: ThreadDeleteParams
211
212
213class ThreadDeleteParams(BaseModel):
6988ea0avictor-openai9 months ago214"""Parameters identifying a thread to delete."""
215
f688d870victor-openai9 months ago216thread_id: str
217
218
219StreamingReq = (
220ThreadsCreateReq
221| ThreadsAddUserMessageReq
222| ThreadsAddClientToolOutputReq
223| ThreadsRetryAfterItemReq
224| ThreadsCustomActionReq
225)
6988ea0avictor-openai9 months ago226"""Union of request types that produce streaming responses."""
227
f688d870victor-openai9 months ago228
229NonStreamingReq = (
230ThreadsGetByIdReq
231| ThreadsListReq
232| ItemsListReq
233| ItemsFeedbackReq
234| AttachmentsCreateReq
235| AttachmentsDeleteReq
236| ThreadsUpdateReq
237| ThreadsDeleteReq
238)
6988ea0avictor-openai9 months ago239"""Union of request types that yield immediate responses."""
240
f688d870victor-openai9 months ago241
242ChatKitReq = Annotated[
243StreamingReq | NonStreamingReq,
244Field(discriminator="type"),
245]
246
247
248def is_streaming_req(request: ChatKitReq) -> TypeIs[StreamingReq]:
6988ea0avictor-openai9 months ago249"""Return True if the given request should be processed as streaming."""
f688d870victor-openai9 months ago250return isinstance(
251request,
252(
253ThreadsCreateReq,
254ThreadsAddUserMessageReq,
255ThreadsRetryAfterItemReq,
256ThreadsAddClientToolOutputReq,
257ThreadsCustomActionReq,
258),
259)
260
261
262### THREAD STREAM EVENT TYPES
263
264
265class ThreadCreatedEvent(BaseModel):
6988ea0avictor-openai9 months ago266"""Event emitted when a thread is created."""
aa7ec072victor-openai9 months ago267
f688d870victor-openai9 months ago268type: Literal["thread.created"] = "thread.created"
269thread: Thread
270
271
272class ThreadUpdatedEvent(BaseModel):
6988ea0avictor-openai9 months ago273"""Event emitted when a thread is updated."""
aa7ec072victor-openai9 months ago274
f688d870victor-openai9 months ago275type: Literal["thread.updated"] = "thread.updated"
276thread: Thread
277
278
279class ThreadItemAddedEvent(BaseModel):
6988ea0avictor-openai9 months ago280"""Event emitted when a new item is added to a thread."""
aa7ec072victor-openai9 months ago281
f688d870victor-openai9 months ago282type: Literal["thread.item.added"] = "thread.item.added"
283item: ThreadItem
284
285
286class ThreadItemUpdated(BaseModel):
6988ea0avictor-openai9 months ago287"""Event describing an update to an existing thread item."""
aa7ec072victor-openai9 months ago288
f688d870victor-openai9 months ago289type: Literal["thread.item.updated"] = "thread.item.updated"
290item_id: str
291update: ThreadItemUpdate
292
293
294class ThreadItemDoneEvent(BaseModel):
6988ea0avictor-openai9 months ago295"""Event emitted when a thread item is marked complete."""
aa7ec072victor-openai9 months ago296
f688d870victor-openai9 months ago297type: Literal["thread.item.done"] = "thread.item.done"
298item: ThreadItem
299
300
301class ThreadItemRemovedEvent(BaseModel):
6988ea0avictor-openai9 months ago302"""Event emitted when a thread item is removed."""
aa7ec072victor-openai9 months ago303
f688d870victor-openai9 months ago304type: Literal["thread.item.removed"] = "thread.item.removed"
305item_id: str
306
307
308class ThreadItemReplacedEvent(BaseModel):
6988ea0avictor-openai9 months ago309"""Event emitted when a thread item is replaced."""
aa7ec072victor-openai9 months ago310
f688d870victor-openai9 months ago311type: Literal["thread.item.replaced"] = "thread.item.replaced"
312item: ThreadItem
313
314
315class ProgressUpdateEvent(BaseModel):
6988ea0avictor-openai9 months ago316"""Event providing incremental progress from the assistant."""
aa7ec072victor-openai9 months ago317
f688d870victor-openai9 months ago318type: Literal["progress_update"] = "progress_update"
319icon: IconName | None = None
320text: str
321
322
323class ErrorEvent(BaseModel):
6988ea0avictor-openai9 months ago324"""Event indicating an error occurred while processing a thread."""
aa7ec072victor-openai9 months ago325
f688d870victor-openai9 months ago326type: Literal["error"] = "error"
327code: ErrorCode | Literal["custom"] = Field(default="custom")
328message: str | None = None
329allow_retry: bool = Field(default=False)
330
331
332class NoticeEvent(BaseModel):
6988ea0avictor-openai9 months ago333"""Event conveying a user-facing notice."""
aa7ec072victor-openai9 months ago334
f688d870victor-openai9 months ago335type: Literal["notice"] = "notice"
336level: Literal["info", "warning", "danger"]
337message: str
338"""
339Supports markdown e.g. "You've reached your limit of 100 messages. [Upgrade](https://...) to a paid plan."
340"""
341title: str | None = None
342
343
344ThreadStreamEvent = Annotated[
345ThreadCreatedEvent
346| ThreadUpdatedEvent
347| ThreadItemDoneEvent
348| ThreadItemAddedEvent
349| ThreadItemUpdated
350| ThreadItemRemovedEvent
351| ThreadItemReplacedEvent
352| ProgressUpdateEvent
353| ErrorEvent
354| NoticeEvent,
355Field(discriminator="type"),
356]
6988ea0avictor-openai9 months ago357"""Union of all streaming events emitted to clients."""
f688d870victor-openai9 months ago358
359### THREAD ITEM UPDATE TYPES
360
361
362class AssistantMessageContentPartAdded(BaseModel):
6988ea0avictor-openai9 months ago363"""Event emitted when new assistant content is appended."""
aa7ec072victor-openai9 months ago364
f688d870victor-openai9 months ago365type: Literal["assistant_message.content_part.added"] = (
366"assistant_message.content_part.added"
367)
368content_index: int
369content: AssistantMessageContent
370
371
372class AssistantMessageContentPartTextDelta(BaseModel):
6988ea0avictor-openai9 months ago373"""Event carrying incremental assistant text output."""
aa7ec072victor-openai9 months ago374
f688d870victor-openai9 months ago375type: Literal["assistant_message.content_part.text_delta"] = (
376"assistant_message.content_part.text_delta"
377)
378content_index: int
379delta: str
380
381
382class AssistantMessageContentPartAnnotationAdded(BaseModel):
6988ea0avictor-openai9 months ago383"""Event announcing a new annotation on assistant content."""
aa7ec072victor-openai9 months ago384
f688d870victor-openai9 months ago385type: Literal["assistant_message.content_part.annotation_added"] = (
386"assistant_message.content_part.annotation_added"
387)
388content_index: int
389annotation_index: int
390annotation: Annotation
391
392
393class AssistantMessageContentPartDone(BaseModel):
6988ea0avictor-openai9 months ago394"""Event indicating an assistant content part is finalized."""
aa7ec072victor-openai9 months ago395
f688d870victor-openai9 months ago396type: Literal["assistant_message.content_part.done"] = (
397"assistant_message.content_part.done"
398)
399content_index: int
400content: AssistantMessageContent
401
402
403class WidgetStreamingTextValueDelta(BaseModel):
6988ea0avictor-openai9 months ago404"""Event streaming widget text deltas."""
aa7ec072victor-openai9 months ago405
f688d870victor-openai9 months ago406type: Literal["widget.streaming_text.value_delta"] = (
407"widget.streaming_text.value_delta"
408)
409component_id: str
410delta: str
411done: bool
412
413
414class WidgetRootUpdated(BaseModel):
6988ea0avictor-openai9 months ago415"""Event published when the widget root changes."""
aa7ec072victor-openai9 months ago416
f688d870victor-openai9 months ago417type: Literal["widget.root.updated"] = "widget.root.updated"
418widget: WidgetRoot
419
420
421class WidgetComponentUpdated(BaseModel):
6988ea0avictor-openai9 months ago422"""Event emitted when a widget component updates."""
aa7ec072victor-openai9 months ago423
f688d870victor-openai9 months ago424type: Literal["widget.component.updated"] = "widget.component.updated"
425component_id: str
426component: WidgetComponent
427
428
429class WorkflowTaskAdded(BaseModel):
6988ea0avictor-openai9 months ago430"""Event emitted when a workflow task is added."""
aa7ec072victor-openai9 months ago431
f688d870victor-openai9 months ago432type: Literal["workflow.task.added"] = "workflow.task.added"
433task_index: int
434task: Task
435
436
437class WorkflowTaskUpdated(BaseModel):
6988ea0avictor-openai9 months ago438"""Event emitted when a workflow task is updated."""
aa7ec072victor-openai9 months ago439
f688d870victor-openai9 months ago440type: Literal["workflow.task.updated"] = "workflow.task.updated"
441task_index: int
442task: Task
443
444
445ThreadItemUpdate = (
446AssistantMessageContentPartAdded
447| AssistantMessageContentPartTextDelta
448| AssistantMessageContentPartAnnotationAdded
449| AssistantMessageContentPartDone
450| WidgetStreamingTextValueDelta
451| WidgetComponentUpdated
452| WidgetRootUpdated
453| WorkflowTaskAdded
454| WorkflowTaskUpdated
455)
6988ea0avictor-openai9 months ago456"""Union of possible updates applied to thread items."""
f688d870victor-openai9 months ago457
458
459### THREAD TYPES
460
461
462class ThreadMetadata(BaseModel):
6988ea0avictor-openai9 months ago463"""Metadata describing a thread without its items."""
aa7ec072victor-openai9 months ago464
f688d870victor-openai9 months ago465title: str | None = None
466id: str
467created_at: datetime
468status: ThreadStatus = Field(default_factory=lambda: ActiveStatus())
469# TODO - make not client rendered
470metadata: dict[str, Any] = Field(default_factory=dict)
471
472
473class ActiveStatus(BaseModel):
6988ea0avictor-openai9 months ago474"""Status indicating the thread is active."""
aa7ec072victor-openai9 months ago475
f688d870victor-openai9 months ago476type: Literal["active"] = Field(default="active", frozen=True)
477
478
479class LockedStatus(BaseModel):
6988ea0avictor-openai9 months ago480"""Status indicating the thread is locked."""
aa7ec072victor-openai9 months ago481
f688d870victor-openai9 months ago482type: Literal["locked"] = Field(default="locked", frozen=True)
483reason: str | None = None
484
485
486class ClosedStatus(BaseModel):
6988ea0avictor-openai9 months ago487"""Status indicating the thread is closed."""
aa7ec072victor-openai9 months ago488
f688d870victor-openai9 months ago489type: Literal["closed"] = Field(default="closed", frozen=True)
490reason: str | None = None
491
492
493ThreadStatus = Annotated[
494ActiveStatus | LockedStatus | ClosedStatus,
495Field(discriminator="type"),
496]
6988ea0avictor-openai9 months ago497"""Union of lifecycle states for a thread."""
f688d870victor-openai9 months ago498
499
500class Thread(ThreadMetadata):
6988ea0avictor-openai9 months ago501"""Thread with its paginated items."""
aa7ec072victor-openai9 months ago502
f688d870victor-openai9 months ago503items: Page[ThreadItem]
504
505
506### THREAD ITEM TYPES
507
508
509class ThreadItemBase(BaseModel):
6988ea0avictor-openai9 months ago510"""Base fields shared by all thread items."""
aa7ec072victor-openai9 months ago511
f688d870victor-openai9 months ago512id: str
513thread_id: str
514created_at: datetime
515
516
517class UserMessageItem(ThreadItemBase):
6988ea0avictor-openai9 months ago518"""Thread item representing a user message."""
aa7ec072victor-openai9 months ago519
f688d870victor-openai9 months ago520type: Literal["user_message"] = "user_message"
521content: list[UserMessageContent]
522attachments: list[Attachment] = Field(default_factory=list)
523quoted_text: str | None = None
524inference_options: InferenceOptions
525
526
527class AssistantMessageItem(ThreadItemBase):
6988ea0avictor-openai9 months ago528"""Thread item representing an assistant message."""
aa7ec072victor-openai9 months ago529
f688d870victor-openai9 months ago530type: Literal["assistant_message"] = "assistant_message"
531content: list[AssistantMessageContent]
532
533
534class ClientToolCallItem(ThreadItemBase):
6988ea0avictor-openai9 months ago535"""Thread item capturing a client tool call."""
aa7ec072victor-openai9 months ago536
f688d870victor-openai9 months ago537type: Literal["client_tool_call"] = "client_tool_call"
538status: Literal["pending", "completed"] = "pending"
539call_id: str
540name: str
541arguments: dict[str, Any]
542output: Any | None = None
543
544
545class WidgetItem(ThreadItemBase):
6988ea0avictor-openai9 months ago546"""Thread item containing widget content."""
aa7ec072victor-openai9 months ago547
f688d870victor-openai9 months ago548type: Literal["widget"] = "widget"
549widget: WidgetRoot
550copy_text: str | None = None
551
552
553class TaskItem(ThreadItemBase):
6988ea0avictor-openai9 months ago554"""Thread item containing a task."""
aa7ec072victor-openai9 months ago555
f688d870victor-openai9 months ago556type: Literal["task"] = "task"
557task: Task
558
559
560class WorkflowItem(ThreadItemBase):
6988ea0avictor-openai9 months ago561"""Thread item representing a workflow."""
aa7ec072victor-openai9 months ago562
f688d870victor-openai9 months ago563type: Literal["workflow"] = "workflow"
564workflow: Workflow
565
566
567class EndOfTurnItem(ThreadItemBase):
6988ea0avictor-openai9 months ago568"""Marker item indicating the assistant ends its turn."""
aa7ec072victor-openai9 months ago569
f688d870victor-openai9 months ago570type: Literal["end_of_turn"] = "end_of_turn"
571
572
573class HiddenContextItem(ThreadItemBase):
574"""HiddenContext is never sent to the client. It's not officially part of ChatKit. It is only used internally to store additional context in a specific place in the thread."""
575
576type: Literal["hidden_context_item"] = "hidden_context_item"
577content: Any
578
579
580ThreadItem = Annotated[
581UserMessageItem
582| AssistantMessageItem
583| ClientToolCallItem
584| WidgetItem
585| WorkflowItem
586| TaskItem
587| HiddenContextItem
588| EndOfTurnItem,
589Field(discriminator="type"),
590]
6988ea0avictor-openai9 months ago591"""Union of all thread item variants."""
f688d870victor-openai9 months ago592
593
594### ASSISTANT MESSAGE TYPES
595
596
597class AssistantMessageContent(BaseModel):
6988ea0avictor-openai9 months ago598"""Assistant message content consisting of text and annotations."""
aa7ec072victor-openai9 months ago599
f688d870victor-openai9 months ago600annotations: list[Annotation] = Field(default_factory=list)
601text: str
602type: Literal["output_text"] = "output_text"
603
604
605class Annotation(BaseModel):
6988ea0avictor-openai9 months ago606"""Reference to supporting context attached to assistant output."""
aa7ec072victor-openai9 months ago607
f688d870victor-openai9 months ago608type: Literal["annotation"] = "annotation"
609source: URLSource | FileSource | EntitySource
610index: int | None = None
611
612
613### USER MESSAGE TYPES
614
615
616class UserMessageInput(BaseModel):
6988ea0avictor-openai9 months ago617"""Payload describing a user message submission."""
aa7ec072victor-openai9 months ago618
f688d870victor-openai9 months ago619content: list[UserMessageContent]
620attachments: list[str]
621quoted_text: str | None = None
622inference_options: InferenceOptions
623
624
625class UserMessageTextContent(BaseModel):
6988ea0avictor-openai9 months ago626"""User message content containing plaintext."""
aa7ec072victor-openai9 months ago627
f688d870victor-openai9 months ago628type: Literal["input_text"] = "input_text"
629text: str
630
631
632class UserMessageTagContent(BaseModel):
6988ea0avictor-openai9 months ago633"""User message content representing an interactive tag."""
aa7ec072victor-openai9 months ago634
f688d870victor-openai9 months ago635type: Literal["input_tag"] = "input_tag"
636id: str
637text: str
638data: dict[str, Any]
639interactive: bool = False
640
641
642UserMessageContent = Annotated[
643UserMessageTextContent | UserMessageTagContent, Field(discriminator="type")
644]
6988ea0avictor-openai9 months ago645"""Union of allowed user message content payloads."""
f688d870victor-openai9 months ago646
647
648class InferenceOptions(BaseModel):
6988ea0avictor-openai9 months ago649"""Model and tool configuration for message processing."""
aa7ec072victor-openai9 months ago650
f688d870victor-openai9 months ago651tool_choice: ToolChoice | None = None
652model: str | None = None
653
654
655class ToolChoice(BaseModel):
6988ea0avictor-openai9 months ago656"""Explicit tool selection for the assistant to invoke."""
aa7ec072victor-openai9 months ago657
f688d870victor-openai9 months ago658id: str
659
660
661class AttachmentBase(BaseModel):
6988ea0avictor-openai9 months ago662"""Base metadata shared by all attachments."""
aa7ec072victor-openai9 months ago663
f688d870victor-openai9 months ago664id: str
665name: str
666mime_type: str
667upload_url: AnyUrl | None = None
668"""
669The URL to upload the file, used for two-phase upload.
670Should be set to None after upload is complete or when using direct upload where uploading happens when creating the attachment object.
671"""
672
673
674class FileAttachment(AttachmentBase):
6988ea0avictor-openai9 months ago675"""Attachment representing a generic file."""
aa7ec072victor-openai9 months ago676
f688d870victor-openai9 months ago677type: Literal["file"] = "file"
678
679
680class ImageAttachment(AttachmentBase):
6988ea0avictor-openai9 months ago681"""Attachment representing an image resource."""
aa7ec072victor-openai9 months ago682
f688d870victor-openai9 months ago683type: Literal["image"] = "image"
684preview_url: AnyUrl
685
686
687Attachment = Annotated[
688FileAttachment | ImageAttachment,
689Field(discriminator="type"),
690]
6988ea0avictor-openai9 months ago691"""Union of supported attachment types."""
f688d870victor-openai9 months ago692
693
694### WORKFLOW TYPES
695
696
697class Workflow(BaseModel):
6988ea0avictor-openai9 months ago698"""Workflow attached to a thread with optional summary."""
aa7ec072victor-openai9 months ago699
f688d870victor-openai9 months ago700type: Literal["custom", "reasoning"]
701tasks: list[Task]
702summary: WorkflowSummary | None = None
703expanded: bool = False
704
705
706class CustomSummary(BaseModel):
6988ea0avictor-openai9 months ago707"""Custom summary for a workflow."""
aa7ec072victor-openai9 months ago708
f688d870victor-openai9 months ago709title: str
c9f5f09dJiwon Kim8 months ago710icon: IconName | None = None
f688d870victor-openai9 months ago711
712
713class DurationSummary(BaseModel):
6988ea0avictor-openai9 months ago714"""Summary providing total workflow duration."""
aa7ec072victor-openai9 months ago715
f688d870victor-openai9 months ago716duration: int
717"""The duration of the workflow in seconds"""
718
719
720WorkflowSummary = CustomSummary | DurationSummary
6988ea0avictor-openai9 months ago721"""Summary variants available for workflows."""
f688d870victor-openai9 months ago722
723### TASK TYPES
724
725
726class BaseTask(BaseModel):
6988ea0avictor-openai9 months ago727"""Base fields common to all workflow tasks."""
aa7ec072victor-openai9 months ago728
f688d870victor-openai9 months ago729status_indicator: Literal["none", "loading", "complete"] = "none"
730"""Only used when rendering the task as part of a workflow. Indicates the status of the task."""
731
732
733class CustomTask(BaseTask):
6988ea0avictor-openai9 months ago734"""Workflow task displaying custom content."""
aa7ec072victor-openai9 months ago735
f688d870victor-openai9 months ago736type: Literal["custom"] = "custom"
737title: str | None = None
c9f5f09dJiwon Kim8 months ago738icon: IconName | None = None
f688d870victor-openai9 months ago739content: str | None = None
740
741
742class SearchTask(BaseTask):
6988ea0avictor-openai9 months ago743"""Workflow task representing a web search."""
aa7ec072victor-openai9 months ago744
f688d870victor-openai9 months ago745type: Literal["web_search"] = "web_search"
746title: str | None = None
747title_query: str | None = None
748queries: list[str] = Field(default_factory=list)
749sources: list[URLSource] = Field(default_factory=list)
750
751
752class ThoughtTask(BaseTask):
6988ea0avictor-openai9 months ago753"""Workflow task capturing assistant reasoning."""
aa7ec072victor-openai9 months ago754
f688d870victor-openai9 months ago755type: Literal["thought"] = "thought"
756title: str | None = None
757content: str
758
759
760class FileTask(BaseTask):
6988ea0avictor-openai9 months ago761"""Workflow task referencing file sources."""
aa7ec072victor-openai9 months ago762
f688d870victor-openai9 months ago763type: Literal["file"] = "file"
764title: str | None = None
765sources: list[FileSource] = Field(default_factory=list)
766
767
768class ImageTask(BaseTask):
6988ea0avictor-openai9 months ago769"""Workflow task rendering image content."""
aa7ec072victor-openai9 months ago770
f688d870victor-openai9 months ago771type: Literal["image"] = "image"
772title: str | None = None
773
774
775Task = Annotated[
776CustomTask | SearchTask | ThoughtTask | FileTask | ImageTask,
777Field(discriminator="type"),
778]
6988ea0avictor-openai9 months ago779"""Union of workflow task variants."""
f688d870victor-openai9 months ago780
781
782### SOURCE TYPES
783
784
785class SourceBase(BaseModel):
6988ea0avictor-openai9 months ago786"""Base class for sources displayed to users."""
aa7ec072victor-openai9 months ago787
f688d870victor-openai9 months ago788title: str
789description: str | None = None
790timestamp: str | None = None
791group: str | None = None
792
793
794class FileSource(SourceBase):
6988ea0avictor-openai9 months ago795"""Source metadata for file-based references."""
aa7ec072victor-openai9 months ago796
f688d870victor-openai9 months ago797type: Literal["file"] = "file"
798filename: str
799
800
801class URLSource(SourceBase):
6988ea0avictor-openai9 months ago802"""Source metadata for external URLs."""
aa7ec072victor-openai9 months ago803
f688d870victor-openai9 months ago804type: Literal["url"] = "url"
805url: str
806attribution: str | None = None
807
808
809class EntitySource(SourceBase):
6988ea0avictor-openai9 months ago810"""Source metadata for entity references."""
aa7ec072victor-openai9 months ago811
f688d870victor-openai9 months ago812type: Literal["entity"] = "entity"
813id: str
c9f5f09dJiwon Kim8 months ago814icon: IconName | None = None
f688d870victor-openai9 months ago815preview: Literal["lazy"] | None = None
c47e7701jiwon-oai8 months ago816data: dict[str, Any] = Field(default_factory=dict)
f688d870victor-openai9 months ago817
818
6988ea0avictor-openai9 months ago819Source = Annotated[
820URLSource | FileSource | EntitySource,
821Field(discriminator="type"),
822]
823"""Union of supported source types."""
f688d870victor-openai9 months ago824
825
826### MISC TYPES
827
828
829FeedbackKind = Literal["positive", "negative"]
6988ea0avictor-openai9 months ago830"""Literal type for feedback sentiment."""
831
f688d870victor-openai9 months ago832
833IconName = Literal[
78ade7a7Jiwon Kim8 months ago834"agent",
f688d870victor-openai9 months ago835"analytics",
836"atom",
78ade7a7Jiwon Kim8 months ago837"batch",
f688d870victor-openai9 months ago838"bolt",
839"book-open",
840"book-closed",
78ade7a7Jiwon Kim8 months ago841"book-clock",
842"bug",
f688d870victor-openai9 months ago843"calendar",
844"chart",
78ade7a7Jiwon Kim8 months ago845"check",
846"check-circle",
847"check-circle-filled",
848"chevron-left",
849"chevron-right",
f688d870victor-openai9 months ago850"circle-question",
851"compass",
78ade7a7Jiwon Kim8 months ago852"confetti",
f688d870victor-openai9 months ago853"cube",
78ade7a7Jiwon Kim8 months ago854"desktop",
855"document",
856"dot",
857"dots-horizontal",
858"dots-vertical",
859"empty-circle",
860"external-link",
f688d870victor-openai9 months ago861"globe",
862"keys",
863"lab",
864"images",
78ade7a7Jiwon Kim8 months ago865"info",
f688d870victor-openai9 months ago866"lifesaver",
867"lightbulb",
78ade7a7Jiwon Kim8 months ago868"mail",
f688d870victor-openai9 months ago869"map-pin",
78ade7a7Jiwon Kim8 months ago870"maps",
871"mobile",
f688d870victor-openai9 months ago872"name",
873"notebook",
874"notebook-pencil",
875"page-blank",
78ade7a7Jiwon Kim8 months ago876"phone",
877"play",
878"plus",
f688d870victor-openai9 months ago879"profile",
880"profile-card",
78ade7a7Jiwon Kim8 months ago881"reload",
882"star",
883"star-filled",
f688d870victor-openai9 months ago884"search",
885"sparkle",
886"sparkle-double",
887"square-code",
888"square-image",
889"square-text",
890"suitcase",
78ade7a7Jiwon Kim8 months ago891"settings-slider",
892"user",
893"wreath",
f688d870victor-openai9 months ago894"write",
895"write-alt",
896"write-alt2",
897]
6988ea0avictor-openai9 months ago898"""Literal names of supported progress icons."""