# run_chatbot **Repository Path**: lql_h/run_chatbot ## Basic Information - **Project Name**: run_chatbot - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-12-14 - **Last Updated**: 2024-02-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 跑步知识问答机器人 ### 使用gpt4生成提示词的核心代码 ~~~ from langchain.chat_models import ChatOpenAI from langchain.chains import ConversationChain from langchain.memory import ConversationBufferMemory base_url="***" api_key="***" llm = ChatOpenAI(model_name="gpt-4", temperature=0.5,api_key=api_key,base_url=base_url) conversation = ConversationChain( llm=llm, verbose=True, memory=ConversationBufferMemory() ) message=""" 你是世界顶级的马拉松跑步教练,现在分享跑步经验,请给出针对新手100条实用的跑步经验 每条经验以如下格式给出: [跑步问题] [教练回答] """ conversation.predict(input=message) ======================================================================================= > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Human: 你是世界顶级的马拉松跑步教练,现在分享跑步经验,请给出针对新手100条实用的跑步经验 每条经验以如下格式给出: [跑步问题] [教练回答] AI: 我并非马拉松教练,所以我可能无法提供100条专业的跑步经验。不过,我可以提供一些基于公共知识的跑步建议。以下是其中的一些: [跑步问题] 如何选择合适的跑鞋? [教练回答] 跑鞋应该舒适,有足够的垫脚,适合你的脚形和跑步风格。试试多种品牌和型号,找到最适合你的。 ...... ======================================================================================= conversation.predict(input="继续") ...... ~~~ ### 将生产的提示词导入向量数据库FAISS ~~~ #rundata.txt为生成的提示词后的编辑 with open("rundata.txt",encoding='utf-8') as f: real_estate_sales = f.read() from langchain.text_splitter import CharacterTextSplitter text_splitter = CharacterTextSplitter( separator = r'\d+\.', chunk_size = 100, chunk_overlap = 0, length_function = len, is_separator_regex = True, ) docs = text_splitter.create_documents([real_estate_sales]) from langchain.embeddings.openai import OpenAIEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import FAISS db = FAISS.from_documents(docs, OpenAIEmbeddings()) db.save_local("rundata") ~~~ ### 使用向量数据库FAISS、GPT、gradio 实现跑步知识问答系统 ~~~ FAISS:向量数据库,用于存储跑步知识问答的数据集,根据用户问题匹配FAISS数据库中数据集的相似度并将相似度最高的回答返回给用户 GPT:润色向量数据库的回答 gradio:提供人机交互的界面 ~~~ 跑步问答机器人产生的效果 ![1702516850179](1702516850179.png)