AutoGen is an open-source framework that enables the development of conversational AI applications using multiple agents.
Chroma DB is an open-source vector database for storing and retrieving vector embeddings.
virtualenv -p python3.11 env_name
python -m venv env_name
env_name/scripts/activate
pip install -U "pyautogen[retrievechat]" chromadb
-U
tells pip to upgrade any already installed packages to their latest versions before installing."pyautogen[retrievechat]"
installs the pyautogen package and also installs the optional "retrievechat" extra feature of that package
export AUTOGEN_USE_DOCKER=False
$Env:AUTOGEN_USE_DOCKER="False"
Exporting AUTOGEN_USE_DOCKER=False
tells pyautogen to run its tasks directly on the host rather than using Docker containers. It bypasses the Docker dependency but also loses some of the isolation benefits Docker provides.
export OPENAI_API_KEY=Fxxxxxxxxxxxxxxxxxxxxxxxxx
$Env:OPENAI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxx"
python app.py
This code file defines a chatbot system using the autogen and chromadb libraries. Here's a step-by-step breakdown of the code:
The first step is to import the necessary libraries. In this case, we're using autogen and chromadb to create a chatbot that can retrieve information from a database and generate responses based on a language model.
import autogen
import chromadb
Next, we define the chatbot assistant using the AssistantAgent class from the autogen library. This class takes a name, language model configuration, and system message as input.
assistant = AssistantAgent(
name="my_assistant",
llm_config=llm_config_proxy,
system_message="You are a helpful assistant. Provide accurate answers based on the context. Respond 'Unsure about answer' if uncertain."
)
We also define the user using the RetrieveUserProxyAgent class from the autogen.agentchat.contrib module. This class takes a name, human input mode, system message, maximum number of consecutive auto-replies, and configuration for retrieving information from a database as input.
user = RetrieveUserProxyAgent(
name="me_user",
human_input_mode="NEVER",
system_message="Assistant who has extra content retrieval power for solving difficult problems.",
max_consecutive_auto_reply=10,
retrieve_config={
"task": "code",
"docs_path": ['./docs/autogen.pdf'],
"chunk_token_size": 1000,
"model": config_list[0]["model"],
"client": chromadb.PersistentClient(path='/tmp/chromadb'),
"collection_name": "pdfreader",
"get_or_create": True,
},
code_execution_config={"work_dir": "coding"},
)
We define the user's question or prompt as a string variable.
user_question = """
Compose a short blog post showcasing how AutoGen is revolutionizing the future of Generative AI
through the collaboration of various agents. Craft an introduction, main body, and a compelling
conclusion. Encourage readers to share the post. Keep the post under 500 words.
"""
Finally, we initiate the chat session between the user and the chatbot using the initiate_chat method of the RetrieveUserProxyAgent class.
user.initiate_chat(assistant, problem=user_question)
Overall, this code file defines a chatbot system that can respond to user questions or prompts by retrieving information from a database and generating responses based on a language model. The chatbot can also execute code and provide answers based on the context of the user's question.