Chainlit
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
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.
- 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:
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:
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
(c) No Clocks, LLC | 2024