国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

基于GPT-4和LangChain構(gòu)建云端定制化PDF知識庫AI聊天機器人

這篇具有很好參考價值的文章主要介紹了基于GPT-4和LangChain構(gòu)建云端定制化PDF知識庫AI聊天機器人。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

參考:

GitHub - mayooear/gpt4-pdf-chatbot-langchain: GPT4 & LangChain Chatbot for large PDF docs

1.摘要:

使用新的GPT-4 api為多個大型PDF文件構(gòu)建chatGPT聊天機器人。

使用的技術(shù)棧包括LangChain, Pinecone, Typescript, Openai和Next.js。LangChain是一個框架,可以更容易地構(gòu)建可擴展的AI/LLM大語言模型應(yīng)用程序和聊天機器人。Pinecone是一個矢量存儲,用于存儲嵌入和文本格式的PDF,以便以后檢索類似的文檔。

2.準備工作:

OpenAI API Key GPT-3.5或者GPT-4?openai?

Pinecone API Key/Environment/Index??pinecone

Pinecone Starter(免費)計劃用戶的Index在7天后被刪除。為了防止這種情況,在7天之前向Pinecone發(fā)送API請求重置計數(shù)器。就可以繼續(xù)免費使用了。

基于GPT-4和LangChain構(gòu)建云端定制化PDF知識庫AI聊天機器人,隨筆,langchain,pdf

3.克隆或下載項目gpt4-pdf-chatbot-langchain

git clone https://github.com/mayooear/gpt4-pdf-chatbot-langchain.git

4.安裝依賴包

使用npm安裝yarn,如果沒有npm,參考安裝?

npm/Node.js介紹及快速安裝 - Linux CentOS_Entropy-Go的博客-CSDN博客

npm install yarn -g

?再使用yarn安裝依賴包

?進入項目根目錄,執(zhí)行命令

yarn install

安裝成功后,可以看到?node_modules 目錄

gpt4-pdf-chatbot-langchain-main$ ls -a
.           declarations  .eslintrc.json  node_modules        .prettierrc  styles               utils           yarn.lock
..          docs          .gitignore      package.json        public       tailwind.config.cjs  venv
components  .env          .idea           pages               README.md    tsconfig.json        visual-guide
config      .env.example  next.config.js  postcss.config.cjs  scripts      types                yarn-error.log

5.環(huán)境配置

將.env.example復(fù)制成.env配置文件

OPENAI_API_KEY=sk-xxx

# Update these with your pinecone details from your dashboard.
# PINECONE_INDEX_NAME is in the indexes tab under "index name" in blue
# PINECONE_ENVIRONMENT is in indexes tab under "Environment". Example: "us-east1-gcp"
PINECONE_API_KEY=xxx
PINECONE_ENVIRONMENT=us-west1-gcp-free
PINECONE_INDEX_NAME=xxx

config/pinecone.ts修改

在config文件夾中,將PINECONE_NAME_SPACE替換為一個namespace,當(dāng)你運行npm run ingest時,你想在這個namespace中存儲嵌入到PINECONE_NAME_SPACE。這個namespace稍后將用于查詢和檢索。

修改聊天機器人的提示詞和OpenAI模型

utils/makechain.ts中為您自己的用例更改QA_PROMPT。

如果您可以訪問gpt-4 api,請將新OpenAI中的modelName更改為gpt-4。請在此repo之外驗證您是否可以訪問gpt-4 api,否則應(yīng)用程序?qū)o法工作。

import { OpenAI } from 'langchain/llms/openai';
import { PineconeStore } from 'langchain/vectorstores/pinecone';
import { ConversationalRetrievalQAChain } from 'langchain/chains';

const CONDENSE_PROMPT = `Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.

Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:`;

const QA_PROMPT = `You are a helpful AI assistant. Use the following pieces of context to answer the question at the end.
If you don't know the answer, just say you don't know. DO NOT try to make up an answer.
If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.

{context}

Question: {question}
Helpful answer in markdown:`;

export const makeChain = (vectorstore: PineconeStore) => {
  const model = new OpenAI({
    temperature: 0, // increase temepreature to get more creative answers
    modelName: 'gpt-3.5-turbo', //change this to gpt-4 if you have access
  });

  const chain = ConversationalRetrievalQAChain.fromLLM(
    model,
    vectorstore.asRetriever(),
    {
      qaTemplate: QA_PROMPT,
      questionGeneratorTemplate: CONDENSE_PROMPT,
      returnSourceDocuments: true, //The number of source documents returned is 4 by default
    },
  );
  return chain;
};

6.添加PDF文檔為知識庫

因為會和OpenAI和Pinecone有數(shù)據(jù)交互,建議上傳文檔之前,慎重考慮數(shù)據(jù)隱私和安全。

將1個或多個PDF文檔上傳到 docs 目錄下

