【新增】AI:聊天更新的窗口
parent
ebd593bf92
commit
bd5262e21d
|
@ -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 })
|
||||
},
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ export interface ChatRoleVO {
|
|||
category: string // 角色类别
|
||||
sort: number // 角色排序
|
||||
description: string // 角色描述
|
||||
welcomeMessage: string // 角色欢迎语
|
||||
systemMessage: string // 角色上下文
|
||||
systemMessage: string // 角色设定
|
||||
publicStatus: boolean // 是否公开
|
||||
status: number // 状态
|
||||
}
|
||||
|
|
|
@ -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) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
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>
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue