gpt4 book ai didi

python - 使用 ChatGPT API 仅使用自定义知识而非一般知识来训练聊天机器人

转载 作者:行者123 更新时间:2023-12-02 22:47:29 26 4
gpt4 key购买 nike

所以现在我正在使用 ChatGPT API 在 Python 中编写一个聊天机器人,我遇到的问题是我希望聊天机器人只具有将从 PDF 文件训练的自定义知识,而不是一般知识。

所以我用来嵌入PDF文件的函数如下:

# Function to embed the text
def get_vectorstore(text_chunks, api_key):
embeddings = OpenAIEmbeddings(openai_api_key=api_key)
vectorstore = FAISS.from_texts(text_chunks, embedding=embeddings)
return vectorstore

我用来训练聊天机器人的代码如下?

# Train the bot with the PDF information
def get_conversation_chain(vectorstore, api_key):
llm = ChatOpenAI(openai_api_key=api_key)
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
conversation_chain = ConversationalRetrievalChain.from_llm(
llm = llm,
retriever = vectorstore.as_retriever(),
memory = memory
)
return conversation_chain

关于如何仅使用自定义知识训练聊天机器人有什么想法吗?

提前致谢!

最佳答案

使用 ChatGPT 将任何 PDF 或文档转换为功能齐全的聊天机器人可能无法直接开箱即用。但是,您可以遵循结构化流程,结合使用工具和技术来实现此转换。检查这个link获取所有信息

关于python - 使用 ChatGPT API 仅使用自定义知识而非一般知识来训练聊天机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76775748/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com