国产在线视频精品视频,国产亚洲精品久久久久久青梅 ,国产麻豆精品一区,国产真实乱对白精彩久久,国产精品视频一区二区三区四

您的位置:教育>正文

天天熱議:基于任何數(shù)據(jù)集創(chuàng)建LLM(Large Language Models)機(jī)器人

來源:Python七號2023-06-28 01:22:06

今天偶然翻到一個倉庫 Embedchain,覺得很實(shí)用,分享給大家。倉庫地址如下:

https://github.com/embedchain/embedchain


(資料圖片)

它是基于 OpenAI 的,但是你可以添加自己的數(shù)據(jù)集,然后生成一個對話機(jī)器人,使用方法簡單,很容易上手。

Embedchain 簡介

Embedchain 是一個可以方便地基于任何數(shù)據(jù)集創(chuàng)建 LLM(Large Language Models)機(jī)器人的框架。它抽象了加載數(shù)據(jù)集、分塊、創(chuàng)建嵌入向量以及存儲在向量數(shù)據(jù)庫中的整個過程。你可以使用.add和.add_local函數(shù)添加單個或多個數(shù)據(jù)集,然后使用.query函數(shù)從添加的數(shù)據(jù)集中查找答案。

假如你崇拜一個很厲害的人 - Naval Ravikant,你想把他的知識做成一個對話機(jī)器人,你可以把他的 Youtube 視頻、PDF 書籍、博客文章,以及你提供的一個問題和答案對,添加到 Embedchain,Embedchain 將為你創(chuàng)建一個機(jī)器人。這是一個例子:

from embedchain import Appnaval_chat_bot = App()# 嵌入在線資源naval_chat_bot.add("youtube_video", "https://www.youtube.com/watch?v=3qHkcs3kG44")naval_chat_bot.add("pdf_file", "https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf")naval_chat_bot.add("web_page", "https://nav.al/feedback")naval_chat_bot.add("web_page", "https://nav.al/agi")# 嵌入本地資源naval_chat_bot.add_local("qna_pair", ("Who is Naval Ravikant?", "Naval Ravikant is an Indian-American entrepreneur and investor."))naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?")# 答案:Naval 認(rèn)為,人類在理解解釋或概念方面擁有獨(dú)特的能力,這是在這個物理現(xiàn)實(shí)中可能的最大程度。
Embedchain 使用

要開始使用 Embedchain,首先確保你已經(jīng)安裝了該包。如果還沒有安裝,可以使用pip進(jìn)行安裝:

pip install embedchain

Embedchain使用 OpenAI 的嵌入模型創(chuàng)建塊的嵌入,使用 ChatGPT API 作為 LLM,給出相關(guān)文檔的答案。確保你有一個 OpenAI 帳戶和 API 密鑰。如果你沒有 API 密鑰,可以通過訪問此鏈接[1]創(chuàng)建一個。

一旦你有了 API 密鑰,將其設(shè)置在一個名為OPENAI_API_KEY的環(huán)境變量中

import osos.environ["OPENAI_API_KEY"] = "sk-xxxx"

接下來,從 embedchain 中導(dǎo)入App類并使用.add函數(shù)添加任何數(shù)據(jù)集。

from embedchain import Appnaval_chat_bot = App()# 嵌入在線資源naval_chat_bot.add("youtube_video", "https://www.youtube.com/watch?v=3qHkcs3kG44")naval_chat_bot.add("pdf_file", "https://navalmanack.s3.amazonaws.com/Eric-Jorgenson_The-Almanack-of-Naval-Ravikant_Final.pdf")naval_chat_bot.add("web_page", "https://nav.al/feedback")naval_chat_bot.add("web_page", "https://nav.al/agi")# 嵌入本地資源naval_chat_bot.add_local("qna_pair", ("Who is Naval Ravikant?", "Naval Ravikant is an Indian-American entrepreneur and investor."))

如果在你的腳本或應(yīng)用中有任何其他的應(yīng)用實(shí)例,你可以更改導(dǎo)入如下

from embedchain import App as EmbedChainApp# 或者from embedchain import App as ECApp

現(xiàn)在你的應(yīng)用已經(jīng)創(chuàng)建好了??梢允褂?query函數(shù)獲得任何查詢的答案。

print(naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?"))# answer: Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.
支持的格式

支持以下格式:

Youtube 視頻

要將任何 Youtube 視頻添加到你的應(yīng)用中,使用數(shù)據(jù)類型(.add的第一個參數(shù))為youtube_video。例如:

app.add("youtube_video", "a_valid_youtube_url_here")
PDF 文件

要添加任何 PDF 文件,使用數(shù)據(jù)類型為pdf_file。例如:

app.add("pdf_file", "a_valid_url_where_pdf_file_can_be_accessed")

注意,不支持密碼保護(hù)的 PDF。

網(wǎng)頁

要添加任何網(wǎng)頁,使用數(shù)據(jù)類型為web_page。例如:

app.add("web_page", "a_valid_web_page_url")
文本

要提供你自己的文本,使用數(shù)據(jù)類型為text并輸入一個字符串。文本不會被處理,這可以非常多樣化。例如:

app.add_local("text", "Seek wealth, not money or status. Wealth is having assets that earn while you sleep. Money is how we transfer time and wealth. Status is your place in the social hierarchy.")

注意:這在示例中沒有使用,因為在大多數(shù)情況下,你將提供整個段落或文件。

相關(guān)內(nèi)容