Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Use .stream_async() when streaming #31

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions chatlas/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def app(
port: int = 0,
launch_browser: bool = True,
bg_thread: Optional[bool] = None,
echo: Optional[Literal["text", "all", "none"]] = None,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how this is being used below, could be cleaner to default this to "none". I forget now the previous default behavior but would none be preferred over text for both cases (stream = True/False) unless explicitly set by the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In stream=False, the default is "text". But for stream=True, the default is "none".

With the conflicting behavior, I set the default to None (which goes to the appropriate default value given stream's value).

kwargs: Optional[SubmitInputArgsT] = None,
):
"""
Expand All @@ -404,6 +405,8 @@ def app(
bg_thread
Whether to run the app in a background thread. If `None`, the app will
run in a background thread if the current environment is a notebook.
echo
Whether to echo text content, all content (i.e., tool calls), or no content. Defaults to `"none"` when `stream=True` and `"text"` when `stream=False`.
kwargs
Additional keyword arguments to pass to the method used for requesting
the response.
Expand Down Expand Up @@ -438,10 +441,22 @@ async def _():
return
if stream:
await chat.append_message_stream(
self.stream(user_input, kwargs=kwargs)
await self.stream_async(
user_input,
kwargs=kwargs,
echo=echo or "none",
)
)
else:
await chat.append_message(str(self.chat(user_input, kwargs=kwargs)))
await chat.append_message(
str(
self.chat(
user_input,
kwargs=kwargs,
echo=echo or "text",
)
)
)

app = App(app_ui, server)

Expand Down
Loading