執(zhí)行上傳命令

npm run ingest

在Pinecone上檢查是否上傳成功

7.運行知識庫聊天機器人

當(dāng)你驗證了嵌入和內(nèi)容已經(jīng)成功地添加到你的Pinecone中,你可以運行應(yīng)用程序npm run dev來啟動本地開發(fā)環(huán)境,然后在聊天界面中輸入一個問題,進行對話。

執(zhí)行命令:

npm run dev

8.常見問題Troubleshooting

https://github.com/mayooear/gpt4-pdf-chatbot-langchain#troubleshooting

In general, keep an eye out in the?issues?and?discussions?section of this repo for solutions.

General errors

  • Make sure you're running the latest Node version. Run?node -v
  • Try a different PDF or convert your PDF to text first. It's possible your PDF is corrupted, scanned, or requires OCR to convert to text.
  • Console.log?the?env?variables and make sure they are exposed.
  • Make sure you're using the same versions of LangChain and Pinecone as this repo.
  • Check that you've created an?.env?file that contains your valid (and working) API keys, environment and index name.
  • If you change?modelName?in?OpenAI, make sure you have access to the api for the appropriate model.
  • Make sure you have enough OpenAI credits and a valid card on your billings account.
  • Check that you don't have multiple OPENAPI keys in your global environment. If you do, the local?env?file from the project will be overwritten by systems?env?variable.
  • Try to hard code your API keys into the?process.env?variables if there are still issues.

Pinecone errors文章來源地址http://www.zghlxwxcb.cn/news/detail-669632.html

  • Make sure your pinecone dashboard?environment?and?index?matches the one in the?pinecone.ts?and?.env?files.
  • Check that you've set the vector dimensions to?1536.
  • Make sure your pinecone namespace is in lowercase.
  • Pinecone indexes of users on the Starter(free) plan are deleted after 7 days of inactivity. To prevent this, send an API request to Pinecone to reset the counter before 7 days.
  • Retry from scratch with a new Pinecone project, index, and cloned repo.

