Skip to content

Commit 15d1d6c

Browse files
Merge pull request #25 from basedosdados/chore/handle-new-streaming
chore: handle new streaming
2 parents 0d196dd + afb79bf commit 15d1d6c

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

frontend/components/chat_page.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def render(self):
330330

331331
with st.status(label=label, state=state) as status:
332332
for step in message_pair.safe_steps:
333-
st.caption(step.content)
333+
display_streaming_step(step)
334334

335335
if message_pair.assistant_message:
336336
st.write(message_pair.assistant_message)
@@ -370,7 +370,7 @@ def render(self):
370370
if streaming_status == "running":
371371
step: Step = message
372372
status.update(label=step.label)
373-
st.caption(step.content)
373+
display_streaming_step(step)
374374
elif streaming_status == "complete":
375375
message_pair: MessagePair = message
376376
if message_pair.assistant_message:
@@ -438,3 +438,18 @@ def toggle_flag(flag_id: str):
438438
flag_id (str): The flag identifier.
439439
"""
440440
st.session_state[flag_id] = not st.session_state[flag_id]
441+
442+
def display_streaming_step(step: Step):
443+
"""Display a streaming step.
444+
445+
Args:
446+
step (Step): The step to display, containing either a string
447+
or a list of `StepContent` items.
448+
"""
449+
if isinstance(step.content, str):
450+
st.caption(step.content)
451+
else:
452+
for content in step.content:
453+
if content.title:
454+
st.caption(f"##### :green[{content.title}]")
455+
st.caption(content.body.strip())

frontend/components/typewriter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
1313
@keyframes blink-caret {
1414
from, to { border-color: transparent; }
15-
50% { border-color: white; }
15+
50% { border-color: #31333f; }
1616
}
1717
1818
@keyframes disappear {
19-
0% { border-color: white; }
19+
0% { border-color: #31333f; }
2020
100% { border-color: transparent; }
2121
}
2222
@@ -28,7 +28,7 @@
2828
overflow: hidden; /* Ensures the content is not revealed until the animation */
2929
padding-right: 0.1em; /* Adds space between the text and the cursor */
3030
margin: 0 auto; /* Centering effect */
31-
border-right: 0.125em solid white; /* The typewriter cursor */
31+
border-right: 0.125em solid #31333f; /* The typewriter cursor */
3232
animation:
3333
typing 1s steps(80, end),
3434
blink-caret 0.75s step-end infinite,

frontend/datatypes/datatypes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ class UserMessage(BaseModel):
1616
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
1717
content: str
1818

19+
class StepContent(BaseModel):
20+
title: str|None
21+
body: str
22+
1923
class Step(BaseModel):
2024
label: str
21-
content: str
25+
content: str|list[StepContent] # str allowed for backward compatibility
2226

2327
class MessagePair(BaseModel):
2428
id: UUID4 = Field(default_factory=uuid.uuid4)

0 commit comments

Comments
 (0)