? Megabots는 최첨단 생산 준비 LLM 앱을 Mega-Easty로 제공하므로 처음부터 구축 할 필요가 없습니까? 지금 봇을 만드시겠습니까?
Megabots 라이브러리는 다음과 같은 봇을 만드는 데 사용될 수 있습니다.
? Megabots는 AI를 생산하는 가장 유명한 도구로 뒷받침됩니다. LLM 체인을 관리하기 위해 Langchain을 사용하여 Langchain-Serve를 사용하여 생산 준비 API를 만들어 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" ) 당신은 당신의 요구에 맞게 그것을 사용자 정의하기 위해 프롬프트 봇을 변경할 수 있습니다. qna-over-docs 유형의 봇에서 context (인덱스에서 검색 된 Knwoledge) 및 question (인간 질문)에 대해 2 개의 변수를 전달해야합니다.
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?" ) memory 매개 변수를 사용하여 bot 에 메모리를 쉽게 추가 할 수 있습니다. 사용될 메모리 유형이있는 문자열을 허용합니다. 이것은 기본적으로 어떤 제정신도 할 수 있습니다. 더 많은 구성이 필요한 경우 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 BOT의 경우 메모리를 사용하고 사용자 정의 프롬프트를 통과 할 때는 채팅 기록을 촉진하기 위해 사용자 정의 프롬프트에 하나 더 변수를 전달하는 것이 중요합니다. 변수 이름은 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 Compose 파일을 다운로드하여 실행해야합니다. 명령은 다음과 같습니다.
wget https://raw.githubusercontent.com/milvus-io/pymilvus/v2.2.7/examples/hello_milvus.py그런 다음 Milvus의 관리 도구로 Attu를 설치할 수 있습니다.
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 create_interface 함수를 사용하여 봇의 Gradio UI를 노출시킬 수 있습니다. 파일을 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 | 인덱스에 사용되는 벡터 스토어. Databse의 이름을 가진 문자열이거나 vectorstore Factory 기능을 사용할 수 있습니다. 지원되는 DBS : milvus . |
대형 언어 모델 (LLM)은 강력하지만 보지 못한 문서에 대한 질문에 대답 할 수는 없습니다. LLM을 사용하여 교육을받지 않은 문서에 대한 질문에 답하려면 해당 문서에 대한 정보를 제공해야합니다. 이를 해결하기 위해 "검색 증강 세대"를 사용합니다.
간단히 말해서 질문이 있으면 먼저 관련 문서를 검색합니다. 그런 다음 문서와 질문을 언어 모델에 제공하여 답을 생성합니다. 이 작업을 수행하려면 검색 가능한 형식 (색인)으로 문서가 필요합니다. 이 과정에는 (1) 쿼리를 쉽게하기 위해 문서 준비 및 (2) 검색 증강 생성 방법을 사용하여 두 가지 주요 단계가 포함됩니다.
qna-over-docs FAISS를 사용하여 문서 색인과 GPT를 만들어 답을 생성합니다.
시퀀스 인디 아그램
배우 사용자
참가자 API
참가자 LLM
참가자 vectorstore
참가자 섭취 엔진
참가자 Datalake
Autonumber
API, Datalake : 섭취 단계에 대한 참고
매번 X 시간을 반복하십시오
ensestionEngine- >> Datalake :로드 문서
Datalake- >> eningestionEngine : 반환 데이터
eningestionEngine- >> eningestionEngine : 문서를 분할하고 임베딩을 만듭니다
eningestionEngine- >> vectorstore : 문서와 임베딩을 저장합니다
끝
API, Datalake : Generation Phase에 대한 참고 사항
사용자 ->> API : 사용자 질문을받습니다
API- >> vectorStore : 질문과 관련된 색인의 조회 문서
API- >> API : 질문 및 관련 문서에서 프롬프트를 구성합니다.
API- >> llm : 프롬프트를 모델로 전달하십시오
LLM- >> API : 모델에서 응답을 얻습니다
API- >> 사용자 : 반환 응답