mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-07-15 19:35:07 +08:00
【增加】增加 chat stream 功能(删除、复制、滚动删除、发送消息自动到最下面)
This commit is contained in:
@ -1,15 +1,18 @@
|
||||
import request from '@/config/axios'
|
||||
import {fetchEventSource} from '@microsoft/fetch-event-source';
|
||||
import {getAccessToken} from '@/utils/auth'
|
||||
import {config} from '@/config/axios/config'
|
||||
|
||||
// 聊天VO
|
||||
export interface ChatMessageVO {
|
||||
id: number // 编号
|
||||
id: string // 编号
|
||||
conversationId: string // 会话编号
|
||||
type: string // 消息类型
|
||||
userId: string // 用户编号
|
||||
roleId: string // 角色编号
|
||||
model: number // 模型标志
|
||||
modelId: number // 模型编号
|
||||
content: number // 聊天内容
|
||||
content: string // 聊天内容
|
||||
tokens: number // 消耗 Token 数量
|
||||
createTime: Date // 创建时间
|
||||
}
|
||||
@ -27,11 +30,35 @@ export const ChatMessageApi = {
|
||||
return await request.get({ url: `/ai/chat/message/list-by-conversation-id?conversationId=${conversationId}`})
|
||||
},
|
||||
|
||||
// 发送 send 消息
|
||||
send: async (data: ChatMessageSendVO) => {
|
||||
return await request.post({ url: `/ai/chat/message/send`, data })
|
||||
// 发送 add 消息
|
||||
add: async (data: ChatMessageSendVO) => {
|
||||
return await request.post({ url: `/ai/chat/message/add`, data})
|
||||
},
|
||||
|
||||
// 发送 send 消息
|
||||
send: async (data: ChatMessageSendVO) => {
|
||||
return await request.post({ url: `/ai/chat/message/send`, data})
|
||||
},
|
||||
|
||||
// 发送 send stream 消息
|
||||
sendStream: async (id: string, ctrl, onMessage, onError, onClose) => {
|
||||
const token = getAccessToken()
|
||||
return fetchEventSource(`${ config.base_url}/ai/chat/message/send-stream`, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
openWhenHidden: true,
|
||||
body: JSON.stringify({
|
||||
id: id,
|
||||
}),
|
||||
onmessage: onMessage,
|
||||
onerror:onError,
|
||||
onclose: onClose,
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
},
|
||||
|
||||
// 发送 send 消息
|
||||
delete: async (id: string) => {
|
||||
|
Reference in New Issue
Block a user