前端react如何引入ChatUI实现类似chatgpt智能客服

可以看官网:ChatUI

第一步:

"@chatui/core": "^2.4.2",

第二步:

import React from "react";
import Chat, { Bubble, useMessages } from "@chatui/core";
import { Button, } from 'antd';
import "@chatui/core/dist/index.css";

export default function App() {
    const { messages, appendMsg, setTyping } = useMessages([]);

    const die =
        <div>
            <p>
                俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问俄请问请问请问俄请问请
                问请问俄请问请问请问俄请问
                请问请问俄请问请问请问俄请
                问请问请问
            </p>
            <Button style={{ margin: "5px 40%" }}>
                停止输出
            </Button>
        </div>;

    function handleSend(type, val) {
        if (type === "text" && val.trim()) {
            appendMsg({
                type: "text",
                content: { text: val },
                user: { avatar: 'https://img0.baidu.com/it/u=3097844124,3594311210&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500' },
                position: "right"
            });

            setTyping(true);

            setTimeout(() => {
                appendMsg({
                    type: "text",
                    content: {
                        text: die
                    },
                    position: "left",
                    user: { avatar: 'https://img2.baidu.com/it/u=740800004,2820304439&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500' },
                });
            }, 1000);
        }
    }

    function renderMessageContent(msg) {
        const { content } = msg;
        return <Bubble
            content={content.text}
            user="https://img2.baidu.com/it/u=740800004,2820304439&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"
        />;
    }

    return (
        <Chat
            messages={messages}
            placeholder="请输入提示内容"
            renderMessageContent={renderMessageContent}
            onSend={handleSend}
        />
    );
}




可以参考这几种方法:

前端react如何引入chatgpt实现智能客服_react chatgpt-CSDN博客

React AntDesign 聊天机器人 阿里ChatUI使用-CSDN博客

封装一个丝滑的聊天框组件_react.js_jacoby_fire-华为云开发者联盟

搭建一个AI对话机器人——前端ChatUI使用纪录-CSDN博客

chatui-demo - CodeSandbox

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值