app.py
in your project directory. This file will contain the main logic for your LLM application.
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:
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.
app.py
. Then run the following command:
-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.