From c3054c11e9ec59462e814387b4e6a3d7ab6144d4 Mon Sep 17 00:00:00 2001 From: jZonG Date: Thu, 19 Jun 2025 11:25:22 +0800 Subject: [PATCH] support selecting model in auto generator --- .../config-prompt/simple-prompt-input.tsx | 10 --- .../config/automatic/get-automatic-res.tsx | 89 ++++++++++++++----- .../llm/components/prompt-generator-btn.tsx | 3 - 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx index 3268c1dc76..2a9a15296e 100644 --- a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx +++ b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx @@ -10,7 +10,6 @@ import PromptEditorHeightResizeWrap from './prompt-editor-height-resize-wrap' import cn from '@/utils/classnames' import type { PromptVariable } from '@/models/debug' import Tooltip from '@/app/components/base/tooltip' -import type { CompletionParams } from '@/types/app' import { AppType } from '@/types/app' import { getNewVar, getVars } from '@/utils/var' import AutomaticBtn from '@/app/components/app/configuration/config/automatic/automatic-btn' @@ -63,7 +62,6 @@ const Prompt: FC = ({ const { eventEmitter } = useEventEmitterContextContext() const { modelConfig, - completionParams, dataSets, setModelConfig, setPrevPromptConfig, @@ -264,14 +262,6 @@ const Prompt: FC = ({ {showAutomatic && ( void onFinished: (res: AutomaticRes) => void @@ -65,16 +66,23 @@ const TryLabel: FC<{ const GetAutomaticRes: FC = ({ mode, - model, isShow, onClose, isInLLMNode, onFinished, }) => { const { t } = useTranslation() + const localModel = localStorage.getItem('auto-gen-model') + ? JSON.parse(localStorage.getItem('auto-gen-model') as string) as Model + : null + const [model, setModel] = React.useState(localModel || { + name: '', + provider: '', + mode: mode as unknown as ModelModeType.chat, + completion_params: {} as CompletionParams, + }) const { - currentProvider, - currentModel, + defaultModel, } = useModelListAndDefaultModelAndCurrentProviderAndModel(ModelTypeEnum.textGeneration) const tryList = [ { @@ -115,7 +123,7 @@ const GetAutomaticRes: FC = ({ }, ] - const [instruction, setInstruction] = React.useState('') + const [instruction, setInstruction] = useState('') const handleChooseTemplate = useCallback((key: string) => { return () => { const template = t(`appDebug.generate.template.${key}.instruction`) @@ -135,7 +143,25 @@ const GetAutomaticRes: FC = ({ return true } const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false) - const [res, setRes] = React.useState(null) + const [res, setRes] = useState(null) + + useEffect(() => { + if (defaultModel) { + const localModel = localStorage.getItem('auto-gen-model') + ? JSON.parse(localStorage.getItem('auto-gen-model') || '') + : null + if (localModel) { + setModel(localModel) + } + else { + setModel(prev => ({ + ...prev, + name: defaultModel.model, + provider: defaultModel.provider.provider, + })) + } + } + }, [defaultModel]) const renderLoading = (
@@ -154,6 +180,26 @@ const GetAutomaticRes: FC = ({
) + const handleModelChange = useCallback((newValue: { modelId: string; provider: string; mode?: string; features?: string[] }) => { + const newModel = { + ...model, + provider: newValue.provider, + name: newValue.modelId, + mode: newValue.mode as ModelModeType, + } + setModel(newModel) + localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + }, [model, setModel]) + + const handleCompletionParamsChange = useCallback((newParams: FormValue) => { + const newModel = { + ...model, + completion_params: newParams as CompletionParams, + } + setModel(newModel) + localStorage.setItem('auto-gen-model', JSON.stringify(newModel)) + }, [model, setModel]) + const onGenerate = async () => { if (!isValid()) return @@ -198,17 +244,18 @@ const GetAutomaticRes: FC = ({
{t('appDebug.generate.title')}
{t('appDebug.generate.description')}
-
- - +
diff --git a/web/app/components/workflow/nodes/llm/components/prompt-generator-btn.tsx b/web/app/components/workflow/nodes/llm/components/prompt-generator-btn.tsx index 804478dde3..f58a749684 100644 --- a/web/app/components/workflow/nodes/llm/components/prompt-generator-btn.tsx +++ b/web/app/components/workflow/nodes/llm/components/prompt-generator-btn.tsx @@ -9,7 +9,6 @@ import GetAutomaticResModal from '@/app/components/app/configuration/config/auto import { AppType } from '@/types/app' import type { AutomaticRes } from '@/service/debug' import type { ModelConfig } from '@/app/components/workflow/types' -import type { Model } from '@/types/app' type Props = { className?: string @@ -20,7 +19,6 @@ type Props = { const PromptGeneratorBtn: FC = ({ className, onGenerated, - modelConfig, }) => { const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false) const handleAutomaticRes = useCallback((res: AutomaticRes) => { @@ -40,7 +38,6 @@ const PromptGeneratorBtn: FC = ({ isShow={showAutomatic} onClose={showAutomaticFalse} onFinished={handleAutomaticRes} - model={modelConfig as Model} isInLLMNode /> )}