更新记录
1.1.2(2025-01-02)
网络不通失败时,重置内部状态
1.1.1(2024-12-31)
响应回调放到ui线程
1.1.0(2024-12-31)
修复close触发之后client的状态没有重置的问题
查看更多平台兼容性
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | 5.0 | × | × | × |
uminitech-sse
价格和示例仅供参考,有问题和需求私信我
开发文档
import * as UminitechSSE from '@/uni_modules/uminitech-sse'
import type { SSEOptions } from '@/uni_modules/uminitech-sse'
// 订阅
subscribeToSSE() {
if (this.sseClient == null) {
// 创建一个新的Client
this.sseClient = UminitechSSE.createSSEClient()
}
let input = {
"model": "gpt-4o-mini",
"messages": [{
"role": "user",
"content": "写一个冒泡算法"
}],
"temperature": 0.7,
"stream": true
}
let header = {
"Content-Type": "application/json",
"Authorization": "Bearer sk-xxx"
}
// 订阅到this.sseClient
UminitechSSE.subscribeToSSEClient(this.sseClient!,{
url: 'https://open.xxxx.com/v1/chat/completions',
method: "POST",
body: JSON.stringify(input),
header: header,
onOpen: (response: string) => {
console.log(response)
},
onMessage: (message: string) => {
console.log(message)
},
onError: (error: string) => {
console.log(error)
},
onClose: () => {
}
} as SSEOptions)
}
// 取消
cancelSSESubscribe() {
UminitechSSE.cancel(this.sseClient!)
},