fix: do not init meta data when switch tab

This commit is contained in:
jialin
2025-03-05 20:30:53 +08:00
parent caadc02fb4
commit 4de1a38c00
11 changed files with 133 additions and 108 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import { createFromIconfontCN } from '@ant-design/icons';
// import './iconfont/iconfont.js'; // import './iconfont/iconfont.js';
const IconFont = createFromIconfontCN({ const IconFont = createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/c/font_4613488_pr3u3llgke.js' scriptUrl: '//at.alicdn.com/t/c/font_4613488_y6wf3nguxjl.js'
}); });
export default IconFont; export default IconFont;
+8 -5
View File
@@ -78,8 +78,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
const mouseDownState = useRef<boolean>(false); const mouseDownState = useRef<boolean>(false);
const disabled = useMemo(() => { const disabled = useMemo(() => {
return isDisabled || invertMask; return isDisabled || invertMask || !!maskUpload?.length;
}, [isDisabled, invertMask]); }, [isDisabled, invertMask, maskUpload]);
const getTransformedPoint = useCallback( const getTransformedPoint = useCallback(
(offsetX: number, offsetY: number) => { (offsetX: number, offsetY: number) => {
@@ -465,6 +465,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
clearOverlayCanvas(); clearOverlayCanvas();
setStrokes([]); setStrokes([]);
currentStroke.current = []; currentStroke.current = [];
saveImage();
console.log('Resetting strokes', currentStroke.current); console.log('Resetting strokes', currentStroke.current);
}, []); }, []);
@@ -577,8 +578,9 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
1 1
); );
canvas!.width = img.width * baseScale.current; // if need to fit the image to the container, show * baseScale.current
canvas!.height = img.height * baseScale.current; canvas!.width = img.width;
canvas!.height = img.height;
// fit the image to the container // fit the image to the container
autoScale.current = autoScale.current || 1; autoScale.current = autoScale.current || 1;
@@ -721,6 +723,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
}; };
const handleOnWheel = (event: any) => { const handleOnWheel = (event: any) => {
// stop
handleZoom(event); handleZoom(event);
updateCursorSize(); updateCursorSize();
updateCursorPosOnZoom(event); updateCursorPosOnZoom(event);
@@ -874,7 +877,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
<Checkbox <Checkbox
onChange={handleOnChangeMask} onChange={handleOnChangeMask}
className="flex-center" className="flex-center"
value={negativeMaskRef.current} value={invertMask}
> >
<span className="font-size-12"> <span className="font-size-12">
{intl.formatMessage({ {intl.formatMessage({
+38 -38
View File
@@ -7,8 +7,17 @@ const RenderProgress = memo(
steps?: number; steps?: number;
download?: boolean; download?: boolean;
label?: React.ReactNode; label?: React.ReactNode;
successPercent?: number;
successColor?: string;
}) => { }) => {
const { percent, steps = 5, download, label } = props; const {
percent,
steps = 5,
download,
label,
successPercent,
successColor
} = props;
const strokeColor = useMemo(() => { const strokeColor = useMemo(() => {
if (download) { if (download) {
@@ -24,47 +33,38 @@ const RenderProgress = memo(
return 'var(--ant-color-error)'; return 'var(--ant-color-error)';
}, [percent]); }, [percent]);
const renderProgress = useMemo(() => {
return (
<Progress
percentPosition={{ align: 'center', type: 'inner' }}
size={[undefined, 16]}
format={() => {
return (
<span
style={{
color: '#fff'
}}
>
{percent}%
</span>
);
}}
percent={percent}
success={{
percent: successPercent,
strokeColor: 'var(--ant-geekblue-3)'
}}
strokeColor={strokeColor}
></Progress>
);
}, [percent, successPercent, strokeColor]);
return ( return (
<> <>
{label ? ( {label ? (
<Tooltip title={label}> <Tooltip title={label}>{renderProgress}</Tooltip>
<Progress
percentPosition={{ align: 'center', type: 'inner' }}
size={[undefined, 16]}
format={() => {
return (
<span
style={{
color: '#fff'
}}
>
{percent}%
</span>
);
}}
percent={percent}
strokeColor={strokeColor}
></Progress>
</Tooltip>
) : ( ) : (
<Progress renderProgress
type="line"
percentPosition={{ align: 'center', type: 'inner' }}
size={[undefined, 16]}
format={() => {
return (
<span
style={{
color: '#fff'
}}
>
{percent}%
</span>
);
}}
percent={percent}
strokeColor={strokeColor}
></Progress>
)} )}
</> </>
); );
@@ -1,4 +1,5 @@
import { DownOutlined, RightOutlined } from '@ant-design/icons'; import IconFont from '@/components/icon-font';
import { RightOutlined } from '@ant-design/icons';
import { Button, Checkbox } from 'antd'; import { Button, Checkbox } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
import React from 'react'; import React from 'react';
@@ -39,7 +40,17 @@ const HeaderPrefix: React.FC<HeaderPrefixProps> = (props) => {
<span style={{ marginRight: 5 }}> <span style={{ marginRight: 5 }}>
{_.isBoolean(expandable) ? ( {_.isBoolean(expandable) ? (
<Button type="text" size="small" onClick={handleToggleExpand}> <Button type="text" size="small" onClick={handleToggleExpand}>
{expandAll ? <DownOutlined /> : <RightOutlined />} {expandAll ? (
<IconFont
type="icon-collapse_all"
className="font-size-16"
></IconFont>
) : (
<IconFont
type="icon-uncollapse_all"
className="font-size-16"
></IconFont>
)}
</Button> </Button>
) : ( ) : (
expandable expandable
+3
View File
@@ -53,6 +53,9 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
}, [columns, children]); }, [columns, children]);
const expandAll = useMemo(() => { const expandAll = useMemo(() => {
if (expandedRowKeys?.length === 0) {
return false;
}
const allKeys = new Set(expandedRowKeys); const allKeys = new Set(expandedRowKeys);
const currentDataKeys = props.dataSource.map((record) => record[rowKey]); const currentDataKeys = props.dataSource.map((record) => record[rowKey]);
return currentDataKeys.every((key) => allKeys.has(key)); return currentDataKeys.every((key) => allKeys.has(key));
+1 -1
View File
@@ -348,7 +348,7 @@ const options = [
{ {
label: '--rope-scaling', label: '--rope-scaling',
value: '--rope-scaling', value: '--rope-scaling',
options: ['none', 'linear', 'yarn'] options: ['linear', 'yarn']
}, },
{ {
label: '--rope-scale', label: '--rope-scale',
@@ -289,8 +289,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
isResetNeeded: false isResetNeeded: false
}; };
}); });
setMask(data.mask || null); setMask(data.mask || maskUpload[0]?.dataUrl || null);
setImage(data.img || maskUpload[0]?.dataUrl || null); setImage(data.img);
}, },
[] []
); );
@@ -332,7 +332,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
return ( return (
<> <>
<UploadImg <UploadImg
accept="image/png" accept="image/*"
drag={true} drag={true}
multiple={false} multiple={false}
handleUpdateImgList={handleUpdateImageList} handleUpdateImgList={handleUpdateImageList}
+2 -1
View File
@@ -689,11 +689,12 @@ export const ChatParamsConfig: ParamsSchema[] = [
html: false, html: false,
isLocalized: true isLocalized: true
}, },
attrs: { formItemAttrs: {
normalize(value: string) { normalize(value: string) {
return value || null; return value || null;
} }
}, },
attrs: {},
rules: [ rules: [
{ {
required: false required: false
+7
View File
@@ -10,6 +10,13 @@ export const LLM_METAKEYS: Record<string, any> = {
presence_penalty: 'presence_penalty' presence_penalty: 'presence_penalty'
}; };
export const precisionTwoKeys = [
'temperature',
'top_p',
'frequency_penalty',
'presence_penalty'
];
export const IMG_METAKEYS = [ export const IMG_METAKEYS = [
'sample_method', 'sample_method',
'sampling_steps', 'sampling_steps',
+27 -20
View File
@@ -23,7 +23,8 @@ import {
IMG_METAKEYS, IMG_METAKEYS,
advancedFieldsDefaultValus, advancedFieldsDefaultValus,
imgInitialValues, imgInitialValues,
openaiCompatibleFieldsDefaultValus openaiCompatibleFieldsDefaultValus,
precisionTwoKeys
} from './config'; } from './config';
interface MessageProps { interface MessageProps {
@@ -53,16 +54,13 @@ export const useInitLLmMeta = (
} = options; } = options;
const formRef = useRef<any>(null); const formRef = useRef<any>(null);
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const defaultModel =
searchParams.get('model') ||
(isChat ? model ?? modelList?.[0]?.value : model);
const [modelMeta, setModelMeta] = useState<any>({}); const [modelMeta, setModelMeta] = useState<any>({});
const [initialValues, setInitialValues] = useState<any>({ const [initialValues, setInitialValues] = useState<any>({
...defaultValues, ...defaultValues,
model: defaultModel model: ''
}); });
const [parameters, setParams] = useState<any>({ const [parameters, setParams] = useState<any>({
model: defaultModel model: ''
}); });
const [paramsConfig, setParamsConfig] = const [paramsConfig, setParamsConfig] =
useState<ParamsSchema[]>(defaultParamsConfig); useState<ParamsSchema[]>(defaultParamsConfig);
@@ -70,13 +68,20 @@ export const useInitLLmMeta = (
const { initialize: innitializeParams } = useOverlayScroller(); const { initialize: innitializeParams } = useOverlayScroller();
const defaultModel = useMemo(() => {
return (
searchParams.get('model') ||
(isChat ? model ?? modelList?.[0]?.value : model)
);
}, [model, modelList, isChat]);
const extractLLMMeta = (meta: any) => { const extractLLMMeta = (meta: any) => {
const towKeys = new Set(precisionTwoKeys);
const modelMeta = meta || {}; const modelMeta = meta || {};
const modelMetaValue = _.pick(modelMeta, _.keys(metaKeys)); const modelMetaValue = _.pick(modelMeta, _.keys(metaKeys));
const obj = Object.entries(metaKeys).reduce((acc: any, [key, value]) => { const obj = Object.entries(metaKeys).reduce((acc: any, [key, value]) => {
const val = modelMetaValue[key]; const val = modelMetaValue[key];
if (val && _.hasIn(modelMetaValue, key)) { if (_.hasIn(modelMetaValue, key)) {
acc[value] = val; acc[value] = towKeys.has(key) ? _.round(val, 2) : val;
} }
return acc; return acc;
}, {}); }, {});
@@ -109,10 +114,9 @@ export const useInitLLmMeta = (
const handleOnModelChange = useCallback( const handleOnModelChange = useCallback(
(val: string) => { (val: string) => {
if (!val || val === parameters.model) return; if (!val) return;
const model = modelList.find((item) => item.value === val); const model = modelList.find((item) => item.value === val);
const { form: initialData, meta } = extractLLMMeta(model?.meta); const { form: initialData, meta } = extractLLMMeta(model?.meta);
setModelMeta(meta || {}); setModelMeta(meta || {});
setInitialValues({ setInitialValues({
...initialData, ...initialData,
@@ -135,7 +139,7 @@ export const useInitLLmMeta = (
}); });
setParamsConfig(config); setParamsConfig(config);
}, },
[modelList, parameters, defaultParamsConfig] [modelList, defaultParamsConfig]
); );
const handleOnValuesChange = useCallback( const handleOnValuesChange = useCallback(
@@ -152,10 +156,10 @@ export const useInitLLmMeta = (
); );
useEffect(() => { useEffect(() => {
if (defaultModel) { if (defaultModel && modelList.length) {
handleOnModelChange(defaultModel); handleOnModelChange(defaultModel);
} }
}, [defaultModel, handleOnModelChange]); }, [defaultModel, modelList.length]);
useEffect(() => { useEffect(() => {
if (paramsRef.current) { if (paramsRef.current) {
@@ -185,7 +189,6 @@ export const useInitImageMeta = (props: MessageProps) => {
const { modelList } = props; const { modelList } = props;
const form = useRef<any>(null); const form = useRef<any>(null);
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const defaultModel = searchParams.get('model') || modelList?.[0]?.value || '';
const [modelMeta, setModelMeta] = useState<any>({}); const [modelMeta, setModelMeta] = useState<any>({});
const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false); const [isOpenaiCompatible, setIsOpenaiCompatible] = useState<boolean>(false);
const [imageSizeOptions, setImageSizeOptions] = React.useState< const [imageSizeOptions, setImageSizeOptions] = React.useState<
@@ -198,7 +201,7 @@ export const useInitImageMeta = (props: MessageProps) => {
const [initialValues, setInitialValues] = useState<any>({ const [initialValues, setInitialValues] = useState<any>({
...imgInitialValues, ...imgInitialValues,
...advancedFieldsDefaultValus, ...advancedFieldsDefaultValus,
model: defaultModel model: ''
}); });
const [paramsConfig, setParamsConfig] = useState<ParamsSchema[]>([ const [paramsConfig, setParamsConfig] = useState<ParamsSchema[]>([
...ImageCountConfig, ...ImageCountConfig,
@@ -209,9 +212,13 @@ export const useInitImageMeta = (props: MessageProps) => {
const [parameters, setParams] = useState<any>({ const [parameters, setParams] = useState<any>({
...imgInitialValues, ...imgInitialValues,
...advancedFieldsDefaultValus, ...advancedFieldsDefaultValus,
model: defaultModel model: ''
}); });
const defaultModel = useMemo(() => {
return searchParams.get('model') || modelList?.[0]?.value || '';
}, [modelList]);
const cacheFormData = React.useRef<Record<string, any>>({ const cacheFormData = React.useRef<Record<string, any>>({
...imgInitialValues, ...imgInitialValues,
...openaiCompatibleFieldsDefaultValus, ...openaiCompatibleFieldsDefaultValus,
@@ -373,7 +380,7 @@ export const useInitImageMeta = (props: MessageProps) => {
const handleOnModelChange = useCallback( const handleOnModelChange = useCallback(
(val: string) => { (val: string) => {
if (!val || val === parameters.model) return; if (!val) return;
const model = modelList.find((item) => item.value === val); const model = modelList.find((item) => item.value === val);
const { form: initialData, sizeOptions } = extractIMGMeta(model?.meta); const { form: initialData, sizeOptions } = extractIMGMeta(model?.meta);
const newParamsConfig = generateImageParamsConfig(model, sizeOptions); const newParamsConfig = generateImageParamsConfig(model, sizeOptions);
@@ -396,7 +403,7 @@ export const useInitImageMeta = (props: MessageProps) => {
}); });
updateCacheFormData(initialData); updateCacheFormData(initialData);
}, },
[modelList, isOpenaiCompatible, parameters.model] [modelList, isOpenaiCompatible]
); );
const handleOnValuesChange = useCallback( const handleOnValuesChange = useCallback(
@@ -448,10 +455,10 @@ export const useInitImageMeta = (props: MessageProps) => {
); );
useEffect(() => { useEffect(() => {
if (defaultModel) { if (defaultModel && modelList.length) {
handleOnModelChange(defaultModel); handleOnModelChange(defaultModel);
} }
}, [defaultModel, handleOnModelChange]); }, [defaultModel, modelList.length]);
return { return {
extractIMGMeta, extractIMGMeta,
+30 -37
View File
@@ -264,6 +264,30 @@ const Workers: React.FC = () => {
return <div></div>; return <div></div>;
}; };
const renderProgressLabels = (data: {
total: number;
used: number;
allocated: number;
}) => {
const { total, used, allocated } = data;
return (
<span className="flex-column">
<span>
{intl.formatMessage({ id: 'resources.table.total' })}:{' '}
{convertFileSize(total, 0)}
</span>
<span>
{intl.formatMessage({ id: 'resources.table.used' })}:{' '}
{convertFileSize(used, 0)}
</span>
<span>
{intl.formatMessage({ id: 'resources.table.allocated' })}:{' '}
{convertFileSize(allocated, 0)}
</span>
</span>
);
};
useEffect(() => { useEffect(() => {
fetchData(); fetchData();
}, [queryParams]); }, [queryParams]);
@@ -425,22 +449,11 @@ const Workers: React.FC = () => {
record?.status?.memory?.used, record?.status?.memory?.used,
record?.status?.memory?.total record?.status?.memory?.total
)} )}
label={ successPercent={formateUtilazation(
<span className="flex-column"> record?.status?.memory?.allocated,
<span> record?.status?.memory?.total
{intl.formatMessage({ id: 'resources.table.total' })}:{' '} )}
{convertFileSize(record?.status?.memory?.total, 0)} label={renderProgressLabels(record?.status?.memory)}
</span>
<span>
{intl.formatMessage({ id: 'resources.table.used' })}:{' '}
{convertFileSize(
record?.status?.memory?.used ||
record?.status.memory?.allocated,
0
)}
</span>
</span>
}
></ProgressBar> ></ProgressBar>
); );
}} }}
@@ -511,27 +524,7 @@ const Workers: React.FC = () => {
0 0
) )
} }
label={ label={renderProgressLabels(item.memory)}
<span className="flex-column">
<span>
{intl.formatMessage({
id: 'resources.table.total'
})}
: {convertFileSize(item.memory?.total, 0)}
</span>
<span>
{intl.formatMessage({
id: 'resources.table.used'
})}
:{' '}
{convertFileSize(
item.memory?.used ||
item.memory?.allocated,
0
)}
</span>
</span>
}
></ProgressBar> ></ProgressBar>
{item.memory.is_unified_memory && ( {item.memory.is_unified_memory && (
<Tooltip <Tooltip