From fd5eb1bd8e25e1db9b1766ea6067ca3db7b17450 Mon Sep 17 00:00:00 2001 From: CaptainB <bin@fit2cloud.com> Date: Wed, 9 Oct 2024 21:44:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/setting/serializers/provider_serializers.py | 2 +- ui/src/api/type/model.ts | 1 + ui/src/views/template/component/ModelCard.vue | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/setting/serializers/provider_serializers.py b/apps/setting/serializers/provider_serializers.py index 4ee3a3ac2d2..0a714680952 100644 --- a/apps/setting/serializers/provider_serializers.py +++ b/apps/setting/serializers/provider_serializers.py @@ -94,7 +94,7 @@ def list(self, with_valid): return [ {'id': str(model.id), 'provider': model.provider, 'name': model.name, 'model_type': model.model_type, 'model_name': model.model_name, 'status': model.status, 'meta': model.meta, - 'permission_type': model.permission_type, 'user_id': model.user_id} for model in + 'permission_type': model.permission_type, 'user_id': model.user_id, 'username': model.user.username} for model in model_query_set.filter(**query_params).order_by("-create_time")] class Edit(serializers.Serializer): diff --git a/ui/src/api/type/model.ts b/ui/src/api/type/model.ts index 8a41d68bf97..1660ffd712b 100644 --- a/ui/src/api/type/model.ts +++ b/ui/src/api/type/model.ts @@ -54,6 +54,7 @@ interface Model { */ model_type: string user_id: string + username: string permission_type: 'PUBLIC' | 'PRIVATE' /** * 基础模型 diff --git a/ui/src/views/template/component/ModelCard.vue b/ui/src/views/template/component/ModelCard.vue index 17c051e6aa0..3a572dc1f6b 100644 --- a/ui/src/views/template/component/ModelCard.vue +++ b/ui/src/views/template/component/ModelCard.vue @@ -47,6 +47,12 @@ {{ model.model_name }}</span > </li> + <li class="flex mt-12"> + <el-text type="info">创建者</el-text> + <span class="ellipsis-1 ml-16" style="height: 20px; width: 70%"> + {{ model.username }}</span + > + </li> </ul> </div> <!-- progress --> From dd5c03452492f9f20ed4ce63a750384462b42495 Mon Sep 17 00:00:00 2001 From: CaptainB <bin@fit2cloud.com> Date: Fri, 11 Oct 2024 18:55:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E6=9F=A5=E8=AF=A2=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/dataset/views/dataset.py | 1 - .../serializers/provider_serializers.py | 19 +++++- ui/src/views/template/index.vue | 65 ++++++++++++++++--- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/apps/dataset/views/dataset.py b/apps/dataset/views/dataset.py index fc3f8a8a588..4bd9e1f749b 100644 --- a/apps/dataset/views/dataset.py +++ b/apps/dataset/views/dataset.py @@ -235,7 +235,6 @@ class Model(APIView): dynamic_tag=keywords.get('dataset_id'))], compare=CompareConstants.AND)) def get(self, request: Request, dataset_id: str): - print(dataset_id) return result.success( ModelSerializer.Query( data={'user_id': request.user.id, 'model_type': 'LLM'}).list( diff --git a/apps/setting/serializers/provider_serializers.py b/apps/setting/serializers/provider_serializers.py index 0a714680952..5b926ec0bee 100644 --- a/apps/setting/serializers/provider_serializers.py +++ b/apps/setting/serializers/provider_serializers.py @@ -75,12 +75,26 @@ class Query(serializers.Serializer): provider = serializers.CharField(required=False, error_messages=ErrMessage.char("供应商")) + permission_type = serializers.CharField(required=False, error_messages=ErrMessage.char("权限")) + + create_user = serializers.CharField(required=False, error_messages=ErrMessage.char("创建者")) + + def list(self, with_valid): if with_valid: self.is_valid(raise_exception=True) user_id = self.data.get('user_id') name = self.data.get('name') - model_query_set = QuerySet(Model).filter((Q(user_id=user_id) | Q(permission_type='PUBLIC'))) + create_user = self.data.get('create_user') + if create_user is not None: + # 当前用户能查看自己的模型,包括公开和私有的 + if create_user == user_id: + model_query_set = QuerySet(Model).filter(Q(user_id=create_user)) + # 当前用户能查看其他人的模型,只能查看公开的 + else: + model_query_set = QuerySet(Model).filter((Q(user_id=self.data.get('create_user')) & Q(permission_type='PUBLIC'))) + else: + model_query_set = QuerySet(Model).filter((Q(user_id=user_id) | Q(permission_type='PUBLIC'))) query_params = {} if name is not None: query_params['name__contains'] = name @@ -90,6 +104,9 @@ def list(self, with_valid): query_params['model_name'] = self.data.get('model_name') if self.data.get('provider') is not None: query_params['provider'] = self.data.get('provider') + if self.data.get('permission_type') is not None: + query_params['permission_type'] = self.data.get('permission_type') + return [ {'id': str(model.id), 'provider': model.provider, 'name': model.name, 'model_type': model.model_type, diff --git a/ui/src/views/template/index.vue b/ui/src/views/template/index.vue index 54eb037003a..a9217bb0440 100644 --- a/ui/src/views/template/index.vue +++ b/ui/src/views/template/index.vue @@ -41,14 +41,42 @@ <h4>{{ active_provider?.name }}</h4> <div class="flex-between mt-16 mb-16"> <el-button type="primary" @click="openCreateModel(active_provider)">添加模型</el-button> - <el-input - v-model="model_search_form.name" - @change="list_model" - placeholder="按名称搜索" - prefix-icon="Search" - style="max-width: 240px" - clearable - /> + <div class="flex-between"> + <el-select v-model="search_type" style="width: 200px" @change="search_type_change"> + <el-option label="创建者" value="create_user" /> + <el-option label="权限" value="permission_type" /> + <el-option label="模型类型" value="model_type" /> + <el-option label="模型名称" value="name" /> + </el-select> + <el-input + v-if="search_type === 'name'" + v-model="model_search_form.name" + @change="list_model" + placeholder="按名称搜索" + prefix-icon="Search" + style="max-width: 240px" + clearable + /> + <el-select v-else-if="search_type === 'create_user'" v-model="model_search_form.create_user" @change="list_model" + clearable> + <el-option v-for="u in user_options" :key="u.id" :value="u.id" :label="u.username" /> + </el-select> + <el-select v-else-if="search_type === 'permission_type'" v-model="model_search_form.permission_type" + clearable + @change="list_model"> + <el-option label="公有" value="PUBLIC" /> + <el-option label="私有" value="PRIVATE" /> + </el-select> + <el-select v-else-if="search_type === 'model_type'" v-model="model_search_form.model_type" + clearable + @change="list_model"> + <el-option label="大语言模型" value="LLM" /> + <el-option label="向量模型" value="EMBEDDING" /> + <el-option label="重排模型" value="RERANKER" /> + <el-option label="语音识别" value="STT" /> + <el-option label="语音合成" value="TTS" /> + </el-select> + </div> </div> </div> <div class="model-list-height"> @@ -114,7 +142,14 @@ const allObj = { const loading = ref<boolean>(false) const active_provider = ref<Provider>() -const model_search_form = ref<{ name: string }>({ name: '' }) +const search_type = ref('name') +const model_search_form = ref<{ name: string, create_user: string, permission_type: string, model_type: string }>({ + name: '', + create_user: '', + permission_type: '', + model_type: '' +}) +const user_options = ref<any[]>([]) const list_model_loading = ref<boolean>(false) const provider_list = ref<Array<Provider>>([]) @@ -150,9 +185,20 @@ const list_model = () => { const params = active_provider.value?.provider ? { provider: active_provider.value.provider } : {} ModelApi.getModel({ ...model_search_form.value, ...params }, list_model_loading).then((ok) => { model_list.value = ok.data + const v = model_list.value.map((m) => ({ id: m.user_id, username: m.username })) + if (user_options.value.length === 0){ + user_options.value = Array.from( + new Map(v.map(item => [item.id, item])).values() + ) + } }) } +const search_type_change = () => { + model_search_form.value = { name: '', create_user: '', permission_type: '', model_type: '' } +} + + onMounted(() => { ModelApi.getProvider(loading).then((ok) => { active_provider.value = allObj @@ -173,6 +219,7 @@ onMounted(() => { .model-list-height { height: calc(var(--create-dataset-height) - 70px); } + .model-list-height-left { height: calc(var(--create-dataset-height)); }