| title | AutoGen with Chainlit | ||
|---|---|---|---|
| tags |
|
This repository demonstrates the integration of AutoGen with Chainlit to create an interactive chat application that can execute code and perform tasks such as plotting a chart of stock price changes and saving it to disk.
Follow these steps to get started with AutoGen and Chainlit:
- (Optional) Create and activate a Python virtual environment:
python3 -m venv venv
source venv/bin/activate- Install the required dependencies:
pip install chainlit pyautogen- Copy the
.env.samplefile to a new.envfile and replace theapi_keyvalue with your own OpenAI API key. - Run the Chainlit app:
- You can modify the initial AutoGen prompt in the
app.pyfile to change the task.
- Do not run with
chainlit run app.py -was it may cause unexpected behavior. - You can monkey-patch methods of the
Agentclass if needed, instead of creating a subclass.
The app.py file contains the main logic for the Chainlit chat application. It defines custom Agent classes that handle sending messages and processing user input.
ChainlitAssistantAgent: A subclass ofAssistantAgentthat sends messages to other agents.ChainlitUserProxyAgent: A subclass ofUserProxyAgentthat handles user input and can send messages to other agents.
The async_app.py file is a placeholder for future asynchronous support, pending the resolution of an issue in the AutoGen library.
To change the task, modify the TASK variable in app.py with the desired prompt.
To start the application, use the following command:
chainlit run app.pyThis will initiate a chat session where the user can interact with the assistant agent to perform tasks such as generating a plot for NVDA stock price change YTD.
For more detailed information on the functions and classes used, refer to the source code in the app.py and async_app.py files.