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
-
Build fast:Ā Integrate seamlessly with an existing code base or start from scratch in minutes
-
Copilot:Ā Embed your chainlit app as a Software Copilot
-
Data persistence:Ā Collect, monitor and analyze data from your users
-
Visualize multi-steps reasoning:Ā Understand the intermediary steps that produced an output at a glance
-
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
- 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
- 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.
- 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.
Backlinks
LIST FROM [[Tool - Python Chainlit]] AND -"CHANGELOG" AND -"04-RESOURCES/Tools/Tool - Python Chainlit"
(c) No Clocks, LLC | 2024