title | tags | ||
---|---|---|---|
AutoGen with Chainlit |
|
Warning: The async version of the application is currently not working and is a draft.
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.sample
file to a new.env
file and replace theapi_key
value with your own OpenAI API key. - Run the Chainlit app:
- You can modify the initial AutoGen prompt in the
app.py
file to change the task.
- Do not run with
chainlit run app.py -w
as it may cause unexpected behavior. - You can monkey-patch methods of the
Agent
class 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 ofAssistantAgent
that sends messages to other agents.ChainlitUserProxyAgent
: A subclass ofUserProxyAgent
that 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.py
This 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.