更新记录
1.0.0(2024-11-10)
下载此版本
1.0.0 完成。
支持浏览器、安卓、ios
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
app-vue |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
√ |
× |
√ |
√ |
√ |
sse 客户端组件,支持v2、v3、安卓、ios、浏览器
使用说明
安装 @microsoft/fetch-event-source
本插件依赖 @microsoft/fetch-event-source,使用必须安装
npm i @microsoft/fetch-event-source
示例代码
<template>
<ChatSSEClient
ref="chatSSEClientRef"
@onOpen="openCore"
@onError="errorCore"
@onMessage="messageCore"
@onFinish="finishCore"
/>
<button @click="start">开始</button>
<button @click="stop">停止</button>
<template v-if="loading">
<view>{{ openLoading ? "正在连接sse..." : '连接完成!' }}</view>
<view>{{ loading ? "加载中..." : '' }}</view>
</template>
<view>
{{ responseText }}
</view>
</template>
<script setup>
import ChatSSEClient from "@/components/ChatSSEClient.vue";
import { ref } from 'vue'
const chatSSEClientRef = ref(null);
const responseText = ref("");
const loading = ref(false);
const openLoading = ref(false);
const openCore = () => {
openLoading.value = false;
console.log("open sse");
}
const errorCore = (err) => {
console.log("error sse:", err);
}
const messageCore = (msg) => {
console.log("message sse:", msg);
responseText.value += `${msg}\n`
}
const finishCore = () => {
console.log("finish sse")
loading.value = false;
}
const start = () => {
if (loading.value) return;
openLoading.value = true;
loading.value = true;
responseText.value = "";
chatSSEClientRef.value.startChat({
// 将它换成你的地址
url: "",
headers: {
authorization: "",
},
body: {
"messages":[
{ "role":"user", "content": "你好!" }
],
"stream":true,
"model":"deepseek-chat",
"temperature":1,
"presence_penalty":0,
"frequency_penalty":0,
"top_p":1
},
})
}
const stop = () => {
chatSSEClientRef.value.stopChat()
console.log("stop");
}
</script>