-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(streaming/messages): refactor to event iterator structure
- Loading branch information
1 parent
bb62980
commit 997af69
Showing
5 changed files
with
129 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Union | ||
from typing_extensions import Literal | ||
|
||
from ...types import ( | ||
Message, | ||
ContentBlock, | ||
MessageDeltaEvent as RawMessageDeltaEvent, | ||
MessageStartEvent as RawMessageStartEvent, | ||
RawMessageStopEvent, | ||
ContentBlockDeltaEvent as RawContentBlockDeltaEvent, | ||
ContentBlockStartEvent as RawContentBlockStartEvent, | ||
RawContentBlockStopEvent, | ||
) | ||
from ..._models import BaseModel | ||
|
||
|
||
class TextEvent(BaseModel): | ||
type: Literal["text"] | ||
|
||
text: str | ||
"""The text delta""" | ||
|
||
snapshot: str | ||
"""The entire accumulated text""" | ||
|
||
|
||
class MessageStopEvent(RawMessageStopEvent): | ||
type: Literal["message_stop"] | ||
|
||
message: Message | ||
|
||
|
||
class ContentBlockStopEvent(RawContentBlockStopEvent): | ||
type: Literal["content_block_stop"] | ||
|
||
content_block: ContentBlock | ||
|
||
|
||
MessageStreamEvent = Union[ | ||
TextEvent, | ||
RawMessageStartEvent, | ||
RawMessageDeltaEvent, | ||
MessageStopEvent, | ||
RawContentBlockStartEvent, | ||
RawContentBlockDeltaEvent, | ||
ContentBlockStopEvent, | ||
] |