In the intro, we learned how the .app() method launches a web app with a simple chat interface, for example:

from chatlas import ChatAnthropic

chat = ChatAnthropic()
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

chat = ChatAnthropic()

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


@chat_ui.on_user_submit
async def _():
    response = chat.stream(chat_ui.user_input())
    await chat_ui.append_message_stream(response)

Streamlit

Coming soon