【新增】AI:聊天对话的更新模型

This commit is contained in:
YunaiV 2024-05-15 19:45:19 +08:00
parent c06bc71020
commit 3d83f4928a
3 changed files with 67 additions and 66 deletions

View File

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

View File

@ -4,23 +4,46 @@
ref="formRef" ref="formRef"
:model="formData" :model="formData"
:rules="formRules" :rules="formRules"
label-width="100px" label-width="130px"
v-loading="formLoading" v-loading="formLoading"
> >
<el-form-item label="角色设定" prop="systemContext"> <el-form-item label="角色设定" prop="systemMessage">
<el-input type="textarea" v-model="formData.systemContext" placeholder="请输入角色设定" /> <el-input type="textarea" v-model="formData.systemMessage" placeholder="请输入角色设定" />
</el-form-item> </el-form-item>
<el-form-item label="模型" prop="modelId"> <el-form-item label="模型" prop="modelId">
<UploadImg v-model="formData.modelId" /> <el-select v-model="formData.modelId" placeholder="请选择模型">
<el-option
v-for="chatModel in chatModelList"
:key="chatModel.id"
:label="chatModel.name"
:value="chatModel.id"
/>
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="上下文数量" prop="category"> <el-form-item label="温度参数" prop="temperature">
<el-input v-model="formData.category" placeholder="请输入角色类别" /> <el-input-number
v-model="formData.temperature"
placeholder="请输入温度参数"
:min="0"
:max="2"
:precision="2"
/>
</el-form-item> </el-form-item>
<el-form-item label="话题随机性" prop="description"> <el-form-item label="回复数 Token 数" prop="maxTokens">
<el-input type="textarea" v-model="formData.description" placeholder="请输入角色描述" /> <el-input-number
v-model="formData.maxTokens"
placeholder="请输入回复数 Token 数"
:min="0"
:max="4096"
/>
</el-form-item> </el-form-item>
<el-form-item label="回复数" prop="systemMessage"> <el-form-item label="上下文数量" prop="maxContexts">
<el-input type="textarea" v-model="formData.systemMessage" placeholder="请输入角色设定" /> <el-input-number
v-model="formData.maxContexts"
placeholder="请输入上下文数量"
:min="0"
:max="20"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
@ -30,7 +53,6 @@
</Dialog> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ChatRoleApi, ChatRoleVO } from '@/api/ai/model/chatRole'
import { CommonStatusEnum } from '@/utils/constants' import { CommonStatusEnum } from '@/utils/constants'
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel' import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation' import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
@ -45,25 +67,18 @@ const dialogVisible = ref(false) // 弹窗的是否展示
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formData = ref({ const formData = ref({
id: undefined, id: undefined,
systemContext: undefined,
modelId: undefined,
name: undefined,
avatar: undefined,
category: undefined,
sort: undefined,
description: undefined,
systemMessage: undefined, systemMessage: undefined,
publicStatus: true, modelId: undefined,
status: CommonStatusEnum.ENABLE temperature: undefined,
maxTokens: undefined,
maxContexts: undefined
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '角色名称不能为空', trigger: 'blur' }], modelId: [{ required: true, message: '模型不能为空', trigger: 'blur' }],
avatar: [{ required: true, message: '角色头像不能为空', trigger: 'blur' }], status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
category: [{ required: true, message: '角色类别不能为空', trigger: 'blur' }], temperature: [{ required: true, message: '温度参数不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '角色排序不能为空', trigger: 'blur' }], maxTokens: [{ required: true, message: '回复数 Token 数不能为空', trigger: 'blur' }],
description: [{ required: true, message: '角色描述不能为空', trigger: 'blur' }], maxContexts: [{ required: true, message: '上下文数量不能为空', trigger: 'blur' }]
systemMessage: [{ required: true, message: '角色设定不能为空', trigger: 'blur' }],
publicStatus: [{ required: true, message: '是否公开不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const chatModelList = ref([] as ChatModelVO[]) // const chatModelList = ref([] as ChatModelVO[]) //
@ -76,7 +91,13 @@ const open = async (id: number) => {
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await ChatConversationApi.getChatConversationMy(id) const data = await ChatConversationApi.getChatConversationMy(id)
formData.value = Object.keys(formData.value).reduce((obj, key) => {
if (data.hasOwnProperty(key)) {
obj[key] = data[key]
}
return obj
}, {})
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -94,9 +115,9 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value as unknown as ChatRoleVO const data = formData.value as unknown as ChatConversationVO
await ChatRoleApi.updateChatRole(data) await ChatConversationApi.updateChatConversationMy(data)
message.success(t('common.updateSuccess')) message.success('对话配置已更新')
dialogVisible.value = false dialogVisible.value = false
// //
emit('success') emit('success')
@ -109,15 +130,11 @@ const submitForm = async () => {
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,
modelId: undefined,
name: undefined,
avatar: undefined,
category: undefined,
sort: undefined,
description: undefined,
systemMessage: undefined, systemMessage: undefined,
publicStatus: true, modelId: undefined,
status: CommonStatusEnum.ENABLE temperature: undefined,
maxTokens: undefined,
maxContexts: undefined
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

View File

@ -68,17 +68,10 @@
</div> </div>
<div> <div>
<!-- TODO @fan样式改下这里我已经改成点击后弹出了 --> <!-- TODO @fan样式改下这里我已经改成点击后弹出了 -->
<el-dropdown style="margin-right: 12px" @command="openChatConversationUpdateForm"> <el-button type="primary" @click="openChatConversationUpdateForm">
<el-button type="primary"> <span v-html="useModal?.name"></span>
<span v-html="useModal?.name"></span> <Icon icon="ep:setting" style="margin-left: 10px" />
<Icon icon="ep:setting" style="margin-left: 10px" /> </el-button>
</el-button>
<template #dropdown>
<el-dropdown-menu v-for="(item, index) in modalList" :key="index">
<el-dropdown-item :command="item">{{ item.name }}</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-button> <el-button>
<Icon icon="ep:user" /> <Icon icon="ep:user" />
</el-button> </el-button>
@ -187,16 +180,15 @@
</el-container> </el-container>
</el-container> </el-container>
<ChatConversationUpdateForm ref="chatConversationUpdateFormRef" /> <ChatConversationUpdateForm
ref="chatConversationUpdateFormRef"
@success="getChatConversationList"
/>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ChatMessageApi, ChatMessageSendVO, ChatMessageVO } from '@/api/ai/chat/message' import { ChatMessageApi, ChatMessageSendVO, ChatMessageVO } from '@/api/ai/chat/message'
import { import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
ChatConversationApi,
ChatConversationUpdateVO,
ChatConversationVO
} from '@/api/ai/chat/conversation'
import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue' import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel' import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
import { formatDate } from '@/utils/formatTime' import { formatDate } from '@/utils/formatTime'
@ -460,15 +452,7 @@ const stopStream = async () => {
/** 修改聊天会话 */ /** 修改聊天会话 */
const chatConversationUpdateFormRef = ref() const chatConversationUpdateFormRef = ref()
const openChatConversationUpdateForm = async (command) => { const openChatConversationUpdateForm = async () => {
// 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) chatConversationUpdateFormRef.value.open(conversationId.value)
} }