Skip to content

Commit

Permalink
Update some usages of scroll-to (google#915)
Browse files Browse the repository at this point in the history
We can remove the intentional delay on scroll-to now.

There is one case where this does not work as expected though. When the
chat message is not streamed, the scroll to with hidden box strategy
does not work since the output is too fast. This occurred on LLM
Rewriter example. But I updated it to fake the streaming.
  • Loading branch information
richard-to committed Sep 1, 2024
1 parent eb2e9fa commit 41692f5
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 18 deletions.
5 changes: 1 addition & 4 deletions ai/src/ai/offline_common/inputs/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ def submit():
output = []
output.append(ChatMessage(role=_ROLE_USER, content=input))
state.in_progress = True
yield

me.scroll_into_view(key="scroll-to")
time.sleep(0.15)
yield

start_time = time.time()
Expand Down Expand Up @@ -262,7 +259,7 @@ def toggle_theme(e: me.ClickEvent):
me.markdown(msg.content)

if state.in_progress:
with me.box(key="scroll-to", style=me.Style(height=300)):
with me.box(key="scroll-to", style=me.Style(height=250)):
pass

with me.box(style=_STYLE_CHAT_INPUT_BOX):
Expand Down
3 changes: 0 additions & 3 deletions demo/fancy_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,7 @@ def on_click_submit_chat_msg(e: me.ClickEvent):
output = []
output.append(ChatMessage(role="user", content=input))
state.in_progress = True
yield

me.scroll_into_view(key="scroll-to")
time.sleep(0.15)
yield

start_time = time.time()
Expand Down
6 changes: 2 additions & 4 deletions demo/llm_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def page():
me.icon(icon="edit_note")

if state.in_progress:
with me.box(key="scroll-to", style=me.Style(height=300)):
with me.box(key="scroll-to", style=me.Style(height=250)):
pass
with me.box(style=_STYLE_CHAT_INPUT_BOX):
with me.box(style=me.Style(flex_grow=1)):
Expand Down Expand Up @@ -187,10 +187,7 @@ def on_click_submit_chat_msg(e: me.ClickEvent | me.InputEnterEvent):
output = []
output.append(ChatMessage(role=_ROLE_USER, content=input))
state.in_progress = True
yield

me.scroll_into_view(key="scroll-to")
time.sleep(0.15)
yield

start_time = time.time()
Expand Down Expand Up @@ -240,6 +237,7 @@ def respond_to_chat(input: str, history: list[ChatMessage]):
"Habitant morbi tristique senectus et netus et malesuada.",
]
for line in random.sample(lines, random.randint(3, len(lines) - 1)):
time.sleep(0.25)
yield line + " "


Expand Down
5 changes: 1 addition & 4 deletions mesop/examples/inlined_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ def submit():
output = []
output.append(ChatMessage(role=_ROLE_USER, content=input))
state.in_progress = True
yield

me.scroll_into_view(key="scroll-to")
time.sleep(0.15)
yield

start_time = time.time()
Expand Down Expand Up @@ -247,7 +244,7 @@ def toggle_theme(e: me.ClickEvent):
me.markdown(msg.content)

if state.in_progress:
with me.box(key="scroll-to", style=me.Style(height=300)):
with me.box(key="scroll-to", style=me.Style(height=250)):
pass

with me.box(style=_STYLE_CHAT_INPUT_BOX):
Expand Down
3 changes: 0 additions & 3 deletions mesop/labs/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ def submit():
output = []
output.append(ChatMessage(role=_ROLE_USER, content=input))
state.in_progress = True
yield

me.scroll_into_view(key="scroll-to")
time.sleep(0.15)
yield

start_time = time.time()
Expand Down

0 comments on commit 41692f5

Please sign in to comment.