提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog title="设定" v-model="dialogVisible"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
:model="formData" |
|
6 |
:rules="formRules" |
|
7 |
label-width="130px" |
|
8 |
v-loading="formLoading" |
|
9 |
> |
|
10 |
<el-form-item label="角色设定" prop="systemMessage"> |
|
11 |
<el-input |
|
12 |
type="textarea" |
|
13 |
v-model="formData.systemMessage" |
|
14 |
rows="4" |
|
15 |
placeholder="请输入角色设定" |
|
16 |
/> |
|
17 |
</el-form-item> |
|
18 |
<el-form-item label="模型" prop="modelId"> |
|
19 |
<el-select v-model="formData.modelId" placeholder="请选择模型"> |
|
20 |
<el-option |
|
21 |
v-for="chatModel in chatModelList" |
|
22 |
:key="chatModel.id" |
|
23 |
:label="chatModel.name" |
|
24 |
:value="chatModel.id" |
|
25 |
/> |
|
26 |
</el-select> |
|
27 |
</el-form-item> |
|
28 |
<el-form-item label="温度参数" prop="temperature"> |
|
29 |
<el-input-number |
|
30 |
v-model="formData.temperature" |
|
31 |
placeholder="请输入温度参数" |
|
32 |
:min="0" |
|
33 |
:max="2" |
|
34 |
:precision="2" |
|
35 |
/> |
|
36 |
</el-form-item> |
|
37 |
<el-form-item label="回复数 Token 数" prop="maxTokens"> |
|
38 |
<el-input-number |
|
39 |
v-model="formData.maxTokens" |
|
40 |
placeholder="请输入回复数 Token 数" |
|
41 |
:min="0" |
|
42 |
:max="4096" |
|
43 |
/> |
|
44 |
</el-form-item> |
|
45 |
<el-form-item label="上下文数量" prop="maxContexts"> |
|
46 |
<el-input-number |
|
47 |
v-model="formData.maxContexts" |
|
48 |
placeholder="请输入上下文数量" |
|
49 |
:min="0" |
|
50 |
:max="20" |
|
51 |
/> |
|
52 |
</el-form-item> |
|
53 |
</el-form> |
|
54 |
<template #footer> |
|
55 |
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button> |
|
56 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
57 |
</template> |
|
58 |
</Dialog> |
|
59 |
</template> |
|
60 |
<script setup lang="ts"> |
|
61 |
import { CommonStatusEnum } from '@/utils/constants' |
|
62 |
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel' |
|
63 |
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation' |
|
64 |
|
|
65 |
/** AI 聊天对话的更新表单 */ |
|
66 |
defineOptions({ name: 'ChatConversationUpdateForm' }) |
|
67 |
|
|
68 |
const message = useMessage() // 消息弹窗 |
|
69 |
|
|
70 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
71 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
72 |
const formData = ref({ |
|
73 |
id: undefined, |
|
74 |
systemMessage: undefined, |
|
75 |
modelId: undefined, |
|
76 |
temperature: undefined, |
|
77 |
maxTokens: undefined, |
|
78 |
maxContexts: undefined |
|
79 |
}) |
|
80 |
const formRules = reactive({ |
|
81 |
modelId: [{ required: true, message: '模型不能为空', trigger: 'blur' }], |
|
82 |
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }], |
|
83 |
temperature: [{ required: true, message: '温度参数不能为空', trigger: 'blur' }], |
|
84 |
maxTokens: [{ required: true, message: '回复数 Token 数不能为空', trigger: 'blur' }], |
|
85 |
maxContexts: [{ required: true, message: '上下文数量不能为空', trigger: 'blur' }] |
|
86 |
}) |
|
87 |
const formRef = ref() // 表单 Ref |
|
88 |
const chatModelList = ref([] as ChatModelVO[]) // 聊天模型列表 |
|
89 |
|
|
90 |
/** 打开弹窗 */ |
|
91 |
const open = async (id: number) => { |
|
92 |
dialogVisible.value = true |
|
93 |
resetForm() |
|
94 |
// 修改时,设置数据 |
|
95 |
if (id) { |
|
96 |
formLoading.value = true |
|
97 |
try { |
|
98 |
const data = await ChatConversationApi.getChatConversationMy(id) |
|
99 |
formData.value = Object.keys(formData.value).reduce((obj, key) => { |
|
100 |
if (data.hasOwnProperty(key)) { |
|
101 |
obj[key] = data[key] |
|
102 |
} |
|
103 |
return obj |
|
104 |
}, {}) |
|
105 |
} finally { |
|
106 |
formLoading.value = false |
|
107 |
} |
|
108 |
} |
|
109 |
// 获得下拉数据 |
|
110 |
chatModelList.value = await ChatModelApi.getChatModelSimpleList(CommonStatusEnum.ENABLE) |
|
111 |
} |
|
112 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
113 |
|
|
114 |
/** 提交表单 */ |
|
115 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
116 |
const submitForm = async () => { |
|
117 |
// 校验表单 |
|
118 |
await formRef.value.validate() |
|
119 |
// 提交请求 |
|
120 |
formLoading.value = true |
|
121 |
try { |
|
122 |
const data = formData.value as unknown as ChatConversationVO |
|
123 |
await ChatConversationApi.updateChatConversationMy(data) |
|
124 |
message.success('对话配置已更新') |
|
125 |
dialogVisible.value = false |
|
126 |
// 发送操作成功的事件 |
|
127 |
emit('success') |
|
128 |
} finally { |
|
129 |
formLoading.value = false |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/** 重置表单 */ |
|
134 |
const resetForm = () => { |
|
135 |
formData.value = { |
|
136 |
id: undefined, |
|
137 |
systemMessage: undefined, |
|
138 |
modelId: undefined, |
|
139 |
temperature: undefined, |
|
140 |
maxTokens: undefined, |
|
141 |
maxContexts: undefined |
|
142 |
} |
|
143 |
formRef.value?.resetFields() |
|
144 |
} |
|
145 |
</script> |