Autogenは、複数のエージェントを使用した会話型AIアプリケーションの開発を可能にするオープンソースフレームワークです。
Chroma DBは、ベクトル埋め込みを保存および取得するためのオープンソースベクトルデータベースです。
virtualenv -p python3.11 env_namepython -m venv env_nameenv_name/scripts/activate pip install -U "pyautogen[retrievechat]" chromadb
-U 、インストールする前に、すでにインストールされているパッケージを最新バージョンにアップグレードするようにPIPに指示します。"pyautogen[retrievechat]"はpyautogenパッケージをインストールし、そのパッケージのオプションの「retrieveChat」追加機能もインストールします export AUTOGEN_USE_DOCKER=False
$Env:AUTOGEN_USE_DOCKER="False"
AUTOGEN_USE_DOCKER=Falseエクスポートに、dockerコンテナを使用するのではなく、ホストに直接タスクを実行するようにpyautogenに指示します。 Dockerの依存関係をバイパスしますが、Dockerが提供する分離の利点の一部も失います。
export OPENAI_API_KEY=Fxxxxxxxxxxxxxxxxxxxxxxxxx
$Env:OPENAI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxx"
app.pyを実行します python app.py
このコードファイルは、AutogenおよびChromADBライブラリを使用してチャットボットシステムを定義します。これがコードの段階的な内訳です:
最初のステップは、必要なライブラリをインポートすることです。この場合、AutogenとChromaDBを使用して、データベースから情報を取得し、言語モデルに基づいて応答を生成できるチャットボットを作成します。
import autogen
import chromadb次に、Autogen LibraryのAssistantAgentクラスを使用してチャットボットアシスタントを定義します。このクラスは、入力として名前、言語モデルの構成、およびシステムメッセージを取得します。
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."
)また、autogen.agentchat.contribモジュールからRetiveUserproxyagentクラスを使用してユーザーを定義します。このクラスは、名前、人間の入力モード、システムメッセージ、連続した自動レプリーの最大数、および入力としてデータベースから情報を取得するための構成を取ります。
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" },
)ユーザーの質問またはプロンプトを文字列変数として定義します。
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.
"""最後に、retieveuserproxyentクラスのinitiate_chatメソッドを使用して、ユーザーとチャットボットの間のチャットセッションを開始します。
user . initiate_chat ( assistant , problem = user_question )全体として、このコードファイルは、データベースから情報を取得し、言語モデルに基づいて回答を生成することにより、ユーザーの質問またはプロンプトに応答できるチャットボットシステムを定義します。チャットボットは、コードを実行して、ユーザーの質問のコンテキストに基づいて回答を提供することもできます。