聊天机器人

收集窗帘相关的数据

可以用gpt生成,也可以用爬虫

图形化界面 gradio

向量数据库 faiss

python代码

python 复制代码
import gradio as gr
import random
import time

from typing import List

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import FAISS
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI


def 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 = True

    return SALES_BOT

def sales_chat(message, history):
    print(f"[message]{message}")
    print(f"[history]{history}")
    # TODO: 从命令行参数中获取
    enable_chat = True

    ans = 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()

最中结果如下:

相关推荐
视觉语言导航7 分钟前
基于视觉语言模型的机器人实时探索系统!ClipRover:移动机器人零样本视觉语言探索和目标发现
人工智能·机器人·具身智能
WLJT12312312314 分钟前
机器人智能设备:未来生活的新篇章
机器人·生活
Wnq1007213 小时前
论伺服电机在轨道式巡检机器人中的优势及应用实践
机器人·驱动·伺服电机·巡检机器人·北京玉麟科技·轨道式巡检机器人·防爆巡检机器人
Abcdsa14 小时前
柔性关节双臂机器人奇异摄动鲁棒自适应PD控制
机器人
视觉人机器视觉16 小时前
MV-DLS1400P激光振镜立体相机(MV-DLS1400P)重要参数解析
大数据·人工智能·数码相机·机器人·c#·汽车
慧通测控20 小时前
新的“估值锚点”:慧通测控人形(协作)机器人多任务并行
机器人
cosX+sinY21 小时前
ubuntu 20.04 复现 LVI-SAM
linux·ubuntu·机器人·bash
Mr.Winter`1 天前
运动规划实战案例 | 基于四叉树分解的路径规划(附ROS C++/Python仿真)
人工智能·机器人·自动驾驶·ros·计算机图形学·ros2·路径规划
资讯分享周2 天前
智谛达科技:以创新为翼,翱翔AI人形机器人蓝海
人工智能·科技·机器人
tinker2 天前
OSX M1 平台 gazebo 安装记录(失败)
机器人