Skip to content

Commit be7e520

Browse files
authored
feat: clear message event (#789)
1 parent a415964 commit be7e520

22 files changed

+57
-30
lines changed

packages/ragbits-chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## Unreleased
4+
- Add `clear_message` event type allowing to reset whole message (#789)
45
- Add authentication handling in the UI (#763)
56
- Add backend authentication (#761)
67

packages/ragbits-chat/src/ragbits/chat/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ async def _chat_response_to_sse(
541541
{
542542
"type": response.type.value,
543543
"content": response.content
544-
if isinstance(response.content, str | list)
544+
if isinstance(response.content, str | list | None)
545545
else response.content.model_dump(),
546546
}
547547
)

packages/ragbits-chat/src/ragbits/chat/interface/_interface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ def create_image_response(image_id: str, image_url: str) -> ChatResponse:
236236
"""Helper method to create an image response."""
237237
return ChatResponse(type=ChatResponseType.IMAGE, content=Image(id=image_id, url=image_url))
238238

239+
@staticmethod
240+
def create_clear_message_response() -> ChatResponse:
241+
"""Helper method to create an clear message response."""
242+
return ChatResponse(type=ChatResponseType.CLEAR_MESSAGE, content=None)
243+
239244
@staticmethod
240245
def _sign_state(state: dict[str, Any]) -> str:
241246
"""

packages/ragbits-chat/src/ragbits/chat/interface/types.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ChatResponseType(str, Enum):
7777
LIVE_UPDATE = "live_update"
7878
FOLLOWUP_MESSAGES = "followup_messages"
7979
IMAGE = "image"
80+
CLEAR_MESSAGE = "clear_message"
8081

8182

8283
class ChatContext(BaseModel):
@@ -93,7 +94,7 @@ class ChatResponse(BaseModel):
9394
"""Container for different types of chat responses."""
9495

9596
type: ChatResponseType
96-
content: str | Reference | StateUpdate | LiveUpdate | list[str] | Image
97+
content: str | Reference | StateUpdate | LiveUpdate | list[str] | Image | None
9798

9899
def as_text(self) -> str | None:
99100
"""
@@ -157,6 +158,12 @@ def as_image(self) -> Image | None:
157158
"""
158159
return cast(Image, self.content) if self.type == ChatResponseType.IMAGE else None
159160

161+
def as_clear_message(self) -> None:
162+
"""
163+
Return the content of clear_message response, which is None
164+
"""
165+
return cast(None, self.content)
166+
160167

161168
class ChatMessageRequest(BaseModel):
162169
"""Client-side chat request interface."""

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/AuthGuard-C_MUoo-o.js renamed to packages/ragbits-chat/src/ragbits/chat/ui-build/assets/AuthGuard-DZ_emzfC.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatHistory-Ctlh-0af.js renamed to packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatHistory-CseY-R1k.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatOptionsForm-v2JnxfkR.js renamed to packages/ragbits-chat/src/ragbits/chat/ui-build/assets/ChatOptionsForm-MVJIlSEE.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ragbits-chat/src/ragbits/chat/ui-build/assets/FeedbackForm-AHbpBR0A.js renamed to packages/ragbits-chat/src/ragbits/chat/ui-build/assets/FeedbackForm-_XZ_2nkf.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)