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

feat(Chat): A .on_user_submit callback can now access user input through a function parameter #1801

Merged
merged 3 commits into from
Dec 20, 2024

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Dec 17, 2024

This way you can get the user input directly from the submit callback rather than the chat.user_input() method

from chatlas import ChatAnthropic
from shiny.express import ui

chat = ui.Chat(
    id="ui_chat",
    messages=["Hi! How can I help you today?"],
)
chat.ui()

chat_model = ChatAnthropic()

@chat.on_user_submit
async def handle_user_input(user_input):
    response = chat_model.stream(user_input)
    await chat.append_message_stream(response)

Also, looking forward, a decent way to provide access to uploaded files/images might be through additional function parameters?

@cpsievert cpsievert marked this pull request as ready for review December 20, 2024 15:49
@cpsievert cpsievert merged commit 70acf34 into main Dec 20, 2024
41 checks passed
@cpsievert cpsievert deleted the chat-user-input-parameter branch December 20, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant