-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathModelCard.vue
More file actions
331 lines (308 loc) · 10.2 KB
/
ModelCard.vue
File metadata and controls
331 lines (308 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<template>
<card-box :title="model.name" shadow="hover" class="model-card">
<template #icon>
<span style="height: 32px; width: 32px" :innerHTML="icon"></span>
</template>
<template #title>
<div class="flex" style="height: 22px">
<span class="ellipsis-1 mb-4" :title="model.name" style="max-width: 80%">
{{ model.name }}
</span>
<span v-if="currentModel.status === 'ERROR'">
<el-tooltip effect="dark" :content="errMessage" placement="top">
<el-icon class="color-danger ml-4" size="18"><WarningFilled /></el-icon>
</el-tooltip>
</span>
<span v-if="currentModel.status === 'PAUSE_DOWNLOAD'">
<el-tooltip
effect="dark"
:content="`${$t('views.model.modelForm.base_model.label')}: ${props.model.model_name} ${$t('views.model.tip.downloadError')}`"
placement="top"
>
<el-icon class="color-danger ml-4" size="18"><WarningFilled /></el-icon>
</el-tooltip>
</span>
</div>
</template>
<template #subTitle>
<el-text class="color-secondary lighter" size="small">
{{ $t('common.creator') }}: {{ model.nick_name }}
</el-text>
</template>
<template #tag>
<el-tag v-if="isShared || isSystemShare" type="info" class="info-tag">
{{ t('views.shared.title') }}
</el-tag>
</template>
<ul>
<li class="flex mb-4">
<el-text type="info" class="color-secondary"
>{{ $t('views.model.modelForm.model_type.label') }}
</el-text>
<span class="ellipsis ml-16">
{{ $t(modelType[model.model_type as keyof typeof modelType]) }}</span
>
</li>
<li class="flex">
<el-text type="info" class="color-secondary"
>{{ $t('views.model.modelForm.base_model.label') }}
</el-text>
<span class="ellipsis-1 ml-16" style="height: 20px; width: 70%">
{{ model.model_name }}</span
>
</li>
</ul>
<!-- progress -->
<div class="progress-mask" v-if="currentModel.status === 'DOWNLOAD'">
<DownloadLoading class="percentage" />
<div class="percentage-label flex-center">
{{ $t('views.model.download.downloading') }} <span class="dotting"></span>
<el-button link type="primary" class="ml-16" @click.stop="cancelDownload"
>{{ $t('views.model.download.cancelDownload') }}
</el-button>
</div>
</div>
<template #mouseEnter v-if="MoreFilledPermission(model.id)">
<el-dropdown trigger="click" v-if="!isShared">
<el-button text @click.stop>
<AppIcon iconName="app-more"></AppIcon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-if="permissionPrecise.modify(model.id)"
text
@click.stop="openEditModel"
>
<AppIcon iconName="app-edit" class="color-secondary"></AppIcon>
{{ $t('common.edit') }}
</el-dropdown-item>
<el-dropdown-item
v-if="isSystemShare"
@click.stop="openAuthorizedWorkspaceDialog(model)"
>
<AppIcon iconName="app-lock" class="color-secondary"></AppIcon>
{{ $t('views.shared.authorized_workspace') }}
</el-dropdown-item>
<el-dropdown-item
v-if="
(currentModel.model_type === 'TTS' ||
currentModel.model_type === 'STT' ||
currentModel.model_type === 'LLM' ||
currentModel.model_type === 'IMAGE' ||
currentModel.model_type === 'TTI' ||
currentModel.model_type === 'ITV' ||
currentModel.model_type === 'EMBEDDING' ||
currentModel.model_type === 'TTV') &&
permissionPrecise.paramSetting(model.id)
"
@click.stop="openParamSetting"
>
<AppIcon iconName="app-setting" class="color-secondary"></AppIcon>
{{ $t('views.model.modelForm.title.paramSetting') }}
</el-dropdown-item>
<el-dropdown-item @click.stop="openAuthorization(model)" v-if="apiType === 'workspace' && permissionPrecise.auth(model.id)">
<AppIcon iconName="app-resource-authorization" class="color-secondary"></AppIcon>
{{ $t('views.system.resourceAuthorization.title') }}
</el-dropdown-item>
<el-dropdown-item
divided
text
@click.stop="deleteModel"
v-if="permissionPrecise.delete(model.id)"
>
<AppIcon iconName="app-delete" class="color-secondary"></AppIcon>
{{ $t('common.delete') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
<EditModel ref="editModelRef" @submit="emit('change')"></EditModel>
<ParamSettingDialog ref="paramSettingRef" />
<AuthorizedWorkspace
ref="AuthorizedWorkspaceDialogRef"
v-if="isSystemShare"
></AuthorizedWorkspace>
<ResourceAuthorizationDrawer
:type="SourceTypeEnum.MODEL"
ref="ResourceAuthorizationDrawerRef"
v-if="apiType === 'workspace'"
/>
</card-box>
</template>
<script setup lang="ts">
import type { Provider, Model } from '@/api/type/model'
import { computed, ref, onMounted, onBeforeUnmount } from 'vue'
import EditModel from '@/views/model/component/EditModel.vue'
import DownloadLoading from '@/components/loading/DownloadLoading.vue'
import { MsgConfirm, MsgSuccess } from '@/utils/message'
import { modelType } from '@/enums/model'
import ParamSettingDialog from './ParamSettingDialog.vue'
import AuthorizedWorkspace from '@/views/system-shared/AuthorizedWorkspaceDialog.vue'
import ResourceAuthorizationDrawer from '@/components/resource-authorization-drawer/index.vue'
import { SourceTypeEnum } from '@/enums/common'
import { t } from '@/locales'
import permissionMap from '@/permission'
import { useRoute } from 'vue-router'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
const route = useRoute()
const props = defineProps<{
model: Model
provider_list: Array<Provider>
updateModelById: (model_id: string, model: Model) => void
isShared?: boolean | undefined
isSystemShare?: boolean | undefined
apiType: 'systemShare' | 'workspace' | 'systemManage'
}>()
const isSystemShare = computed(() => {
return props.apiType === 'systemShare'
})
const permissionPrecise = computed(() => {
return permissionMap['model'][props.apiType]
})
const MoreFilledPermission = (id: any) => {
return (
permissionPrecise.value.modify(id) ||
permissionPrecise.value.delete(id) ||
permissionPrecise.value.auth(id) ||
isSystemShare.value
)
}
const ResourceAuthorizationDrawerRef = ref()
function openAuthorization(item: any) {
ResourceAuthorizationDrawerRef.value.open(item.id)
}
const downModel = ref<Model>()
const currentModel = computed(() => {
if (downModel.value) {
return downModel.value
} else {
return props.model
}
})
const errMessage = computed(() => {
if (currentModel.value.meta && currentModel.value.meta.message) {
if (currentModel.value.meta.message === 'pull model manifest: file does not exist') {
return `${currentModel.value.model_name} ${t('views.model.tip.noModel')}`
}
return currentModel.value.meta.message
}
return ''
})
const emit = defineEmits(['change', 'update:model'])
const editModelRef = ref<InstanceType<typeof EditModel>>()
let interval: any
const deleteModel = () => {
MsgConfirm(
`${t('views.model.delete.confirmTitle')}${props.model.name} ?`,
t('views.model.delete.confirmMessage'),
{
confirmButtonText: t('common.confirm'),
confirmButtonClass: 'danger',
},
)
.then(() => {
loadSharedApi({ type: 'model', systemType: props.apiType })
.deleteModel(props.model.id)
.then(() => {
emit('change')
MsgSuccess(t('common.deleteSuccess'))
})
})
.catch(() => {})
}
const cancelDownload = () => {
loadSharedApi({ type: 'model', systemType: props.apiType })
.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) {
editModelRef.value?.open(provider, props.model)
}
}
const icon = computed(() => {
return props.provider_list.find((p) => p.provider === props.model.provider)?.icon
})
/**
* 初始化轮询
*/
const initInterval = () => {
interval = setInterval(() => {
if (currentModel.value.status === 'DOWNLOAD') {
loadSharedApi({ type: 'model', systemType: props.apiType })
.getModelMetaById(props.model.id)
.then((ok: any) => {
downModel.value = ok.data
})
} else {
if (downModel.value) {
props.updateModelById(props.model.id, downModel.value)
downModel.value = undefined
}
}
}, 6000)
}
/**
* 关闭轮询
*/
const closeInterval = () => {
if (interval) {
clearInterval(interval)
}
}
const paramSettingRef = ref<InstanceType<typeof ParamSettingDialog>>()
const openParamSetting = () => {
paramSettingRef.value?.open(props.model)
}
const AuthorizedWorkspaceDialogRef = ref()
function openAuthorizedWorkspaceDialog(row: any) {
if (AuthorizedWorkspaceDialogRef.value) {
AuthorizedWorkspaceDialogRef.value.open(row, 'Model')
}
}
onMounted(() => {
initInterval()
})
onBeforeUnmount(() => {
// 清除定时任务
closeInterval()
})
</script>
<style lang="scss" scoped>
.model-card {
min-height: 135px;
min-width: auto;
.operation-button {
position: absolute;
right: 12px;
bottom: 12px;
height: auto;
}
.progress-mask {
position: absolute;
top: 0;
left: 0;
background-color: rgba(255, 255, 255, 0.9);
width: 100%;
height: 100%;
z-index: 99;
text-align: center;
.percentage {
margin-top: 55px;
margin-bottom: 16px;
}
.percentage-label {
margin-top: 50px;
margin-left: 10px;
font-size: 13px;
color: var(--app-text-color-secondary);
}
}
}
</style>