fix: chat compare switch model meta

This commit is contained in:
jialin
2025-12-26 17:29:36 +08:00
parent a006263e51
commit 5b5b2c6364
3 changed files with 72 additions and 76 deletions
@@ -14,6 +14,7 @@ interface ActiveModelsProps {
const ActiveModels: React.FC<ActiveModelsProps> = (props) => { const ActiveModels: React.FC<ActiveModelsProps> = (props) => {
const { spans, modelSelections, setModelRefs } = props; const { spans, modelSelections, setModelRefs } = props;
return ( return (
<Row gutter={[16, 0]} style={{ height: '100%' }}> <Row gutter={[16, 0]} style={{ height: '100%' }}>
{modelSelections.map((model, index) => ( {modelSelections.map((model, index) => (
@@ -21,7 +22,8 @@ const ActiveModels: React.FC<ActiveModelsProps> = (props) => {
span={spans.span} span={spans.span}
key={`${model.value || 'empty'}-${model.uid}`} key={`${model.value || 'empty'}-${model.uid}`}
style={{ style={{
height: spans.count < 4 ? 'calc(100% - 16px)' : 'calc(50% - 16px)' height: spans.count < 4 ? 'calc(100% - 16px)' : 'calc(50% - 16px)',
overflow: 'hidden'
}} }}
> >
<ModelItem <ModelItem
@@ -47,7 +47,8 @@ interface ModelItemProps {
} }
const ModelItem: React.FC<ModelItemProps> = forwardRef((props, ref) => { const ModelItem: React.FC<ModelItemProps> = forwardRef((props, ref) => {
const { modelList, model, instanceId } = props; const { modelList, ...restProps } = props;
const { model, instanceId } = restProps;
const { const {
globalParams, globalParams,
setGlobalParams, setGlobalParams,
@@ -66,14 +67,20 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef((props, ref) => {
paramsConfig, paramsConfig,
initialValues, initialValues,
parameters parameters
} = useInitLLmMeta(props, { } = useInitLLmMeta(
{
...restProps,
modelList: modelFullList
},
{
defaultValues: { defaultValues: {
...llmInitialValues, ...llmInitialValues,
model: model model: model
}, },
defaultParamsConfig: ChatParamsConfig, defaultParamsConfig: ChatParamsConfig,
metaKeys: LLM_METAKEYS metaKeys: LLM_METAKEYS
}); }
);
const intl = useIntl(); const intl = useIntl();
const isApplyToAllModels = useRef(false); const isApplyToAllModels = useRef(false);
const [systemMessage, setSystemMessage] = useState<string>(''); const [systemMessage, setSystemMessage] = useState<string>('');
+7 -20
View File
@@ -12,13 +12,7 @@ import { generateRandomNumber } from '@/utils';
import { useSearchParams } from '@umijs/max'; import { useSearchParams } from '@umijs/max';
import { useMemoizedFn } from 'ahooks'; import { useMemoizedFn } from 'ahooks';
import _ from 'lodash'; import _ from 'lodash';
import React, { import React, { useEffect, useMemo, useRef, useState } from 'react';
useCallback,
useEffect,
useMemo,
useRef,
useState
} from 'react';
import { ParamsSchema } from '../config/types'; import { ParamsSchema } from '../config/types';
import { import {
IMG_METAKEYS, IMG_METAKEYS,
@@ -133,8 +127,7 @@ export const useInitLLmMeta = (
return fields?.join(','); return fields?.join(',');
}, [paramsConfig]); }, [paramsConfig]);
const handleOnModelChange = useCallback( const handleOnModelChange = useMemoizedFn((val: string) => {
(val: string) => {
if (!val) 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);
@@ -159,11 +152,9 @@ export const useInitLLmMeta = (
}; };
}); });
setParamsConfig(config); setParamsConfig(config);
}, });
[modelList, defaultParamsConfig]
);
const handleOnValuesChange = useCallback( const handleOnValuesChange = useMemoizedFn(
(changeValues: Record<string, any>, allValues: Record<string, any>) => { (changeValues: Record<string, any>, allValues: Record<string, any>) => {
if (changeValues.model) { if (changeValues.model) {
handleOnModelChange(changeValues.model); handleOnModelChange(changeValues.model);
@@ -172,8 +163,7 @@ export const useInitLLmMeta = (
setParams(allValues); setParams(allValues);
setInitialValues(allValues); setInitialValues(allValues);
} }
}, }
[handleOnModelChange]
); );
useEffect(() => { useEffect(() => {
@@ -405,8 +395,7 @@ export const useInitImageMeta = (
return fields?.join(','); return fields?.join(',');
}, [paramsConfig]); }, [paramsConfig]);
const handleOnModelChange = useCallback( const handleOnModelChange = useMemoizedFn((val: string) => {
(val: string) => {
if (!val) 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);
@@ -431,9 +420,7 @@ export const useInitImageMeta = (
model: val model: val
}); });
updateCacheFormData(initialData); updateCacheFormData(initialData);
}, });
[modelList, isOpenaiCompatible]
);
const handleOnValuesChange = useMemoizedFn( const handleOnValuesChange = useMemoizedFn(
(changeValues: Record<string, any>, allValues: Record<string, any>) => { (changeValues: Record<string, any>, allValues: Record<string, any>) => {