You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

create.tsx 8.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * @Author: 赵伟
  3. * @Date: 2024-04-16 13:58:08
  4. * @Description: 创建模型部署
  5. */
  6. import PageTitle from '@/components/PageTitle';
  7. import SubAreaTitle from '@/components/SubAreaTitle';
  8. import { CommonTabKeys } from '@/enums';
  9. import { createMirrorReq } from '@/services/mirror';
  10. import { getComputingResourceReq } from '@/services/pipeline';
  11. import { to } from '@/utils/promise';
  12. import { getSessionItemThenRemove, mirrorNameKey } from '@/utils/sessionStorage';
  13. import { validateUploadFiles } from '@/utils/ui';
  14. import { useNavigate } from '@umijs/max';
  15. import { Button, Col, Form, Input, Row, Select, UploadFile, message, type SelectProps } from 'antd';
  16. import { omit } from 'lodash';
  17. import { useEffect, useState } from 'react';
  18. import styles from './create.less';
  19. type FormData = {
  20. name: string;
  21. tag: string;
  22. description: string;
  23. path?: string;
  24. upload_type: string;
  25. fileList?: UploadFile[];
  26. };
  27. function ModelDeploymentCreate() {
  28. const navgite = useNavigate();
  29. const [form] = Form.useForm();
  30. const [nameDisabled, setNameDisabled] = useState(false);
  31. const [resourceStandardList, setResourceStandardList] = useState([]);
  32. useEffect(() => {
  33. const name = getSessionItemThenRemove(mirrorNameKey);
  34. if (name) {
  35. form.setFieldValue('name', name);
  36. setNameDisabled(true);
  37. }
  38. getComputingResource();
  39. }, []);
  40. const getComputingResource = async () => {
  41. const params = {
  42. page: 0,
  43. size: 1000,
  44. resource_type: '',
  45. };
  46. const [res] = await to(getComputingResourceReq(params));
  47. if (res && res.data && res.data.content) {
  48. setResourceStandardList(res.data.content);
  49. }
  50. };
  51. const filterResourceStandard: SelectProps['filterOption'] = (
  52. input: string,
  53. { computing_resource = '' },
  54. ) => {
  55. return computing_resource.toLocaleLowerCase().includes(input.toLocaleLowerCase());
  56. };
  57. // 创建公网、本地镜像
  58. const createPublicMirror = async (formData: FormData) => {
  59. const upload_type = formData['upload_type'];
  60. let params;
  61. if (upload_type === CommonTabKeys.Public) {
  62. params = {
  63. ...omit(formData, ['upload_type']),
  64. upload_type: 0,
  65. image_type: 0,
  66. };
  67. } else {
  68. const fileList = formData['fileList'] ?? [];
  69. if (validateUploadFiles(fileList)) {
  70. const file = fileList[0];
  71. params = {
  72. ...omit(formData, ['fileList', 'upload_type']),
  73. path: file.response.data.url,
  74. file_size: file.response.data.fileSize,
  75. upload_type: 1,
  76. image_type: 0,
  77. };
  78. }
  79. }
  80. const [res] = await to(createMirrorReq(params));
  81. if (res) {
  82. message.success('创建成功');
  83. navgite(-1);
  84. }
  85. };
  86. // 提交
  87. const handleSubmit = (values: FormData) => {
  88. createPublicMirror(values);
  89. };
  90. // 取消
  91. const cancel = () => {
  92. navgite(-1);
  93. };
  94. return (
  95. <div className={styles['model-deployment-create']}>
  96. <PageTitle title="创建推理服务"></PageTitle>
  97. <div className={styles['model-deployment-create__content']}>
  98. <div>
  99. <Form
  100. name="model-deployment-create"
  101. labelCol={{ flex: '130px' }}
  102. wrapperCol={{ flex: 1 }}
  103. labelAlign="left"
  104. form={form}
  105. initialValues={{ upload_type: CommonTabKeys.Public }}
  106. onFinish={handleSubmit}
  107. size="large"
  108. >
  109. <SubAreaTitle
  110. title="基本信息"
  111. image={require('@/assets/img/mirror-basic.png')}
  112. style={{ marginBottom: '26px' }}
  113. ></SubAreaTitle>
  114. <Row gutter={10}>
  115. <Col span={10}>
  116. <Form.Item
  117. label="服务名称"
  118. name="name"
  119. rules={[
  120. {
  121. required: true,
  122. message: '请输入服务名称',
  123. },
  124. ]}
  125. >
  126. <Input
  127. placeholder="请输入服务名称"
  128. maxLength={64}
  129. disabled={nameDisabled}
  130. showCount
  131. allowClear
  132. />
  133. </Form.Item>
  134. </Col>
  135. </Row>
  136. <Row gutter={10}>
  137. <Col span={20}>
  138. <Form.Item
  139. label="描  述"
  140. name="description"
  141. rules={[
  142. {
  143. required: true,
  144. message: '请输入描述',
  145. },
  146. ]}
  147. >
  148. <Input.TextArea
  149. autoSize={{ minRows: 2, maxRows: 6 }}
  150. placeholder="请输入描述,最长128字符"
  151. maxLength={128}
  152. showCount
  153. allowClear
  154. />
  155. </Form.Item>
  156. </Col>
  157. </Row>
  158. <SubAreaTitle
  159. title="部署构建"
  160. image={require('@/assets/img/mirror-version.png')}
  161. style={{ marginTop: '20px', marginBottom: '24px' }}
  162. ></SubAreaTitle>
  163. <Row gutter={10}>
  164. <Col span={10}>
  165. <Form.Item
  166. label="选择模型"
  167. name="name"
  168. rules={[
  169. {
  170. required: true,
  171. message: '请输入模型',
  172. },
  173. ]}
  174. >
  175. <Input
  176. placeholder="请输入模型"
  177. maxLength={64}
  178. disabled={nameDisabled}
  179. showCount
  180. allowClear
  181. />
  182. </Form.Item>
  183. </Col>
  184. </Row>
  185. <Row gutter={10}>
  186. <Col span={10}>
  187. <Form.Item
  188. label="选择镜像"
  189. name="name"
  190. rules={[
  191. {
  192. required: true,
  193. message: '请输入镜像',
  194. },
  195. ]}
  196. >
  197. <Input
  198. placeholder="请输入镜像"
  199. maxLength={64}
  200. disabled={nameDisabled}
  201. showCount
  202. allowClear
  203. />
  204. </Form.Item>
  205. </Col>
  206. </Row>
  207. <Row gutter={10}>
  208. <Col span={10}>
  209. <Form.Item
  210. label="资源规格"
  211. name="name"
  212. rules={[
  213. {
  214. required: true,
  215. message: '请选择资源规格',
  216. },
  217. ]}
  218. >
  219. <Select
  220. showSearch
  221. placeholder="请选择资源规格"
  222. filterOption={filterResourceStandard}
  223. options={resourceStandardList}
  224. fieldNames={{
  225. label: 'description',
  226. value: 'standard',
  227. }}
  228. />
  229. </Form.Item>
  230. </Col>
  231. </Row>
  232. <Row gutter={10}>
  233. <Col span={10}>
  234. <Form.Item
  235. label="副本数量"
  236. name="name"
  237. rules={[
  238. {
  239. required: true,
  240. message: '请输入副本数量',
  241. },
  242. ]}
  243. >
  244. <Input
  245. placeholder="请输入副本数量"
  246. maxLength={64}
  247. disabled={nameDisabled}
  248. showCount
  249. allowClear
  250. />
  251. </Form.Item>
  252. </Col>
  253. </Row>
  254. <Row gutter={10}>
  255. <Col span={10}>
  256. <Form.Item label="环境变量" name="name">
  257. <Button type="link" style={{ padding: '0' }}>
  258. 添加环境变量
  259. </Button>
  260. </Form.Item>
  261. </Col>
  262. </Row>
  263. <Form.Item wrapperCol={{ offset: 0, span: 16 }}>
  264. <Button type="primary" htmlType="submit">
  265. 确定
  266. </Button>
  267. <Button
  268. type="default"
  269. htmlType="button"
  270. onClick={cancel}
  271. style={{ marginLeft: '20px' }}
  272. >
  273. 取消
  274. </Button>
  275. </Form.Item>
  276. </Form>
  277. </div>
  278. </div>
  279. </div>
  280. );
  281. }
  282. export default ModelDeploymentCreate;