|
|
|
@@ -1,7 +1,12 @@ |
|
|
|
import editExperimentIcon from '@/assets/img/edit-experiment.png'; |
|
|
|
import KFModal from '@/components/KFModal'; |
|
|
|
import { DataSource, ResourceVersionData, type ResourceData } from '@/pages/Dataset/config'; |
|
|
|
import { addModelVersion, getModelList, getModelVersionList } from '@/services/dataset'; |
|
|
|
import { |
|
|
|
DataSource, |
|
|
|
ResourceType, |
|
|
|
ResourceVersionData, |
|
|
|
resourceConfig, |
|
|
|
type ResourceData, |
|
|
|
} from '@/pages/Dataset/config'; |
|
|
|
import { to } from '@/utils/promise'; |
|
|
|
import { InfoCircleOutlined } from '@ant-design/icons'; |
|
|
|
import { Form, Input, ModalProps, Select } from 'antd'; |
|
|
|
@@ -15,20 +20,8 @@ type FormData = { |
|
|
|
version_desc: string; |
|
|
|
}; |
|
|
|
|
|
|
|
// type ExportModelResponce = { |
|
|
|
// fileName: string; |
|
|
|
// fileSize: string; |
|
|
|
// url: string; |
|
|
|
// }; |
|
|
|
|
|
|
|
// type CreateModelVersionParams = FormData & { |
|
|
|
// file_name: string; |
|
|
|
// file_size: string; |
|
|
|
// url: string; |
|
|
|
// // name: string; |
|
|
|
// }; |
|
|
|
|
|
|
|
interface ExportModelModalProps extends Omit<ModalProps, 'onOk'> { |
|
|
|
resourceType: ResourceType; |
|
|
|
pipelineId: number; // 流水线 id |
|
|
|
experimentId: number; // 实验 id |
|
|
|
experimentName: string; // 实验 name |
|
|
|
@@ -39,6 +32,7 @@ interface ExportModelModalProps extends Omit<ModalProps, 'onOk'> { |
|
|
|
} |
|
|
|
|
|
|
|
function ExportModelModal({ |
|
|
|
resourceType, |
|
|
|
pipelineId, |
|
|
|
experimentId, |
|
|
|
experimentName, |
|
|
|
@@ -49,9 +43,9 @@ function ExportModelModal({ |
|
|
|
...rest |
|
|
|
}: ExportModelModalProps) { |
|
|
|
const [form] = Form.useForm(); |
|
|
|
const [models, setModels] = useState<ResourceData[]>([]); |
|
|
|
const [resources, setResources] = useState<ResourceData[]>([]); |
|
|
|
const [versions, setVersions] = useState<ResourceVersionData[]>([]); |
|
|
|
// const [uuid] = useState(Date.now()); |
|
|
|
const config = resourceConfig[resourceType]; |
|
|
|
|
|
|
|
const layout = { |
|
|
|
labelCol: { span: 24 }, |
|
|
|
@@ -59,57 +53,57 @@ function ExportModelModal({ |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
requestModelList(); |
|
|
|
requestResourceList(); |
|
|
|
}, []); |
|
|
|
|
|
|
|
// 获取选中的模型 |
|
|
|
const getSelectedModel = (id: number | undefined) => { |
|
|
|
// 获取选中的数据集、模型 |
|
|
|
const getSelectedResource = (id: number | undefined) => { |
|
|
|
if (id) { |
|
|
|
return models.find((item) => item.id === id); |
|
|
|
return resources.find((item) => item.id === id); |
|
|
|
} |
|
|
|
return undefined; |
|
|
|
}; |
|
|
|
|
|
|
|
// 模型版本 tooltip |
|
|
|
// 版本 tooltip |
|
|
|
const getTooltip = () => { |
|
|
|
const id = form.getFieldValue('id'); |
|
|
|
const model = getSelectedModel(id); |
|
|
|
const name = model?.name ?? ''; |
|
|
|
const resource = getSelectedResource(id); |
|
|
|
const name = resource?.name ?? ''; |
|
|
|
const versionNames = versions.map((item: ResourceVersionData) => item.name).join('、'); |
|
|
|
const tooltip = |
|
|
|
versions.length > 0 ? `${name}有以下版本:\n${versionNames}\n注意不能重复` : undefined; |
|
|
|
return tooltip; |
|
|
|
}; |
|
|
|
|
|
|
|
// 处理模型名称变化 |
|
|
|
const handleModelChange = (id: number | undefined) => { |
|
|
|
// 处理数据集、模型选择变化 |
|
|
|
const handleResourceChange = (id: number | undefined) => { |
|
|
|
if (id) { |
|
|
|
getModelVersions(id); |
|
|
|
getRecourceVersions(id); |
|
|
|
} else { |
|
|
|
setVersions([]); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 获取模型列表 |
|
|
|
const requestModelList = async () => { |
|
|
|
// 获取数据集、模型列表 |
|
|
|
const requestResourceList = async () => { |
|
|
|
const params = { |
|
|
|
page: 0, |
|
|
|
size: 1000, |
|
|
|
is_public: false, // 个人 |
|
|
|
}; |
|
|
|
const [res] = await to(getModelList(params)); |
|
|
|
const [res] = await to(config.getList(params)); |
|
|
|
if (res && res.data) { |
|
|
|
setModels(res.data.content || []); |
|
|
|
setResources(res.data.content || []); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 获取模型版本列表 |
|
|
|
const getModelVersions = async (id: number) => { |
|
|
|
const model = getSelectedModel(id); |
|
|
|
if (!model) { |
|
|
|
// 获取数据集、模型版本列表 |
|
|
|
const getRecourceVersions = async (id: number) => { |
|
|
|
const resource = getSelectedResource(id); |
|
|
|
if (!resource) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const [res] = await to(getModelVersionList(pick(model, ['identifier', 'owner']))); |
|
|
|
const [res] = await to(config.getVersions(pick(resource, ['identifier', 'owner']))); |
|
|
|
if (res && res.data) { |
|
|
|
setVersions(res.data); |
|
|
|
} |
|
|
|
@@ -117,17 +111,17 @@ function ExportModelModal({ |
|
|
|
|
|
|
|
// 提交 |
|
|
|
const hanldeFinish = (formData: FormData) => { |
|
|
|
exportToModel(formData); |
|
|
|
exportToResource(formData); |
|
|
|
}; |
|
|
|
|
|
|
|
// 导出到模型 |
|
|
|
const exportToModel = async (formData: FormData) => { |
|
|
|
// 导出到数据集、模型 |
|
|
|
const exportToResource = async (formData: FormData) => { |
|
|
|
const id = form.getFieldValue('id'); |
|
|
|
const model = getSelectedModel(id); |
|
|
|
const resource = getSelectedResource(id); |
|
|
|
const params = { |
|
|
|
...formData, |
|
|
|
identifier: model?.identifier, |
|
|
|
name: model?.name, |
|
|
|
identifier: resource?.identifier, |
|
|
|
name: resource?.name, |
|
|
|
model_source: DataSource.HandExport, |
|
|
|
train_task: { |
|
|
|
workflow_id: pipelineId, |
|
|
|
@@ -142,7 +136,7 @@ function ExportModelModal({ |
|
|
|
}, |
|
|
|
], |
|
|
|
}; |
|
|
|
const [res] = await to(addModelVersion(params)); |
|
|
|
const [res] = await to(config.addVersion(params)); |
|
|
|
if (res) { |
|
|
|
onOk(); |
|
|
|
} |
|
|
|
@@ -151,7 +145,7 @@ function ExportModelModal({ |
|
|
|
return ( |
|
|
|
<KFModal |
|
|
|
{...rest} |
|
|
|
title="导出到模型库" |
|
|
|
title={`导出到${config.name}`} |
|
|
|
image={editExperimentIcon} |
|
|
|
okButtonProps={{ |
|
|
|
htmlType: 'submit', |
|
|
|
@@ -170,17 +164,21 @@ function ExportModelModal({ |
|
|
|
labelAlign="left" |
|
|
|
labelWrap |
|
|
|
> |
|
|
|
<Form.Item label="模型名称" name="id" rules={[{ required: true, message: '请选择模型' }]}> |
|
|
|
<Form.Item |
|
|
|
label={`${config.name}名称`} |
|
|
|
name="id" |
|
|
|
rules={[{ required: true, message: `请选择${config.name}` }]} |
|
|
|
> |
|
|
|
<Select |
|
|
|
placeholder="请选择模型" |
|
|
|
onChange={handleModelChange} |
|
|
|
options={models} |
|
|
|
placeholder={`请选择${config.name}`} |
|
|
|
onChange={handleResourceChange} |
|
|
|
options={resources} |
|
|
|
fieldNames={{ label: 'name', value: 'id' }} |
|
|
|
allowClear |
|
|
|
></Select> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
label="模型版本" |
|
|
|
label={`${config.name}版本`} |
|
|
|
name="version" |
|
|
|
tooltip={ |
|
|
|
getTooltip() |
|
|
|
@@ -192,11 +190,11 @@ function ExportModelModal({ |
|
|
|
: undefined |
|
|
|
} |
|
|
|
rules={[ |
|
|
|
{ required: true, message: '请输入模型版本' }, |
|
|
|
{ required: true, message: `请输入${config.name}版本` }, |
|
|
|
{ |
|
|
|
validator: (_, value) => { |
|
|
|
if (value && versions.map((item) => item.name).includes(value)) { |
|
|
|
return Promise.reject('模型版本已存在'); |
|
|
|
return Promise.reject(`${config.name}版本已存在`); |
|
|
|
} else { |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
@@ -204,7 +202,7 @@ function ExportModelModal({ |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input placeholder="请输入模型版本" maxLength={64} showCount allowClear /> |
|
|
|
<Input placeholder={`请输入${config.name}版本`} maxLength={64} showCount allowClear /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
label="版本描述" |
|
|
|
|