我的 Langchain 聊天机器人遇到问题
通过更新代码帮助我找到解决方案 它显示此错误:模型
text-davinci-003
已被弃用,在此处了解更多信息:https://platform.openai.com/docs/deprecations
请修复我的代码。
有关更多信息,我使用此视频创建了此项目:https://youtu.be/wUAUdEw5oxM?si=NbRXJsSLfjpIgHzR
import os
from apikey import apikey
import streamlit as st
from PyPDF2 import PdfReader
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import FAISS
from langchain.llms import OpenAI
from langchain.chains.question_answering import load_qa_chain
os.environ['OPENAI_API_KEY']=apikey
def main():
print('hello world')
st.set_page_config(page_title='Chat Bot 🛠📋')
st.header('ChatBot 🛠📋 For Mechanical Department')
#UPLOADING THE FILE
pdf=st.file_uploader('Upload your PDF',type='pdf')
#READING THE FILE
if pdf is not None:
pdf_reader=PdfReader(pdf)
text=''
for page in pdf_reader.pages:
text+=page.extract_text()
#SPLIT INTO CHUNCK
text_splitter=CharacterTextSplitter(
separator="\n",
chunk_size=1000,
chunk_overlap=200,
length_function=len
)
chunks=text_splitter.split_text(text)
#CREATE EMBEDDINGS
embeddings=OpenAIEmbeddings()
knowledge_base=FAISS.from_texts(chunks, embeddings)
#SHOW USER INPUT
user_questions=st.text_input("Ask question")
if user_questions:
docs = knowledge_base.similarity_search(user_questions)
#ASWERING THE QUESTION
llm=OpenAI() #language model
chain = load_qa_chain(llm, chain_type="stuff")
response=chain.run(input_documents=docs, question=user_questions)
st.write(response)
if __name__=='__main__':
main()
langchain-openai
from langchain.embeddings.openai import OpenAIEmbeddings
与
from langchain_openai import OpenAIEmbeddings