fix: 修复AI模型参数,切换模型时参数修改为当前模型的默认参数
This commit is contained in:
parent
7360779002
commit
eb60a0de2e
@ -23,7 +23,7 @@ from common.exception.app_exception import AppApiException
|
|||||||
from common.util.field_message import ErrMessage
|
from common.util.field_message import ErrMessage
|
||||||
from common.util.rsa_util import rsa_long_decrypt, rsa_long_encrypt
|
from common.util.rsa_util import rsa_long_decrypt, rsa_long_encrypt
|
||||||
from dataset.models import DataSet
|
from dataset.models import DataSet
|
||||||
from setting.models.model_management import Model, Status
|
from setting.models.model_management import Model, Status, PermissionType
|
||||||
from setting.models_provider import get_model, get_model_credential
|
from setting.models_provider import get_model, get_model_credential
|
||||||
from setting.models_provider.base_model_provider import ValidCode, DownModelChunkStatus
|
from setting.models_provider.base_model_provider import ValidCode, DownModelChunkStatus
|
||||||
from setting.models_provider.constants.model_provider_constants import ModelProvideConstants
|
from setting.models_provider.constants.model_provider_constants import ModelProvideConstants
|
||||||
@ -208,6 +208,27 @@ class ModelSerializer(serializers.Serializer):
|
|||||||
credential),
|
credential),
|
||||||
'permission_type': model.permission_type}
|
'permission_type': model.permission_type}
|
||||||
|
|
||||||
|
class ModelParams(serializers.Serializer):
|
||||||
|
id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("模型id"))
|
||||||
|
|
||||||
|
user_id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("用户id"))
|
||||||
|
|
||||||
|
def is_valid(self, *, raise_exception=False):
|
||||||
|
super().is_valid(raise_exception=True)
|
||||||
|
model = QuerySet(Model).filter(id=self.data.get("id")).first()
|
||||||
|
if model is None:
|
||||||
|
raise AppApiException(500, '模型不存在')
|
||||||
|
if model.permission_type == PermissionType.PRIVATE and self.data.get('user_id') != str(model.user_id):
|
||||||
|
raise AppApiException(500, '没有权限访问到此模型')
|
||||||
|
|
||||||
|
def get_model_params(self, with_valid=True):
|
||||||
|
if with_valid:
|
||||||
|
self.is_valid(raise_exception=True)
|
||||||
|
model_id = self.data.get('id')
|
||||||
|
model = QuerySet(Model).filter(id=model_id).first()
|
||||||
|
credential = get_model_credential(model.provider, model.model_type, model.model_name)
|
||||||
|
return credential.get_model_params_setting_form(model.model_name).to_form_list()
|
||||||
|
|
||||||
class Operate(serializers.Serializer):
|
class Operate(serializers.Serializer):
|
||||||
id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("模型id"))
|
id = serializers.UUIDField(required=True, error_messages=ErrMessage.uuid("模型id"))
|
||||||
|
|
||||||
@ -235,14 +256,6 @@ class ModelSerializer(serializers.Serializer):
|
|||||||
'meta': model.meta
|
'meta': model.meta
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_model_params(self, with_valid=True):
|
|
||||||
if with_valid:
|
|
||||||
self.is_valid(raise_exception=True)
|
|
||||||
model_id = self.data.get('id')
|
|
||||||
model = QuerySet(Model).filter(id=model_id).first()
|
|
||||||
credential = get_model_credential(model.provider, model.model_type, model.model_name)
|
|
||||||
return credential.get_model_params_setting_form(model.model_name).to_form_list()
|
|
||||||
|
|
||||||
def delete(self, with_valid=True):
|
def delete(self, with_valid=True):
|
||||||
if with_valid:
|
if with_valid:
|
||||||
self.is_valid(raise_exception=True)
|
self.is_valid(raise_exception=True)
|
||||||
|
|||||||
@ -92,7 +92,7 @@ class Model(APIView):
|
|||||||
@has_permissions(PermissionConstants.MODEL_READ)
|
@has_permissions(PermissionConstants.MODEL_READ)
|
||||||
def get(self, request: Request, model_id: str):
|
def get(self, request: Request, model_id: str):
|
||||||
return result.success(
|
return result.success(
|
||||||
ModelSerializer.Operate(data={'id': model_id, 'user_id': request.user.id}).get_model_params())
|
ModelSerializer.ModelParams(data={'id': model_id, 'user_id': request.user.id}).get_model_params())
|
||||||
|
|
||||||
class Operate(APIView):
|
class Operate(APIView):
|
||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|||||||
@ -79,6 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-select
|
<el-select
|
||||||
|
@change="model_change"
|
||||||
v-model="applicationForm.model_id"
|
v-model="applicationForm.model_id"
|
||||||
:placeholder="$t('views.application.applicationForm.form.aiModel.placeholder')"
|
:placeholder="$t('views.application.applicationForm.form.aiModel.placeholder')"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
@ -450,7 +451,9 @@ const submit = async (formEl: FormInstance | undefined) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const model_change = (model_id: string) => {
|
||||||
|
AIModeParamSettingDialogRef.value?.reset_default(model_id)
|
||||||
|
}
|
||||||
const openAIParamSettingDialog = () => {
|
const openAIParamSettingDialog = () => {
|
||||||
const model_id = applicationForm.value.model_id
|
const model_id = applicationForm.value.model_id
|
||||||
if (!model_id) {
|
if (!model_id) {
|
||||||
|
|||||||
@ -32,8 +32,6 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
import type { FormInstance } from 'element-plus'
|
|
||||||
import type { FormField } from '@/components/dynamics-form/type'
|
import type { FormField } from '@/components/dynamics-form/type'
|
||||||
import modelAPi from '@/api/model'
|
import modelAPi from '@/api/model'
|
||||||
import DynamicsForm from '@/components/dynamics-form/index.vue'
|
import DynamicsForm from '@/components/dynamics-form/index.vue'
|
||||||
@ -46,6 +44,7 @@ const dialogVisible = ref(false)
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const open = (model_id: string, model_setting_data?: any) => {
|
const open = (model_id: string, model_setting_data?: any) => {
|
||||||
|
form_data.value = {}
|
||||||
modelAPi.getModelParamsForm(model_id, loading).then((ok) => {
|
modelAPi.getModelParamsForm(model_id, loading).then((ok) => {
|
||||||
model_form_field.value = ok.data
|
model_form_field.value = ok.data
|
||||||
model_setting_data =
|
model_setting_data =
|
||||||
@ -60,12 +59,25 @@ const open = (model_id: string, model_setting_data?: any) => {
|
|||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reset_default = (model_id: string) => {
|
||||||
|
form_data.value = {}
|
||||||
|
modelAPi.getModelParamsForm(model_id, loading).then((ok) => {
|
||||||
|
model_form_field.value = ok.data
|
||||||
|
const model_setting_data = ok.data
|
||||||
|
.map((item) => ({ [item.field]: item.default_value }))
|
||||||
|
.reduce((x, y) => ({ ...x, ...y }), {})
|
||||||
|
// 渲染动态表单
|
||||||
|
dynamicsFormRef.value?.render(model_form_field.value, model_setting_data)
|
||||||
|
emit('refresh', form_data.value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
emit('refresh', form_data.value)
|
emit('refresh', form_data.value)
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ open })
|
defineExpose({ open, reset_default })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-select
|
<el-select
|
||||||
|
@change="model_change"
|
||||||
@wheel="wheel"
|
@wheel="wheel"
|
||||||
@keydown="isKeyDown = true"
|
@keydown="isKeyDown = true"
|
||||||
@keyup="isKeyDown = false"
|
@keyup="isKeyDown = false"
|
||||||
@ -238,7 +239,9 @@ function submitDialog() {
|
|||||||
set(props.nodeModel.properties.node_data, 'prompt', cloneContent.value)
|
set(props.nodeModel.properties.node_data, 'prompt', cloneContent.value)
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
|
const model_change = (model_id: string) => {
|
||||||
|
AIModeParamSettingDialogRef.value?.reset_default(model_id)
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
params: { id }
|
params: { id }
|
||||||
} = app.config.globalProperties.$route as any
|
} = app.config.globalProperties.$route as any
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-select
|
<el-select
|
||||||
|
@change="model_change"
|
||||||
@wheel="wheel"
|
@wheel="wheel"
|
||||||
@keydown="isKeyDown = true"
|
@keydown="isKeyDown = true"
|
||||||
@keyup="isKeyDown = false"
|
@keyup="isKeyDown = false"
|
||||||
@ -231,6 +232,9 @@ function openDialog() {
|
|||||||
cloneContent.value = form_data.value.prompt
|
cloneContent.value = form_data.value.prompt
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
const model_change = (model_id: string) => {
|
||||||
|
AIModeParamSettingDialogRef.value?.reset_default(model_id)
|
||||||
|
}
|
||||||
function submitDialog() {
|
function submitDialog() {
|
||||||
set(props.nodeModel.properties.node_data, 'prompt', cloneContent.value)
|
set(props.nodeModel.properties.node_data, 'prompt', cloneContent.value)
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user