- Megabots ให้แอพ LLM ที่ล้ำสมัยที่ล้ำสมัยทำให้เกิดการผลิตที่ยอดเยี่ยมดังนั้นคุณไม่ต้องสร้างมันขึ้นมาตั้งแต่เริ่มต้น? สร้างบอทตอนนี้?
ห้องสมุด MeGabots สามารถใช้ในการสร้างบอทที่:
- Megabots ได้รับการสนับสนุนจากเครื่องมือที่มีชื่อเสียงที่สุดสำหรับการผลิต AI มันใช้ Langchain สำหรับการจัดการโซ่ LLM, Langchain-Serve เพื่อสร้าง API Ready Production, Gradio เพื่อสร้าง UI ในขณะนี้ใช้ OpenAI เพื่อสร้างคำตอบ แต่เราวางแผนที่จะสนับสนุน LLM อื่น ๆ ในอนาคต
หมายเหตุ: นี่เป็นงานที่กำลังดำเนินการ API อาจเปลี่ยนแปลง
pip install megabots from megabots import bot
import os
os . environ [ "OPENAI_API_KEY" ] = "my key"
# Create a bot with one line of code. Automatically loads your data from ./index or index.pkl.
# Keep in mind that you need to have one or another.
qnabot = bot ( "qna-over-docs" )
# Ask a question
answer = qnabot . ask ( "How do I use this bot?" )
# Save the index to save costs (GPT is used to create the index)
qnabot . save_index ( "index.pkl" )
# Load the index from a previous run
qnabot = bot ( "qna-over-docs" , index = "./index.pkl" )
# Or create the index from a directory of documents
qnabot = bot ( "qna-over-docs" , index = "./index" )
# Change the model
qnabot = bot ( "qna-over-docs" , model = "text-davinci-003" ) คุณสามารถเปลี่ยนบอท promnpt เพื่อปรับแต่งตามความต้องการของคุณ ในประเภทของบอท qna-over-docs คุณจะต้องผ่านตัวแปร 2 ตัวแปรสำหรับ context (Knwoledge ค้นหาจากดัชนี) และ question (คำถามของมนุษย์)
from megabots import bot
prompt = """
Use the following pieces of context to answer the question at the end.
If you don't know the answer, just say that you don't know, don't try to make up an answer.
Answer in the style of Tony Stark.
{context}
Question: {question}
Helpful humorous answer:"""
qnabot = bot ( "qna-over-docs" , index = "./index.pkl" , prompt = prompt )
qnabot . ask ( "what was the first roster of the avengers?" ) คุณสามารถเพิ่มหน่วยความจำลงใน bot ของคุณได้อย่างง่ายดายโดยใช้พารามิเตอร์หน่วย memory มันยอมรับสตริงที่มีประเภทของหน่วยความจำที่จะใช้ ค่าเริ่มต้นนี้สำหรับ dafaults ที่มีสติ หากคุณต้องการการกำหนดค่าเพิ่มเติมคุณสามารถใช้ฟังก์ชั่นหน่วย memory และผ่านประเภทของหน่วยความจำและการกำหนดค่าที่คุณต้องการ
from megabots import bot
qnabot = bot ( "qna-over-docs" , index = "./index.pkl" , memory = "conversation-buffer" )
print ( qnabot . ask ( "who is iron man?" ))
print ( qnabot . ask ( "was he in the first roster?" ))
# Bot should understand who "he" refers to. หรือใช้ฟังก์ชันโรงงานหน่วย memory
from megabots import bot , memory
mem ( "conversation-buffer-window" , k = 5 )
qnabot = bot ( "qna-over-docs" , index = "./index.pkl" , memory = mem )
print ( qnabot . ask ( "who is iron man?" ))
print ( qnabot . ask ( "was he in the first roster?" )) หมายเหตุ: สำหรับบอท qna-over-docs เมื่อใช้หน่วยความจำและผ่านพรอมต์ที่กำหนดเองของคุณเป็นสิ่งสำคัญที่จะต้องจำไว้ว่าต้องผ่านตัวแปรอีกหนึ่งตัวไปยังพรอมต์ที่กำหนดเองของคุณเพื่ออำนวยความสะดวกสำหรับประวัติการแชท ชื่อตัวแปรคือ history
from megabots import bot
prompt = """
Use the following pieces of context to answer the question at the end.
If you don't know the answer, just say that you don't know, don't try to make up an answer.
{context}
{history}
Human: {question}
AI:"""
qnabot = bot ( "qna-over-docs" , prompt = prompt , index = "./index.pkl" , memory = "conversation-buffer" )
print ( qnabot . ask ( "who is iron man?" ))
print ( qnabot . ask ( "was he in the first roster?" )) Megabots bot ยังสามารถใช้ Milvus เป็นแบ็กเอนด์สำหรับเครื่องมือค้นหา คุณสามารถค้นหาตัวอย่างของวิธีการทำด้านล่าง
ในการเรียกใช้ Milvus คุณต้องทำตามคู่มือนี้เพื่อดาวน์โหลดไฟล์เขียน Docker และเรียกใช้ คำสั่งคือ:
wget https://raw.githubusercontent.com/milvus-io/pymilvus/v2.2.7/examples/hello_milvus.pyจากนั้นคุณสามารถติดตั้ง Attu เป็นเครื่องมือการจัดการสำหรับ Milvus
from megabots import bot
# Attach a vectorstore by passing the name of the database. Default port for milvus is 19530 and default host is localhost
# Point it to your files directory so that it can index the files and add them to the vectorstore
bot = bot ( "qna-over-docs" , index = "./examples/files/" , vectorstore = "milvus" )
bot . ask ( "what was the first roster of the avengers?" ) หรือใช้ฟังก์ชั่น vectorstore Factory สำหรับการปรับแต่งเพิ่มเติม
from megabots import bot , vectorstore
milvus = vectorstore ( "milvus" , host = "localhost" , port = 19530 )
bot = bot ( "qna-over-docs" , index = "./examples/files/" , vectorstore = milvus ) นอกจากนี้คุณยังสามารถเปิดเผยจุดสิ้นสุดของบอทในพื้นที่โดยใช้ Langchain-Serve ไฟล์ตัวอย่าง api.py มีให้ในโฟลเดอร์ megabots
ในการเปิดเผย API ในพื้นที่คุณสามารถทำได้
lc-serve deploy local megabots.api จากนั้นคุณควรจะสามารถเยี่ยมชม http://localhost:8000/docs เพื่อดูและโต้ตอบกับเอกสาร API
ในการปรับใช้ API ของคุณไปยังคลาวด์คุณสามารถทำและเชื่อมต่อกับ API โดยใช้จุดสิ้นสุดที่ให้ไว้ในเอาต์พุต
lc-serve deploy jcloud megabots.api คุณสามารถเปิดเผย Gradio UI สำหรับบอทโดยใช้ฟังก์ชั่น create_interface สมมติว่าไฟล์ของคุณเรียกว่า ui.py run gradio qnabot/ui.py เพื่อเรียกใช้ UI ในพื้นที่ จากนั้นคุณควรไปที่ http://127.0.0.1:7860 เพื่อดูเอกสาร API
from megabots import bot , create_interface
demo = create_interface ( bot ( "qna-over-docs" )) ฟังก์ชั่น bot ควรใช้เป็นจุดเริ่มต้นสำหรับการสร้างและปรับแต่งบอทของคุณ ด้านล่างเป็นรายการของอาร์กิวเมนต์ที่มีอยู่ใน bot
| การโต้แย้ง | คำอธิบาย |
|---|---|
| งาน | ประเภทของบอทที่จะสร้าง ตัวเลือกที่มีอยู่: qna-over-docs เพิ่มอีกเร็ว ๆ นี้ |
| ดัชนี | ระบุดัชนีที่จะใช้สำหรับบอท มันอาจเป็นไฟล์ดัชนีที่บันทึกไว้ (เช่น index.pkl ) หรือไดเรกทอรีของเอกสาร (เช่น . ./index ) ในกรณีของไดเรกทอรีดัชนีจะถูกสร้างขึ้นโดยอัตโนมัติ หากไม่มีดัชนีระบุ bot จะค้นหา index.pkl หรือ ./index |
| แบบอย่าง | ชื่อของโมเดลที่จะใช้สำหรับบอท คุณสามารถระบุโมเดลอื่นได้โดยให้ชื่อเช่น "Text-Davinci-003" รุ่นที่รองรับ: gpt-3.5-turbo (ค่าเริ่มต้น), text-davinci-003 มีมากขึ้นในไม่ช้า |
| แจ้ง | เทมเพลตสตริงสำหรับพรอมต์ซึ่งกำหนดรูปแบบของคำถามและบริบทที่ส่งผ่านไปยังโมเดล เทมเพลตควรมีตัวแปรตัวยึดตำแหน่งเช่น SO: context , {question} และในกรณีของการใช้ history ความจำ |
| หน่วยความจำ | ประเภทของหน่วยความจำที่จะใช้โดยบอท สามารถเป็นสตริงที่มีประเภทของหน่วยความจำหรือคุณสามารถใช้ฟังก์ชันโรงงานหน่วย memory ความทรงจำที่ได้รับการสนับสนุน: conversation-buffer , conversation-buffer-window |
| เวกเตอร์สโตร์ | เวกเตอร์สโตร์ที่จะใช้สำหรับดัชนี สามารถเป็นสตริงที่มีชื่อของฐานข้อมูลหรือคุณสามารถใช้ฟังก์ชัน vectorstore Factory รองรับ DBS: milvus |
แบบจำลองภาษาขนาดใหญ่ (LLMS) มีประสิทธิภาพ แต่พวกเขาไม่สามารถตอบคำถามเกี่ยวกับเอกสารที่พวกเขาไม่ได้เห็น หากคุณต้องการใช้ LLM เพื่อตอบคำถามเกี่ยวกับเอกสารที่ไม่ได้รับการฝึกฝนคุณต้องให้ข้อมูลเกี่ยวกับเอกสารเหล่านั้น ในการแก้ปัญหานี้เราใช้ "Generation ที่เพิ่มขึ้น"
กล่าวง่ายๆเมื่อคุณมีคำถามคุณจะค้นหาเอกสารที่เกี่ยวข้องก่อน จากนั้นคุณให้เอกสารและคำถามกับโมเดลภาษาเพื่อสร้างคำตอบ ในการทำงานนี้คุณต้องใช้เอกสารของคุณในรูปแบบที่ค้นหาได้ (ดัชนี) กระบวนการนี้เกี่ยวข้องกับสองขั้นตอนหลัก: (1) การเตรียมเอกสารของคุณเพื่อการสืบค้นที่ง่ายและ (2) โดยใช้วิธีการสร้างการเพิ่มการดึง
qna-over-docs ใช้ FAISS เพื่อสร้างดัชนีของเอกสารและ GPT เพื่อสร้างคำตอบ
ลำดับ
ผู้ใช้นักแสดง
ผู้เข้าร่วม API
ผู้เข้าร่วม LLM
เวกเตอร์สโตร์ผู้เข้าร่วม
ผู้เข้าร่วม IngestionEngine
Datalake ผู้เข้าร่วม
จำนวนอัตโนมัติ
หมายเหตุเกี่ยวกับ API, Datalake: การกลืนกินเฟส
วนรอบทุกครั้ง x
IngestionEngine ->> Datalake: โหลดเอกสาร
Datalake ->> IngestionEngine: ส่งคืนข้อมูล
IngestionEngine ->> IngestionEngine: แยกเอกสารและสร้าง EMBEDDING
IngestionEngine ->> Vectorstore: เก็บเอกสารและการฝังตัว
จบ
หมายเหตุเกี่ยวกับ API, Datalake: เฟสการสร้าง
ผู้ใช้ ->> API: รับคำถามผู้ใช้
API ->> Vectorstore: เอกสารค้นหาในดัชนีที่เกี่ยวข้องกับคำถาม
API ->> API: สร้างพรอมต์จากคำถามและเอกสารที่เกี่ยวข้องใด ๆ
api ->> llm: ส่งพรอมต์ไปยังรุ่น
LLM ->> API: รับการตอบกลับจากรุ่น
API ->> ผู้ใช้: การตอบกลับส่งคืน