Chainlit

title: Contents 
style: nestedList # TOC style (nestedList|inlineFirstLevel)
minLevel: 1 # Include headings from the specified level
maxLevel: 4 # Include headings up to the specified level
includeLinks: true # Make headings clickable
debugInConsole: false # Print debug info in Obsidian console

Overview

Sources:

Chainlit is an open-source Python package to build production ready Conversational AI.

Features

  1. Build fast:Ā Integrate seamlessly with an existing code base or start from scratch in minutes

  2. Copilot:Ā Embed your chainlit app as a Software Copilot

  3. Data persistence:Ā Collect, monitor and analyze data from your users

  4. Visualize multi-steps reasoning:Ā Understand the intermediary steps that produced an output at a glance

  5. Iterate on prompts:Ā Deep dive into prompts in the Prompt Playground to understand where things went wrong and iterate

Integrations

Custom Frontend

Chainlit comes with a ChatGPT like Frontend Design|frontend that you can use out of the box. However, you can also build your own frontend and use Chainlit as a backend.

See Chainlit - Custom React Frontend on GitHub.

Installation

pip install chainlit
chainlit hello

Usage

  1. Create app.py: Create a new Python file namedĀ app.pyĀ in your project directory. This file will contain the main logic for your LLM application.
touch app.py
  1. Write Application Logic: InĀ app.py, import the Chainlit package and define a function that will handle incoming messages from the chatbot UI. Decorate the function with theĀ @cl.on_messageĀ decorator to ensure it gets called whenever a user inputs a message.

Hereā€™s the basic structure of the script:

import chainlit as cl
 
@cl.on_message
async def main(message: cl.Message):
    # Your custom logic goes here...
 
    # Send a response back to the user
    await cl.Message(
        content=f"Received: {message.content}",
    ).send()

TheĀ mainĀ function will be called every time a user inputs a message in the chatbot UI. You can put your custom logic within the function to process the userā€™s input, such as analyzing the text, calling an API, or computing a result.

TheĀ MessageĀ class is responsible for sending a reply back to the user. In this example, we simply send a message containing the userā€™s input.

  1. Run Application Locally: To start your Chainlit app, open a terminal and navigate to the directory containingĀ app.py. Then run the following command:
chainlit run app.py -w

TheĀ -wĀ flag tells Chainlit to enable auto-reloading, so you donā€™t need to restart the server every time you make changes to your application. Your chatbot UI should now be accessible atĀ http://localhost:8000.


Appendix

Note created on 2024-04-04 and last modified on 2024-04-04.

LIST FROM [[Tool - Python Chainlit]] AND -"CHANGELOG" AND -"04-RESOURCES/Tools/Tool - Python Chainlit"

(c) No Clocks, LLC | 2024