【优化】处理不同模型 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 label="模型" prop="modelId">
<el-select v-model="formData.modelId" placeholder="请选择模型">
<el-select v-model="formData.modelId" placeholder="请选择模型" @change="handlerChange">
<el-option
v-for="chatModel in chatModelList"
:key="chatModel.id"
@ -39,7 +39,7 @@
v-model="formData.maxTokens"
placeholder="请输入回复数 Token 数"
:min="0"
:max="4096"
:max="maxTokens"
/>
</el-form-item>
<el-form-item label="上下文数量" prop="maxContexts">
@ -69,6 +69,7 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const maxTokens = ref(2000) // maxTokens2000
const formData = ref({
id: undefined,
systemMessage: undefined,
@ -142,4 +143,21 @@ const resetForm = () => {
}
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>