【新增】AI:聊天更新的窗口

pull/449/head^2
YunaiV 2024-05-15 13:00:31 +08:00
parent ebd593bf92
commit bd5262e21d
6 changed files with 156 additions and 36 deletions

View File

@ -20,12 +20,12 @@ export interface ChatConversationVO {
// AI 聊天会话 API
export const ChatConversationApi = {
// 获取 Conversation
get: async (id: string) => {
return await request.get({ url: `/ai/chat/conversation/get?id=${id}` })
// 获得【我的】聊天会话
getChatConversationMy: async (id: string) => {
return await request.get({ url: `/ai/chat/conversation/get-my?id=${id}` })
},
// 更新 Conversation
updateConversationMy: async (data: ChatConversationVO) => {
// 更新【我的】聊天会话
updateChatConversationMy: async (data: ChatConversationVO) => {
return await request.put({ url: `/ai/chat/conversation/update-my`, data })
},

View File

@ -9,8 +9,7 @@ export interface ChatRoleVO {
category: string // 角色类别
sort: number // 角色排序
description: string // 角色描述
welcomeMessage: string // 角色欢迎语
systemMessage: string // 角色上下文
systemMessage: string // 角色设定
publicStatus: boolean // 是否公开
status: number // 状态
}

View File

@ -0,0 +1,124 @@
<template>
<Dialog title="设定" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="角色设定" prop="systemContext">
<el-input type="textarea" v-model="formData.systemContext" placeholder="请输入角色设定" />
</el-form-item>
<el-form-item label="模型" prop="modelId">
<UploadImg v-model="formData.modelId" />
</el-form-item>
<el-form-item label="上下文数量" prop="category">
<el-input v-model="formData.category" placeholder="请输入角色类别" />
</el-form-item>
<el-form-item label="话题随机性" prop="description">
<el-input type="textarea" v-model="formData.description" placeholder="请输入角色描述" />
</el-form-item>
<el-form-item label="回复数" prop="systemMessage">
<el-input type="textarea" v-model="formData.systemMessage" placeholder="请输入角色设定" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { ChatRoleApi, ChatRoleVO } from '@/api/ai/model/chatRole'
import { CommonStatusEnum } from '@/utils/constants'
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
/** AI 聊天角色 表单 */
defineOptions({ name: 'ChatConversationUpdateForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
systemContext: undefined,
modelId: undefined,
name: undefined,
avatar: undefined,
category: undefined,
sort: undefined,
description: undefined,
systemMessage: undefined,
publicStatus: true,
status: CommonStatusEnum.ENABLE
})
const formRules = reactive({
name: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }],
avatar: [{ required: true, message: '角色头像不能为空', trigger: 'blur' }],
category: [{ required: true, message: '角色类别不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '角色排序不能为空', trigger: 'blur' }],
description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }],
systemMessage: [{ required: true, message: '角色设定不能为空', trigger: 'blur' }],
publicStatus: [{ required: true, message: '是否公开不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const chatModelList = ref([] as ChatModelVO[]) //
/** 打开弹窗 */
const open = async (id: number) => {
dialogVisible.value = true
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await ChatConversationApi.getChatConversationMy(id)
} finally {
formLoading.value = false
}
}
//
chatModelList.value = await ChatModelApi.getChatModelSimpleList(CommonStatusEnum.ENABLE)
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as ChatRoleVO
await ChatRoleApi.updateChatRole(data)
message.success(t('common.updateSuccess'))
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
modelId: undefined,
name: undefined,
avatar: undefined,
category: undefined,
sort: undefined,
description: undefined,
systemMessage: undefined,
publicStatus: true,
status: CommonStatusEnum.ENABLE
}
formRef.value?.resetFields()
}
</script>

View File

@ -67,7 +67,8 @@
{{ useConversation?.title }}
</div>
<div>
<el-dropdown style="margin-right: 12px" @command="modalClick">
<!-- TODO @fan样式改下这里我已经改成点击后弹出了 -->
<el-dropdown style="margin-right: 12px" @command="openChatConversationUpdateForm">
<el-button type="primary">
<span v-html="useModal?.name"></span>
<Icon icon="ep:setting" style="margin-left: 10px" />
@ -185,6 +186,8 @@
</el-footer>
</el-container>
</el-container>
<ChatConversationUpdateForm ref="chatConversationUpdateFormRef" />
</template>
<script setup lang="ts">
@ -194,6 +197,7 @@ import {
ChatConversationUpdateVO,
ChatConversationVO
} from '@/api/ai/chat/conversation'
import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
import { formatDate } from '@/utils/formatTime'
import { useClipboard } from '@vueuse/core'
@ -268,16 +272,17 @@ const updateConversationTitle = async (conversation: ChatConversationVO) => {
inputValue: conversation.title
})
//
await ChatConversationApi.updateConversationMy({
await ChatConversationApi.updateChatConversationMy({
id: conversation.id,
title: value
} as ChatConversationVO)
message.success('修改标题成功')
message.success('重命名成功')
//
await getChatConversationList()
}
const deleteConversationTitle = (conversation) => {
/** 删除聊天会话 */
const deleteConversationTitle = async (conversation: ChatConversationVO) => {
console.log(conversation)
// TODO
}
@ -453,15 +458,18 @@ const stopStream = async () => {
conversationInProgress.value = false
}
const modalClick = async (command) => {
const update = {
id: conversationId.value,
modelId: command.id
} as unknown as ChatConversationUpdateVO
// modal
useModal.value = command
//
await ChatConversationApi.updateConversationMy(update)
/** 修改聊天会话 */
const chatConversationUpdateFormRef = ref()
const openChatConversationUpdateForm = async (command) => {
// const update = {
// id: conversationId.value,
// modelId: command.id
// } as unknown as ChatConversationUpdateVO
// // modal
// useModal.value = command
// //
// await ChatConversationApi.updateChatConversationMy(update)
chatConversationUpdateFormRef.value.open(conversationId.value)
}
const getModalList = async () => {
@ -506,7 +514,7 @@ const onPromptInput = (event) => {
const getConversation = async (conversationId: string) => {
//
useConversation.value = await ChatConversationApi.get(conversationId)
useConversation.value = await ChatConversationApi.getChatConversationMy(conversationId)
console.log('useConversation.value', useConversation.value)
// modal
if (useConversation.value) {

View File

@ -29,15 +29,8 @@
<el-form-item label="角色描述" prop="description">
<el-input type="textarea" v-model="formData.description" placeholder="请输入角色描述" />
</el-form-item>
<el-form-item label="角色欢迎语" prop="welcomeMessage">
<el-input
type="textarea"
v-model="formData.welcomeMessage"
placeholder="请输入角色欢迎语"
/>
</el-form-item>
<el-form-item label="角色上下文" prop="systemMessage">
<el-input type="textarea" v-model="formData.systemMessage" placeholder="请输入角色上下文" />
<el-form-item label="角色设定" prop="systemMessage">
<el-input type="textarea" v-model="formData.systemMessage" placeholder="请输入角色设定" />
</el-form-item>
<el-form-item label="是否公开" prop="publicStatus">
<el-radio-group v-model="formData.publicStatus">
@ -95,7 +88,6 @@ const formData = ref({
category: undefined,
sort: undefined,
description: undefined,
welcomeMessage: undefined,
systemMessage: undefined,
publicStatus: true,
status: CommonStatusEnum.ENABLE
@ -106,8 +98,7 @@ const formRules = reactive({
category: [{ required: true, message: '角色类别不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '角色排序不能为空', trigger: 'blur' }],
description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }],
welcomeMessage: [{ required: true, message: '角色欢迎语不能为空', trigger: 'blur' }],
systemMessage: [{ required: true, message: '角色上下文不能为空', trigger: 'blur' }],
systemMessage: [{ required: true, message: '角色设定不能为空', trigger: 'blur' }],
publicStatus: [{ required: true, message: '是否公开不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
@ -167,7 +158,6 @@ const resetForm = () => {
category: undefined,
sort: undefined,
description: undefined,
welcomeMessage: undefined,
systemMessage: undefined,
publicStatus: true,
status: CommonStatusEnum.ENABLE

View File

@ -68,8 +68,7 @@
</el-table-column>
<el-table-column label="角色类别" align="center" prop="category" />
<el-table-column label="角色描述" align="center" prop="description" />
<el-table-column label="角色欢迎语" align="center" prop="welcomeMessage" />
<el-table-column label="角色上下文" align="center" prop="systemMessage" />
<el-table-column label="角色设定" align="center" prop="systemMessage" />
<el-table-column label="是否公开" align="center" prop="publicStatus">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.publicStatus" />