收集窗帘相关的数据
可以用gpt生成,也可以用爬虫
图形化界面 gradio
向量数据库 faiss
python代码
import gradio as gr
import random
import timefrom typing import Listfrom langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import FAISS
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAIdef initialize_sales_bot(vector_store_dir: str="real_estates_sale"):db = FAISS.load_local(vector_store_dir, OpenAIEmbeddings())llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)global SALES_BOT SALES_BOT = RetrievalQA.from_chain_type(llm,retriever=db.as_retriever(search_type="similarity_score_threshold",search_kwargs={"score_threshold": 0.8}))# 返回向量数据库的检索结果SALES_BOT.return_source_documents = Truereturn SALES_BOTdef sales_chat(message, history):print(f"[message]{message}")print(f"[history]{history}")# TODO: 从命令行参数中获取enable_chat = Trueans = SALES_BOT({"query": message})# 如果检索出结果,或者开了大模型聊天模式# 返回 RetrievalQA combine_documents_chain 整合的结果if ans["source_documents"] or enable_chat:print(f"[result]{ans['result']}")print(f"[source_documents]{ans['source_documents']}")return ans["result"]# 否则输出套路话术else:return "这个问题我要问问领导"def launch_gradio():demo = gr.ChatInterface(fn=sales_chat,title="窗帘销售",# retry_btn=None,# undo_btn=None,chatbot=gr.Chatbot(height=600),)demo.launch()if __name__ == "__main__":# 初始化房产销售机器人initialize_sales_bot()# 启动 Gradio 服务launch_gradio()
最中结果如下: