Integrating with Chainlit
In this guide we'll walk through a quick demo app of using BREVIAN's SDK to integrate with Chainlit.
Prerequisites
BREVIAN sdk setup
: https://docsChainlit setup
: https://docs.brevian.ai/sdks#pythonBREVIAN API Token
: Securely generated from BREVIAN's API keys page.
Always keep your token safe and disable it if you suspect it has been compromised.
Step-by-Step Guide
1. Setup BREVIAN API Token
Follow the chainlit guide to setup a demo script.
Chainlit2. Simple Example
import chainlit as cl
from brevian import PostChatRequestMessagesItem, PostChatRequestMessagesItemRole
from brevian.client import BrevianApi
client = BrevianApi(
token={"token"},
base_url="https://chat.brevian.ai/api/v1/",
)
@cl.on_message # this function will be called every time a user inputs a message in the UI
async def main(message: cl.Message):
"""
This function is called every time a user inputs a message in the UI.
It sends back an intermediate response from the tool, followed by the final answer.
Args:
message: The user's message.
Returns:
None.
"""
# Call the BREVIAN
response = client.post_chat(
messages=[
PostChatRequestMessagesItem(
role=PostChatRequestMessagesItemRole.USER,
content=message.content,
)
],
agent_id="{find this is the URL of the agent you want to use e.g e1bf33db-feb6-49a3-a766-2e727ded3ee9}",
)
# Send the final answer.
await cl.Message(content=response.choices[0].message.content).send()
3. Run the app!
chainlit run demo.py -w