到了這里,關(guān)于基于GPT-4和LangChain構(gòu)建云端定制化PDF知識庫AI聊天機器人的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • LLM本地知識庫問答系統(tǒng)(一):使用LangChain和LlamaIndex從零構(gòu)建PDF聊天機器人指南

    LLM本地知識庫問答系統(tǒng)(一):使用LangChain和LlamaIndex從零構(gòu)建PDF聊天機器人指南

    ? ? ? ?隨著大型語言模型(LLM)(如ChatGPT和GPT-4)的興起,現(xiàn)在比以往任何時候都更容易構(gòu)建比普通熊更智能的智能聊天機器人,并且可以瀏覽堆積如山的文檔,為您的輸入提供準確的響應(yīng)。 ? ? ? ?在本系列中,我們將探索如何使用pre-trained的LLM創(chuàng)建一個聊天機器人,該聊

    2024年02月11日
    瀏覽(100)
  • 基于Langchain+向量數(shù)據(jù)庫+ChatGPT構(gòu)建企業(yè)級知識庫

    基于Langchain+向量數(shù)據(jù)庫+ChatGPT構(gòu)建企業(yè)級知識庫

    ▼最近直播超級多, 預(yù)約 保你有收獲 近期直播: 《 基于 LLM 大模型的向量數(shù)據(jù)庫企業(yè)級應(yīng)用實踐 》 ?1 — LangChain 是什么? 眾所周知 OpenAI 的 API 無法聯(lián)網(wǎng)的,所以如果只使用自己的功能實現(xiàn)聯(lián)網(wǎng)搜索并給出回答、總結(jié) PDF 文檔、基于某個 Youtube 視頻進行問答等等的功能肯定

    2024年02月06日
    瀏覽(25)
  • Quivr 基于GPT和開源LLMs構(gòu)建本地知識庫 (更新篇)

    Quivr 基于GPT和開源LLMs構(gòu)建本地知識庫 (更新篇)

    自從大模型被炒的越來越火之后,似乎國內(nèi)涌現(xiàn)出很多希望基于大模型構(gòu)建本地知識庫的需求,大概在5月底的時候,當(dāng)時Quivr發(fā)布了第一個0.0.1版本,第一個版本僅僅只是使用LangChain技術(shù)結(jié)合OpenAI的GPT模型實現(xiàn)了一個最基本的架子,功能并不夠完善,但可以研究研究思路,當(dāng)

    2024年02月12日
    瀏覽(25)
  • GPT實戰(zhàn)系列-簡單聊聊LangChain搭建本地知識庫準備

    GPT實戰(zhàn)系列-簡單聊聊LangChain搭建本地知識庫準備

    LangChain 是一個開發(fā)由語言模型驅(qū)動的應(yīng)用程序的框架,除了和應(yīng)用程序通過 API 調(diào)用, 還會: 數(shù)據(jù)感知 : 將語言模型連接到其他數(shù)據(jù)源 具有代理性質(zhì) : 允許語言模型與其環(huán)境交互 LLM大模型相關(guān)文章: GPT實戰(zhàn)系列-簡單聊聊LangChain GPT實戰(zhàn)系列-ChatGLM3本地部署CUDA11+1080Ti+顯卡

    2024年02月01日
    瀏覽(22)
  • LangChain入門(四)-構(gòu)建本地知識庫問答機器人

    LangChain入門(四)-構(gòu)建本地知識庫問答機器人

    在這個例子中,我們會介紹如何從我們本地讀取多個文檔構(gòu)建知識庫,并且使用 Openai API 在知識庫中進行搜索并給出答案。 目錄 一、安裝向量數(shù)據(jù)庫chromadb和tiktoken 二、使用案例 三、embeddings持久化 四、在線的向量數(shù)據(jù)庫Pinecone 一、安裝向量數(shù)據(jù)庫chromadb和tiktoken ?? 其中h

    2024年02月05日
    瀏覽(102)
  • GPT-Crawler一鍵爬蟲構(gòu)建GPTs知識庫

    GPT-Crawler一鍵爬蟲構(gòu)建GPTs知識庫

    GPT-Crawler一鍵爬蟲構(gòu)建GPTs知識庫 能夠爬取網(wǎng)站數(shù)據(jù),構(gòu)建GPTs的知識庫,項目依賴node.js環(huán)境,接下來我們按步驟來安裝,非常簡單 參考:https://zhuanlan.zhihu.com/p/668700619 在信息爆炸的時代,數(shù)據(jù)成為了新的石油。但是,如何有效地從這無窮無盡的網(wǎng)絡(luò)信息中提取有價值的知識,

    2024年02月04日
    瀏覽(25)
  • 基于 InternLM 和 LangChain 搭建你的知識庫

    基于 InternLM 和 LangChain 搭建你的知識庫

    如何打造垂域大模型是一個重要落地方向。 如何打造個人專屬的大模型應(yīng)用也是重要的問題。 RAG 外掛一個知識庫 優(yōu)勢:成本低,實時更新 劣勢:能力受基座模型影響大,RAG每次需要將檢索文檔和問題提交給大模型,極大占用上下文限制。 Finetune 輕量級的微調(diào) 優(yōu)勢:可以充

    2024年01月19日
    瀏覽(19)
  • AnythingLLM:基于RAG方案構(gòu)專屬私有知識庫(開源|高效|可定制)

    AnythingLLM:基于RAG方案構(gòu)專屬私有知識庫(開源|高效|可定制)

    繼OpenAI和Google的產(chǎn)品發(fā)布會之后,大模型的能力進化速度之快令人驚嘆,然而,對于很多個人和企業(yè)而言,為了數(shù)據(jù)安全不得不考慮私有化部署方案,從GPT-4發(fā)布以來,國內(nèi)外的大模型就拉開了很明顯的差距,能夠?qū)崿F(xiàn)的此路徑無非就只剩下國內(nèi)的開源大模型可以選擇了。而

    2024年02月04日
    瀏覽(23)
  • 【基于 InternLM 和 LangChain 搭建你的知識庫】學(xué)習(xí)筆記

    【基于 InternLM 和 LangChain 搭建你的知識庫】學(xué)習(xí)筆記

    學(xué)習(xí)參考文檔【基于 InternLM 和 LangChain 搭建你的知識庫】 學(xué)習(xí)參考鏈接【書生?浦語大模型實戰(zhàn)營第三課作業(yè)(基礎(chǔ)+進階)】 收集2018年-2020年幾年間的優(yōu)秀數(shù)學(xué)建模論文 LangChain 相關(guān)環(huán)境配置 下載 NLTK 相關(guān)資源 下載相關(guān)倉庫 腳本文件 Web Demo部署

    2024年02月01日
    瀏覽(24)
  • Chinese-LangChain:基于ChatGLM-6b+langchain實現(xiàn)本地化知識庫檢索與智能答案生成

    Chinese-LangChain:基于ChatGLM-6b+langchain實現(xiàn)本地化知識庫檢索與智能答案生成

    Chinese-LangChain:中文langchain項目,基于ChatGLM-6b+langchain實現(xiàn)本地化知識庫檢索與智能答案生成 https://github.com/yanqiangmiffy/Chinese-LangChain 俗稱:小必應(yīng),Q.Talk,強聊,QiangTalk ?? 2023/04/19 引入ChuanhuChatGPT皮膚 ?? 2023/04/19 增加web search功能,需要確保網(wǎng)絡(luò)暢通! ?? 2023/04/18 webui增加知

    2024年02月06日
    瀏覽(33)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包