import { PageAction } from '@/config'; import { PageActionType } from '@/config/types'; import { queryMyModels } from '@/pages/llmodels/apis'; import { SelectPanel, useAppUtils } from '@gpustack/core-ui'; import { useIntl } from '@umijs/max'; import { Checkbox, Divider, Form, Radio } from 'antd'; import { useEffect, useState } from 'react'; import styled from 'styled-components'; import { accessScopeOptions } from '../../config'; import { FormData, ListItem } from '../../config/types'; const Label = styled.div` font-weight: 500; margin-block: -8px 12px; font-size: 14px; margin-left: 4px; `; const AllowModelsForm: React.FC<{ currentData?: Partial | null; action: PageActionType; onValuesChange?: (changedValues: any, allValues: any) => void; }> = ({ currentData, action, onValuesChange }) => { const intl = useIntl(); const { getRuleMessage } = useAppUtils(); const form = Form.useFormInstance(); const allowedModelNames = Form.useWatch( 'allowed_model_names', form ) as string[]; const allowedType = Form.useWatch('allowed_type', form); const scope = Form.useWatch('scope', form) as string[]; const [modelList, setModelList] = useState<{ key: string; title: string }[]>( [] ); const getModelList = async () => { try { const res = await queryMyModels({ page: -1 }); const options = res.items.map((item) => item.name); if (action === PageAction.EDIT && currentData) { const list = new Set([ ...options, ...(currentData.allowed_model_names?.map((item) => item) || []) ]); setModelList( Array.from(list).map((item) => ({ key: item, title: item })) ); } else { setModelList(options.map((item) => ({ key: item, title: item }))); } } catch (error) {} }; const handleAllowTypeChange = (e: any) => { const value = e.target.value; onValuesChange?.({ allowed_type: value }, form.getFieldsValue()); }; const handleOnScopeChange = (checkedValues: any) => { console.log('checkedValues', form.getFieldValue('allowed_type')); }; useEffect(() => { getModelList(); }, [action, currentData]); return (
name="scope" style={{ marginBottom: 8 }}> ({ label: intl.formatMessage({ id: item.label }), value: item.value }))} onChange={handleOnScopeChange} > {scope?.includes('inference') && (
{allowedType === 'custom' && ( { form.setFieldsValue({ allowed_model_names: selectedKeys || [] }); onValuesChange?.( { allowed_model_names: selectedKeys || [] }, form.getFieldsValue() ); }} /> )}
)}
); }; export default AllowModelsForm;