ผู้ช่วย GenAI ที่ใช้ Langchain + Streamlit + Azure Cosmos DB สำหรับ MongoDB (vCore) + Docker
ผู้เขียน:
ทดสอบบน Linux Ubuntu 20.04 (อาจต้องปรับแต่งสำหรับระบบอื่น)
ข้อกำหนดฮาร์ดแวร์ขั้นต่ำสำหรับการปรับใช้แอป AI Assistant และการสร้างฐานข้อมูล Vector เท่านั้น (ไม่รวมแอป PanKB DB, ETL และ AI Assistant):
ความต้องการของระบบ:
กระบวนการเติมข้อมูล DB อาจใช้เวลานานถึง 90-150 นาที ขึ้นอยู่กับเซิร์ฟเวอร์ DEV และการกำหนดค่าคลัสเตอร์ที่แบ่งส่วน Cosmos DB ขนาดพื้นที่เก็บข้อมูล MongoDB ของคอลเลกชันที่มีประชากรคือ ~ 1.0 GiB รวม ดัชนี
โปรดทราบข้อจำกัดและข้อควรพิจารณาต่อไปนี้:
สร้างไฟล์ .env ในรูปแบบต่อไปนี้:
## Do not put this file under version control!
OPENAI_API_KEY=<insert the API key here without quotes>
COHERE_API_KEY=<insert the API key here without quotes>
TOGETHER_API_KEY=<insert the API key here without quotes>
GOOGLE_API_KEY=<insert the API key here without quotes>
ANTHROPIC_API_KEY=<insert the API key here without quotes>
REPLICATE_API_TOKEN=<insert the API key here without quotes>
VOYAGE_API_KEY=<insert the API key here without quotes>
## MongoDB-PROD (Azure Cosmos DB for MongoDB) Connection String
# Had to multiply maxIdleTimeMS by 10 to handle
# urllib3.exceptions.ProtocolError:
# ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
MONGODB_CONN_STRING = "<insert the connection string here with quotes>"
ไม่จำเป็นต้องดำเนินการสคริปต์ประชากร DB ในคอนเทนเนอร์นักเทียบท่า สามารถทำได้ด้วยคำสั่งต่อไปนี้:
# install all the requirements and dependencies
pip3 install -r requirements.txt
# Run the script with two command line arguments:
# the name of the folder containing the documents to feed to the LLM
# and
# the name of the MongoDB collection that will contain the vector DB
python3 make_vectordb.py ./Paper_all pankb_vector_store
คำสั่งสำหรับสร้างอิมเมจนักเทียบท่าและสร้างคอนเทนเนอร์นักเทียบท่าใหม่ด้วยแอป Streamlit ภายใน:
docker compose up -d --build --force-recreate
ไม่จำเป็นต้องดำเนินการแอป dockerized streamlit ใน tmux มันจะเปิดใช้งานและทำงานอยู่เสมอแม้หลังจากรีบูต VM แล้ว (ทำได้โดยใช้ตัวเลือก restart: always
)
สามารถตรวจสอบสถานะของคอนเทนเนอร์นักเทียบท่าได้ด้วยคำสั่งต่อไปนี้:
docker ps
คำสั่งควรสร้างประมาณ ผลลัพธ์ต่อไปนี้ในกรณีการใช้งานสำเร็จ:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54d89d7c4fad pankb_llm:latest "streamlit run strea…" 10 minutes ago Up 10 minutes 0.0.0.0:8501->8501/tcp, :::8501->8501/tcp pankb-llm