In the intro, we learned how the .app()
method launches a web app with a simple chat interface, for example:
from chatlas import ChatAnthropic
= ChatAnthropic()
chat chat.app()
This is a great way to quickly test your model, but you’ll likely want to embed similar functionality into a larger web app. Here’s how you can do that we different web frameworks.
Shiny
Using Shiny’s ui.Chat
component, you can simply pass user input from the component into the chat.stream()
method. This generate a response stream that can then be passed to .append_message_stream()
.
from chatlas import ChatAnthropic
from shiny.express import ui
= ChatAnthropic()
chat
= ui.Chat(
chat_ui id="ui_chat",
=["Hi! How can I help you today?"],
messages
)
chat_ui.ui()
@chat_ui.on_user_submit
async def _():
= chat.stream(chat_ui.user_input())
response await chat_ui.append_message_stream(response)
Streamlit
Coming soon