feat: 支持向量模型

This commit is contained in:
shaohuzhang1 2024-07-19 16:13:44 +08:00
parent 8dc426664f
commit f372095f51
7 changed files with 58 additions and 37 deletions

View File

@ -22,6 +22,8 @@ class Status(models.TextChoices):
DOWNLOAD = "DOWNLOAD", '下载中'
PAUSE_DOWNLOAD = "PAUSE_DOWNLOAD", '暂停下载'
class PermissionType(models.TextChoices):
PUBLIC = "PUBLIC", '公开'

View File

@ -38,6 +38,9 @@ class ModelPullManage:
for chunk in response:
down_model_chunk[chunk.digest] = chunk.to_dict()
if time.time() - timestamp > 5:
model_new = QuerySet(Model).filter(id=model.id).first()
if model_new.status == Status.PAUSE_DOWNLOAD:
return
QuerySet(Model).filter(id=model.id).update(
meta={"down_model_chunk": list(down_model_chunk.values())})
timestamp = time.time()
@ -238,6 +241,12 @@ class ModelSerializer(serializers.Serializer):
QuerySet(Model).filter(id=self.data.get('id')).delete()
return True
def pause_download(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
QuerySet(Model).filter(id=self.data.get('id')).update(status=Status.PAUSE_DOWNLOAD)
return True
def edit(self, instance: Dict, user_id: str, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)

View File

@ -16,6 +16,7 @@ urlpatterns = [
name="provider/model_form"),
path('model', views.Model.as_view(), name='model'),
path('model/<str:model_id>', views.Model.Operate.as_view(), name='model/operate'),
path('model/<str:model_id>/pause_download', views.Model.PauseDownload.as_view(), name='model/operate'),
path('model/<str:model_id>/meta', views.Model.ModelMeta.as_view(), name='model/operate/meta'),
path('email_setting', views.SystemSetting.Email.as_view(), name='email_setting'),
path('valid/<str:valid_type>/<int:valid_count>', views.Valid.as_view())

View File

@ -69,6 +69,18 @@ class Model(APIView):
return result.success(
ModelSerializer.Operate(data={'id': model_id, 'user_id': request.user.id}).one_meta(with_valid=True))
class PauseDownload(APIView):
authentication_classes = [TokenAuth]
@action(methods=['PUT'], detail=False)
@swagger_auto_schema(operation_summary="暂停模型下载",
operation_id="暂停模型下载",
tags=["模型"])
@has_permissions(PermissionConstants.MODEL_CREATE)
def put(self, request: Request, model_id: str):
return result.success(
ModelSerializer.Operate(data={'id': model_id, 'user_id': request.user.id}).pause_download())
class Operate(APIView):
authentication_classes = [TokenAuth]

View File

@ -130,7 +130,18 @@ const getModelMetaById: (model_id: string, loading?: Ref<boolean>) => Promise<Re
) => {
return get(`${prefix}/${model_id}/meta`, {}, loading)
}
/**
*
* @param model_id id
* @param loading
* @returns
*/
const pauseDownload: (model_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
model_id,
loading
) => {
return put(`${prefix}/${model_id}/pause_download`, undefined, {}, loading)
}
const deleteModel: (model_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
model_id,
loading
@ -147,5 +158,6 @@ export default {
updateModel,
deleteModel,
getModelById,
getModelMetaById
getModelMetaById,
pauseDownload
}

View File

@ -69,7 +69,7 @@ interface Model {
/**
*
*/
status: 'SUCCESS' | 'DOWNLOAD' | 'ERROR'
status: 'SUCCESS' | 'DOWNLOAD' | 'ERROR' | 'PAUSE_DOWNLOAD'
/**
*
*/

View File

@ -21,6 +21,12 @@
<el-icon class="danger ml-4" size="20"><Warning /></el-icon>
</el-tooltip>
</div>
<div class="flex align-center" v-if="currentModel.status === 'PAUSE_DOWNLOAD'">
<el-tag type="danger" class="ml-8">暂停下载</el-tag>
<el-tooltip effect="dark" content="暂停下载" placement="top">
<el-icon class="danger ml-4" size="20"><Warning /></el-icon>
</el-tooltip>
</div>
</div>
</template>
@ -39,17 +45,6 @@
<!-- progress -->
<div class="progress-mask" v-if="currentModel.status === 'DOWNLOAD'">
<DownloadLoading class="percentage" />
<!-- <el-progress
type="circle"
:width="56"
color="#3370FF"
:percentage="progress"
class="percentage"
>
<template #default="{ percentage }">
<span class="percentage-value">{{ percentage }}%</span>
</template>
</el-progress> -->
<div class="percentage-label flex-center">
正在下载中 <span class="dotting"></span>
@ -64,7 +59,13 @@
<el-tooltip effect="dark" content="修改" placement="top">
<el-button text @click.stop="openEditModel">
<el-icon>
<component :is="currentModel.status === 'ERROR' ? 'RefreshRight' : 'EditPen'" />
<component
:is="
currentModel.status === 'ERROR' || currentModel.status === 'PAUSE_DOWNLOAD'
? 'RefreshRight'
: 'EditPen'
"
/>
</el-icon>
</el-button>
</el-tooltip>
@ -111,27 +112,6 @@ const errMessage = computed(() => {
}
return ''
})
// const progress = computed(() => {
// if (currentModel.value) {
// const down_model_chunk = currentModel.value.meta['down_model_chunk']
// if (down_model_chunk) {
// const maxObj = down_model_chunk
// .filter((chunk: any) => chunk.index > 1)
// .reduce(
// (prev: any, current: any) => {
// return (prev.index || 0) > (current.index || 0) ? prev : current
// },
// { progress: 0 }
// )
// if (maxObj) {
// return parseFloat(maxObj.progress?.toFixed(1))
// }
// return 0
// }
// return 0
// }
// return 0
// })
const emit = defineEmits(['change', 'update:model'])
const eidtModelRef = ref<InstanceType<typeof EditModel>>()
let interval: any
@ -148,7 +128,12 @@ const deleteModel = () => {
.catch(() => {})
}
const cancelDownload = () => {}
const cancelDownload = () => {
ModelApi.pauseDownload(props.model.id).then(() => {
downModel.value = undefined
emit('change')
})
}
const openEditModel = () => {
const provider = props.provider_list.find((p) => p.provider === props.model.provider)
if (provider) {