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