embedchain 是一個框架,可以在任何資料集上輕鬆創建 LLM 支援的機器人。 embedchainjs 是 embedchain 的 Javascript 版本。如果你想要 python 版本,請查看 embedchain-python
與創辦人 Taranjeet 安排回饋會議,討論任何問題、提供回饋或探索改進。
它抽象化了載入資料集、分塊、建立嵌入然後儲存在向量資料庫中的整個過程。
您可以使用.add
和.addLocal
函數新增單一或多個資料集,然後使用.query
函數從新增的資料集中尋找答案。
如果您想創建一個 Naval Ravikant 機器人,其中包含 2 篇部落格文章以及您提供的問答對,您所需要做的就是將連結添加到部落格文章中,QnA 對和嵌入鏈將創建一個為您服務的機器人。
const dotenv = require ( "dotenv" ) ;
dotenv . config ( ) ;
const { App } = require ( "embedchain" ) ;
//Run the app commands inside an async function only
async function testApp ( ) {
const navalChatBot = await App ( ) ;
// Embed Online Resources
await navalChatBot . add ( "web_page" , "https://nav.al/feedback" ) ;
await navalChatBot . add ( "web_page" , "https://nav.al/agi" ) ;
await navalChatBot . add (
"pdf_file" ,
"https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf"
) ;
// Embed Local Resources
await navalChatBot . addLocal ( "qna_pair" , [
"Who is Naval Ravikant?" ,
"Naval Ravikant is an Indian-American entrepreneur and investor." ,
] ) ;
const result = await navalChatBot . query (
"What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?"
) ;
console . log ( result ) ;
// answer: Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.
}
testApp ( ) ;
npm
安裝npm install embedchain && npm install -S openai@^3.3.0
目前僅相容openai 3.X,不相容於最新版本4.X。請確保使用正確的版本,否則您將看到ChromaDB
錯誤TypeError: OpenAIApi.Configuration is not a constructor
確保已安裝 dotenv 軟體包,並且您的OPENAI_API_KEY
位於根資料夾中名為.env
的檔案中。您可以透過以下方式安裝 dotenv
npm install dotenv
造訪此連結在您的裝置上下載並安裝 Docker。您將需要它來在您的電腦上運行 Chroma 向量資料庫。
執行以下命令在 Docker 中設定 Chroma 容器
git clone https://github.com/chroma-core/chroma.git
cd chroma
docker-compose up -d --build
我們使用 OpenAI 的嵌入模型為區塊建立嵌入,並使用 ChatGPT API 作為 LLM 來取得給定相關文件的答案。確保您擁有 OpenAI 帳戶和 API 金鑰。如果您沒有 API 金鑰,可以透過造訪此連結建立一個。
取得 API 金鑰後,將其設定在名為OPENAI_API_KEY
的環境變數中
// Set this inside your .env file
OPENAI_API_KEY = "sk-xxxx" ;
const dotenv = require ( "dotenv" ) ;
dotenv . config ( ) ;
App
類別並使用.add
函數新增任何資料集。.query
函數來取得任何查詢的答案。 const dotenv = require ( "dotenv" ) ;
dotenv . config ( ) ;
const { App } = require ( "embedchain" ) ;
async function testApp ( ) {
const navalChatBot = await App ( ) ;
// Embed Online Resources
await navalChatBot . add ( "web_page" , "https://nav.al/feedback" ) ;
await navalChatBot . add ( "web_page" , "https://nav.al/agi" ) ;
await navalChatBot . add (
"pdf_file" ,
"https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf"
) ;
// Embed Local Resources
await navalChatBot . addLocal ( "qna_pair" , [
"Who is Naval Ravikant?" ,
"Naval Ravikant is an Indian-American entrepreneur and investor." ,
] ) ;
const result = await navalChatBot . query (
"What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?"
) ;
console . log ( result ) ;
// answer: Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.
}
testApp ( ) ;
const { App : EmbedChainApp } = require ( "embedchain" ) ;
// or
const { App : ECApp } = require ( "embedchain" ) ;
我們支援以下格式:
若要新增任何 pdf 文件,請使用 data_type 作為pdf_file
。例如:
await app . add ( "pdf_file" , "a_valid_url_where_pdf_file_can_be_accessed" ) ;
若要新增任何網頁,請使用 data_type 作為web_page
。例如:
await app . add ( "web_page" , "a_valid_web_page_url" ) ;
要提供您自己的 QnA 對,請使用 data_type 作為qna_pair
並輸入一個元組。例如:
await app . addLocal ( "qna_pair" , [ "Question" , "Answer" ] ) ;
在使用有價值的令牌之前,您應該確保您所做的嵌入有效並且它從資料庫接收正確的文件。
為此,您可以使用dryRun
方法。
按照上面的範例,將其添加到您的腳本中:
let result = await naval_chat_bot . dryRun ( "What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?" ) ; console . log ( result ) ;
'' '
Use the following pieces of context to answer the query 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 .
terms of the unseen . And I think that’s critical . That is what humans do uniquely that no other creature , no other computer , no other intelligence—biological or artificial—that we have ever encountered does . And not only do we do it uniquely , but if we were to meet an alien species that also had the power to generate these good explanations , there is no explanation that they could generate that we could not understand . We are maximally capable of understanding . There is no concept out there that is possible in this physical reality that a human being , given sufficient time and resources and
Query : What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts ?
Helpful Answer :
'' '
確認嵌入按預期工作。即使提出的問題略有不同,它也會傳回正確的文件。沒有消耗任何提示令牌。
試運行仍然會消耗令牌來嵌入您的查詢,但它只是提示的〜1/15。
在任何資料集上建立聊天機器人需要執行以下步驟
每當用戶提出任何查詢時,都會發生以下過程來找到查詢的答案
載入資料集然後查詢的過程涉及多個步驟,每個步驟都有自己的細微差別。
這些問題對某些人來說可能微不足道,但對我們許多人來說,需要研究、實驗和時間才能找到準確的答案。
embedchain 是一個框架,可以處理所有這些細微差別,並提供一個簡單的介面來在任何資料集上建立機器人。
在第一個版本中,我們讓任何人都可以更輕鬆地在不到一分鐘的時間內就任何資料集啟動並運行聊天機器人。您需要做的就是建立一個應用程式實例,使用.add
函數新增資料集,然後使用.query
函數來取得相關答案。
embedchain 建構在以下堆疊之上:
如果您使用此存儲庫,請考慮使用以下方式引用它:
@misc{embedchain,
author = {Taranjeet Singh},
title = {Embechain: Framework to easily create LLM powered bots over any dataset},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {url{https://github.com/embedchain/embedchainjs}},
}