【优化】处理不同模型 maxTokens 不一样问题,如果超出会报错

dev_m2
cherishsince 2024-09-10 22:38:43 +08:00
parent 5a3ae2ab7a
commit 5344602346
1 changed files with 30 additions and 12 deletions

View File

@ -16,7 +16,7 @@
/> />
</el-form-item> </el-form-item>
<el-form-item label="模型" prop="modelId"> <el-form-item label="模型" prop="modelId">
<el-select v-model="formData.modelId" placeholder="请选择模型"> <el-select v-model="formData.modelId" placeholder="请选择模型" @change="handlerChange">
<el-option <el-option
v-for="chatModel in chatModelList" v-for="chatModel in chatModelList"
:key="chatModel.id" :key="chatModel.id"
@ -39,7 +39,7 @@
v-model="formData.maxTokens" v-model="formData.maxTokens"
placeholder="请输入回复数 Token 数" placeholder="请输入回复数 Token 数"
:min="0" :min="0"
:max="4096" :max="maxTokens"
/> />
</el-form-item> </el-form-item>
<el-form-item label="上下文数量" prop="maxContexts"> <el-form-item label="上下文数量" prop="maxContexts">
@ -58,17 +58,18 @@
</Dialog> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
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'
/** AI 聊天对话的更新表单 */ /** AI 聊天对话的更新表单 */
defineOptions({ name: 'ChatConversationUpdateForm' }) defineOptions({name: 'ChatConversationUpdateForm'})
const message = useMessage() // const message = useMessage() //
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const maxTokens = ref(2000) // maxTokens2000
const formData = ref({ const formData = ref({
id: undefined, id: undefined,
systemMessage: undefined, systemMessage: undefined,
@ -78,11 +79,11 @@ const formData = ref({
maxContexts: undefined maxContexts: undefined
}) })
const formRules = reactive({ const formRules = reactive({
modelId: [{ required: true, message: '模型不能为空', trigger: 'blur' }], modelId: [{required: true, message: '模型不能为空', trigger: 'blur'}],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }], status: [{required: true, message: '状态不能为空', trigger: 'blur'}],
temperature: [{ required: true, message: '温度参数不能为空', trigger: 'blur' }], temperature: [{required: true, message: '温度参数不能为空', trigger: 'blur'}],
maxTokens: [{ required: true, message: '回复数 Token 数不能为空', trigger: 'blur' }], maxTokens: [{required: true, message: '回复数 Token 数不能为空', trigger: 'blur'}],
maxContexts: [{ required: true, message: '上下文数量不能为空', trigger: 'blur' }] maxContexts: [{required: true, message: '上下文数量不能为空', trigger: 'blur'}]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const chatModelList = ref([] as ChatModelVO[]) // const chatModelList = ref([] as ChatModelVO[]) //
@ -109,7 +110,7 @@ const open = async (id: number) => {
// //
chatModelList.value = await ChatModelApi.getChatModelSimpleList(CommonStatusEnum.ENABLE) chatModelList.value = await ChatModelApi.getChatModelSimpleList(CommonStatusEnum.ENABLE)
} }
defineExpose({ open }) // open defineExpose({open}) // open
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
@ -142,4 +143,21 @@ const resetForm = () => {
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }
/** model change */
const handlerChange = (val) => {
const filterModel = chatModelList.value.filter(item => {
return item.id === val
})[0]
console.log(filterModel)
console.log(filterModel.maxTokens)
if (filterModel.maxTokens != null) {
maxTokens.value = filterModel.maxTokens
formData.value.maxTokens = filterModel.maxTokens
} else {
maxTokens.value = 2000
formData.value.maxTokens = 2000
}
}
</script> </script>