feat: 支持向量模型
This commit is contained in:
parent
8dc426664f
commit
f372095f51
@ -22,6 +22,8 @@ class Status(models.TextChoices):
|
|||||||
|
|
||||||
DOWNLOAD = "DOWNLOAD", '下载中'
|
DOWNLOAD = "DOWNLOAD", '下载中'
|
||||||
|
|
||||||
|
PAUSE_DOWNLOAD = "PAUSE_DOWNLOAD", '暂停下载'
|
||||||
|
|
||||||
|
|
||||||
class PermissionType(models.TextChoices):
|
class PermissionType(models.TextChoices):
|
||||||
PUBLIC = "PUBLIC", '公开'
|
PUBLIC = "PUBLIC", '公开'
|
||||||
|
|||||||
@ -38,6 +38,9 @@ class ModelPullManage:
|
|||||||
for chunk in response:
|
for chunk in response:
|
||||||
down_model_chunk[chunk.digest] = chunk.to_dict()
|
down_model_chunk[chunk.digest] = chunk.to_dict()
|
||||||
if time.time() - timestamp > 5:
|
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(
|
QuerySet(Model).filter(id=model.id).update(
|
||||||
meta={"down_model_chunk": list(down_model_chunk.values())})
|
meta={"down_model_chunk": list(down_model_chunk.values())})
|
||||||
timestamp = time.time()
|
timestamp = time.time()
|
||||||
@ -238,6 +241,12 @@ class ModelSerializer(serializers.Serializer):
|
|||||||
QuerySet(Model).filter(id=self.data.get('id')).delete()
|
QuerySet(Model).filter(id=self.data.get('id')).delete()
|
||||||
return True
|
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):
|
def edit(self, instance: Dict, user_id: str, with_valid=True):
|
||||||
if with_valid:
|
if with_valid:
|
||||||
self.is_valid(raise_exception=True)
|
self.is_valid(raise_exception=True)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ urlpatterns = [
|
|||||||
name="provider/model_form"),
|
name="provider/model_form"),
|
||||||
path('model', views.Model.as_view(), name='model'),
|
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>', 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('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('email_setting', views.SystemSetting.Email.as_view(), name='email_setting'),
|
||||||
path('valid/<str:valid_type>/<int:valid_count>', views.Valid.as_view())
|
path('valid/<str:valid_type>/<int:valid_count>', views.Valid.as_view())
|
||||||
|
|||||||
@ -69,6 +69,18 @@ class Model(APIView):
|
|||||||
return result.success(
|
return result.success(
|
||||||
ModelSerializer.Operate(data={'id': model_id, 'user_id': request.user.id}).one_meta(with_valid=True))
|
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):
|
class Operate(APIView):
|
||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|
||||||
|
|||||||
@ -130,7 +130,18 @@ const getModelMetaById: (model_id: string, loading?: Ref<boolean>) => Promise<Re
|
|||||||
) => {
|
) => {
|
||||||
return get(`${prefix}/${model_id}/meta`, {}, loading)
|
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>> = (
|
const deleteModel: (model_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
|
||||||
model_id,
|
model_id,
|
||||||
loading
|
loading
|
||||||
@ -147,5 +158,6 @@ export default {
|
|||||||
updateModel,
|
updateModel,
|
||||||
deleteModel,
|
deleteModel,
|
||||||
getModelById,
|
getModelById,
|
||||||
getModelMetaById
|
getModelMetaById,
|
||||||
|
pauseDownload
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ interface Model {
|
|||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
*/
|
*/
|
||||||
status: 'SUCCESS' | 'DOWNLOAD' | 'ERROR'
|
status: 'SUCCESS' | 'DOWNLOAD' | 'ERROR' | 'PAUSE_DOWNLOAD'
|
||||||
/**
|
/**
|
||||||
* 元数据
|
* 元数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -21,6 +21,12 @@
|
|||||||
<el-icon class="danger ml-4" size="20"><Warning /></el-icon>
|
<el-icon class="danger ml-4" size="20"><Warning /></el-icon>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -39,17 +45,6 @@
|
|||||||
<!-- progress -->
|
<!-- progress -->
|
||||||
<div class="progress-mask" v-if="currentModel.status === 'DOWNLOAD'">
|
<div class="progress-mask" v-if="currentModel.status === 'DOWNLOAD'">
|
||||||
<DownloadLoading class="percentage" />
|
<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">
|
<div class="percentage-label flex-center">
|
||||||
正在下载中 <span class="dotting"></span>
|
正在下载中 <span class="dotting"></span>
|
||||||
@ -64,7 +59,13 @@
|
|||||||
<el-tooltip effect="dark" content="修改" placement="top">
|
<el-tooltip effect="dark" content="修改" placement="top">
|
||||||
<el-button text @click.stop="openEditModel">
|
<el-button text @click.stop="openEditModel">
|
||||||
<el-icon>
|
<el-icon>
|
||||||
<component :is="currentModel.status === 'ERROR' ? 'RefreshRight' : 'EditPen'" />
|
<component
|
||||||
|
:is="
|
||||||
|
currentModel.status === 'ERROR' || currentModel.status === 'PAUSE_DOWNLOAD'
|
||||||
|
? 'RefreshRight'
|
||||||
|
: 'EditPen'
|
||||||
|
"
|
||||||
|
/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
@ -111,27 +112,6 @@ const errMessage = computed(() => {
|
|||||||
}
|
}
|
||||||
return ''
|
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 emit = defineEmits(['change', 'update:model'])
|
||||||
const eidtModelRef = ref<InstanceType<typeof EditModel>>()
|
const eidtModelRef = ref<InstanceType<typeof EditModel>>()
|
||||||
let interval: any
|
let interval: any
|
||||||
@ -148,7 +128,12 @@ const deleteModel = () => {
|
|||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
const cancelDownload = () => {}
|
const cancelDownload = () => {
|
||||||
|
ModelApi.pauseDownload(props.model.id).then(() => {
|
||||||
|
downModel.value = undefined
|
||||||
|
emit('change')
|
||||||
|
})
|
||||||
|
}
|
||||||
const openEditModel = () => {
|
const openEditModel = () => {
|
||||||
const provider = props.provider_list.find((p) => p.provider === props.model.provider)
|
const provider = props.provider_list.find((p) => p.provider === props.model.provider)
|
||||||
if (provider) {
|
if (provider) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user