Chainlit

2.11.0 · active · verified Sun Apr 12

Chainlit is an open-source Python framework designed to simplify the creation of interactive user interfaces for Large Language Model (LLM) applications. It enables developers to build ChatGPT-like UIs with minimal frontend code, offering features such as chat lifecycle hooks, UI actions, real-time message streaming, and integrations with popular LLM libraries like LangChain and LlamaIndex. The library is actively maintained with frequent releases, currently at version 2.11.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Chainlit application. Create a file named `app.py`, paste the code, and run it using `chainlit run app.py -w` in your terminal. This will start the Chainlit UI in your browser, where you can interact with the bot. The `@cl.on_chat_start` function sends a welcome message, and `@cl.on_message` handles incoming user messages, simulating an intermediate step and then echoing the user's input.

import chainlit as cl
import os

# Optional: Set CHAINLIT_AUTH_SECRET if authentication is enabled for your app
# os.environ['CHAINLIT_AUTH_SECRET'] = os.environ.get('CHAINLIT_AUTH_SECRET', 'your_secret_key_here_for_testing')

@cl.on_chat_start
async def start():
    await cl.Message(
        content="Welcome! I am a simple Chainlit bot. Type anything to get a response."
    ).send()

@cl.on_message
async def main(message: cl.Message):
    # Simulate a tool's response
    await cl.Message(author="Tool", content=f"Processing: {message.content}", indent=1).send()

    # Send back the final answer
    await cl.Message(content=f"You said: {message.content}").send()

# To run this:
# 1. Save the code as `app.py`
# 2. Run `chainlit run app.py -w` in your terminal

view raw JSON →