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 패키지를 설치하고 해당 패키지의 선택적인 "Retrieckechat"추가 기능을 설치합니다. export AUTOGEN_USE_DOCKER=False
$Env:AUTOGEN_USE_DOCKER="False"
AUTOGEN_USE_DOCKER=False 내보내기 Pyautogen에게 Docker 컨테이너를 사용하지 않고 호스트에서 직접 작업을 실행하도록 지시합니다. 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 모듈에서 retrieveuserproxyagent 클래스를 사용하여 사용자를 정의합니다. 이 클래스는 이름, 휴먼 입력 모드, 시스템 메시지, 최대 연속 자동 참조 및 입력으로 데이터베이스에서 정보를 검색하기위한 구성을 취합니다.
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.
"""마지막으로, retrieveUserProxyAgent 클래스의 initiate_chat 메소드를 사용하여 사용자와 챗봇 사이의 채팅 세션을 시작합니다.
user . initiate_chat ( assistant , problem = user_question )전반적 으로이 코드 파일은 데이터베이스에서 정보를 검색하고 언어 모델을 기반으로 응답을 생성하여 사용자 질문 또는 프롬프트에 응답 할 수있는 챗봇 시스템을 정의합니다. 챗봇은 또한 코드를 실행하고 사용자 질문의 맥락에 따라 답을 제공 할 수 있습니다.