fix: ollama model change trigger check action
This commit is contained in:
@@ -184,6 +184,19 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
||||
onValuesChange?.({}, form.getFieldsValue());
|
||||
};
|
||||
|
||||
const handleScheduleTypeChange = (value: string) => {
|
||||
if (value === 'auto') {
|
||||
onValuesChange?.({}, form.getFieldsValue());
|
||||
}
|
||||
};
|
||||
|
||||
const handleGpuSelectorChange = (value: any[] | string) => {
|
||||
if (!value?.length || !value) {
|
||||
return;
|
||||
}
|
||||
onValuesChange?.({}, form.getFieldsValue());
|
||||
};
|
||||
|
||||
const collapseItems = useMemo(() => {
|
||||
const children = (
|
||||
<>
|
||||
@@ -198,6 +211,7 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
||||
</Form.Item>
|
||||
<Form.Item name="scheduleType">
|
||||
<SealSelect
|
||||
onChange={handleScheduleTypeChange}
|
||||
label={intl.formatMessage({ id: 'models.form.scheduletype' })}
|
||||
description={<TooltipList list={scheduleTypeTips}></TooltipList>}
|
||||
options={[
|
||||
@@ -301,6 +315,7 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
|
||||
value={form.getFieldValue(['gpu_selector', 'gpu_ids'])}
|
||||
optionNode={GPUCard}
|
||||
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
||||
onChange={handleGpuSelectorChange}
|
||||
></SealCascader>
|
||||
</Form.Item>
|
||||
</>
|
||||
|
||||
@@ -146,6 +146,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
||||
|
||||
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
||||
const fieldName = Object.keys(changedValues)[0];
|
||||
console.log('handleOnValuesChange', fieldName, changedValues, allValues);
|
||||
if (excludeFields.includes(fieldName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,13 +99,21 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
const [isGGUF, setIsGGUF] = useState<boolean>(props.isGGUF || false);
|
||||
const modelFileRef = useRef<any>(null);
|
||||
|
||||
const getCategory = (item: any) => {
|
||||
const categories = item.evaluateResult?.default_spec?.categories || [];
|
||||
if (Array.isArray(categories)) {
|
||||
return categories?.[0] || null;
|
||||
}
|
||||
return categories || null;
|
||||
};
|
||||
const handleSelectModelFile = (item: any) => {
|
||||
form.current?.form?.resetFields(resetFields);
|
||||
const modelInfo = onSelectModel(selectedModel, props.source);
|
||||
form.current?.setFieldsValue?.({
|
||||
file_name: item.fakeName,
|
||||
...item.evaluateResult?.default_spec,
|
||||
...modelInfo
|
||||
...modelInfo,
|
||||
categories: getCategory(item)
|
||||
});
|
||||
|
||||
if (item.fakeName) {
|
||||
@@ -122,7 +130,8 @@ const AddModal: FC<AddModalProps> = (props) => {
|
||||
handleShowCompatibleAlert(item.evaluateResult);
|
||||
form.current?.setFieldsValue?.({
|
||||
...item.evaluateResult?.default_spec,
|
||||
...modelInfo
|
||||
...modelInfo,
|
||||
categories: getCategory(item)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -469,5 +469,6 @@ export const excludeFields = [
|
||||
'ollama_library_model_name',
|
||||
'scheduleType',
|
||||
'placement_strategy',
|
||||
'backend'
|
||||
'backend',
|
||||
'gpu_selector'
|
||||
];
|
||||
|
||||
@@ -11,7 +11,7 @@ import { FormData } from '../config/types';
|
||||
const OllamaForm: React.FC = () => {
|
||||
const formCtx = useFormContext();
|
||||
const formInnerCtx = useFormInnerContext();
|
||||
const { byBuiltIn } = formCtx;
|
||||
const { byBuiltIn, onValuesChange } = formCtx;
|
||||
const { getRuleMessage } = useAppUtils();
|
||||
const intl = useIntl();
|
||||
const source = Form.useWatch('source');
|
||||
@@ -20,6 +20,18 @@ const OllamaForm: React.FC = () => {
|
||||
if (![modelSourceMap.ollama_library_value].includes(source) || byBuiltIn) {
|
||||
return null;
|
||||
}
|
||||
const handleModelNameChange = (value: string) => {
|
||||
if (value) {
|
||||
onValuesChange?.({}, formInstance.getFieldsValue());
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnBlur = (e: any) => {
|
||||
if (!e.target.value) {
|
||||
return;
|
||||
}
|
||||
onValuesChange?.({}, formInstance.getFieldsValue());
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Form.Item<FormData>
|
||||
@@ -38,6 +50,8 @@ const OllamaForm: React.FC = () => {
|
||||
defaultActiveFirstOption
|
||||
disabled={false}
|
||||
options={ollamaModelOptions}
|
||||
onSelect={handleModelNameChange}
|
||||
onBlur={handleOnBlur}
|
||||
description={
|
||||
<span>
|
||||
<span>
|
||||
|
||||
@@ -427,17 +427,32 @@ export const useCheckCompatibility = () => {
|
||||
return evalutionData;
|
||||
};
|
||||
|
||||
const checkRequiredValue = (allValues: any) => {
|
||||
const noLocalValue =
|
||||
allValues.source === modelSourceMap.local_path_value &&
|
||||
!allValues.local_path;
|
||||
|
||||
const noOllamaValue =
|
||||
allValues.source === modelSourceMap.ollama_library_value &&
|
||||
!allValues.ollama_library_model_name;
|
||||
return noLocalValue || noOllamaValue;
|
||||
};
|
||||
|
||||
const handleOnValuesChange = async (params: {
|
||||
changedValues: any;
|
||||
allValues: any;
|
||||
source: string;
|
||||
}) => {
|
||||
const { allValues, source } = params;
|
||||
if (
|
||||
_.isEqual(cacheFormValuesRef.current, allValues) ||
|
||||
(allValues.source === modelSourceMap.local_path_value &&
|
||||
!allValues.local_path)
|
||||
) {
|
||||
if (_.isEqual(cacheFormValuesRef.current, allValues)) {
|
||||
return;
|
||||
}
|
||||
if (checkRequiredValue(allValues)) {
|
||||
setWarningStatus({
|
||||
show: false,
|
||||
title: '',
|
||||
message: ''
|
||||
});
|
||||
return;
|
||||
}
|
||||
cacheFormValuesRef.current = allValues;
|
||||
|
||||
Reference in New Issue
Block a user