【增加】AI 配置 Chat角色

pull/449/head^2
cherishsince 2024-05-16 00:18:29 +08:00
parent 9658af7c04
commit f14032d69d
3 changed files with 21 additions and 11 deletions

View File

@ -5,8 +5,8 @@ import { config } from '@/config/axios/config'
// 聊天VO // 聊天VO
export interface ChatMessageVO { export interface ChatMessageVO {
id: string // 编号 id: number // 编号
conversationId: string // 会话编号 conversationId: number // 会话编号
type: string // 消息类型 type: string // 消息类型
userId: string // 用户编号 userId: string // 用户编号
roleId: string // 角色编号 roleId: string // 角色编号
@ -25,7 +25,7 @@ export interface ChatMessageSendVO {
// AI chat 聊天 // AI chat 聊天
export const ChatMessageApi = { export const ChatMessageApi = {
// 消息列表 // 消息列表
messageList: async (conversationId: string) => { messageList: async (conversationId: number) => {
return await request.get({ return await request.get({
url: `/ai/chat/message/list-by-conversation-id?conversationId=${conversationId}` url: `/ai/chat/message/list-by-conversation-id?conversationId=${conversationId}`
}) })

View File

@ -199,7 +199,7 @@ import { marked } from 'marked'
// https://highlightjs.org/ // https://highlightjs.org/
import 'highlight.js/styles/vs2015.min.css' import 'highlight.js/styles/vs2015.min.css'
import hljs from 'highlight.js' import hljs from 'highlight.js'
const route = useRoute() //
const message = useMessage() // const message = useMessage() //
// //
@ -220,7 +220,7 @@ const { copy } = useClipboard()
const searchName = ref('') // const searchName = ref('') //
const inputTimeout = ref<any>() // const inputTimeout = ref<any>() //
const conversationId = ref(0) // const conversationId = ref<number>(-1) //
const conversationInProgress = ref(false) // const conversationInProgress = ref(false) //
const conversationInAbortController = ref<any>() // abort ( stream ) const conversationInAbortController = ref<any>() // abort ( stream )
@ -297,7 +297,7 @@ const onSend = async () => {
if (conversationInProgress.value) { if (conversationInProgress.value) {
return return
} }
const content = prompt.value?.trim() const content = prompt.value?.trim() + ''
if (content.length < 2) { if (content.length < 2) {
ElMessage({ ElMessage({
message: '请输入内容!', message: '请输入内容!',
@ -316,7 +316,7 @@ const onSend = async () => {
const userMessage = { const userMessage = {
conversationId: conversationId.value, conversationId: conversationId.value,
content: content content: content
} } as ChatMessageVO
// list.value.push(userMessage) // list.value.push(userMessage)
// // // //
// scrollToBottom() // scrollToBottom()
@ -387,6 +387,9 @@ const doSendStream = async (userMessage: ChatMessageVO) => {
/** 查询列表 */ /** 查询列表 */
const messageList = async () => { const messageList = async () => {
try { try {
if (!conversationId.value) {
return
}
// //
const res = await ChatMessageApi.messageList(conversationId.value) const res = await ChatMessageApi.messageList(conversationId.value)
@ -504,7 +507,7 @@ const onPromptInput = (event) => {
}, 400) }, 400)
} }
const getConversation = async (conversationId: string) => { const getConversation = async (conversationId: number) => {
// //
useConversation.value = await ChatConversationApi.getChatConversationMy(conversationId) useConversation.value = await ChatConversationApi.getChatConversationMy(conversationId)
console.log('useConversation.value', useConversation.value) console.log('useConversation.value', useConversation.value)
@ -527,12 +530,16 @@ const getChatConversationList = async () => {
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
//
if (route.query.conversationId) {
conversationId.value = route.query.conversationId as number
}
// //
await getChatConversationList() await getChatConversationList()
// //
getConversation(conversationId.value) await getConversation(conversationId.value)
// //
messageList() await messageList()
// scrollToBottom(); // scrollToBottom();
// await nextTick // await nextTick
// //

View File

@ -149,7 +149,10 @@ const handlerCardUse = async (role) => {
const conversation = await ChatConversationApi.createChatConversationMy(data) const conversation = await ChatConversationApi.createChatConversationMy(data)
// //
router.push({ router.push({
path: `/ai/chat/index?conversationId=${conversation.id}` path: `/ai/chat/index`,
query: {
conversationId: conversation,
}
}) })
} }