In this example, we will learn how to use Chainlit and Embedchain together.



First, install the required packages:

pip install embedchain chainlit

Create a Chainlit app

Create a new file called and add the following code:

import chainlit as cl
from embedchain import App

import os

os.environ["OPENAI_API_KEY"] = "sk-xxx"

async def on_chat_start():
    app = App.from_config(config={
        'app': {
            'config': {
                'name': 'chainlit-app'
        'llm': {
            'config': {
                'stream': True,
    # import your data here
    app.collect_metrics = False
    cl.user_session.set("app", app)

async def on_message(message: cl.Message):
    app = cl.user_session.get("app")
    msg = cl.Message(content="")
    for chunk in await cl.make_async(
        await msg.stream_token(chunk)
    await msg.send()

Run the app

chainlit run

Try it out

Open the app in your browser and start chatting with it!