From cea0886e4a182c64e0cee1c8010c0e75bba35e3b Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 17 Mar 2025 16:30:04 +0800 Subject: [PATCH] chore: temp show lengcy --- .../model-parameter-modal/parameter-item.tsx | 16 +++++++++++++ .../components/workflow/nodes/llm/panel.tsx | 23 +++++++++++-------- .../workflow/nodes/llm/use-config.ts | 8 +++++++ web/i18n/en-US/app.ts | 3 +++ web/i18n/zh-Hans/app.ts | 3 +++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx index f43598fc38..48cf05c6de 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx @@ -10,6 +10,8 @@ import Slider from '@/app/components/base/slider' import Radio from '@/app/components/base/radio' import { SimpleSelect } from '@/app/components/base/select' import TagInput from '@/app/components/base/tag-input' +import Badge from '@/app/components/base/badge' +import { useTranslation } from 'react-i18next' export type ParameterValue = number | string | string[] | boolean | undefined @@ -27,6 +29,7 @@ const ParameterItem: FC = ({ onSwitch, isInWorkflow, }) => { + const { t } = useTranslation() const language = useLanguage() const [localValue, setLocalValue] = useState(value) const numberInputRef = useRef(null) @@ -278,6 +281,19 @@ const ParameterItem: FC = ({ /> ) } + {/* TODO: wait api return and product design */} + {parameterRule.name === 'json_schema' && ( + +
{t('app.structOutput.legacyTip')}
+ {t('app.structOutput.learnMore')} + + )} + > + {t('app.structOutput.legacy')} +
+ )} { parameterRule.type === 'tag' && ( diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 6ac1410d8d..bf7fff222c 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -67,6 +67,7 @@ const Panel: FC> = ({ contexts, setContexts, runningStatus, + isModelSupportStructuredOutput, handleStructureOutputEnableChange, handleStructureOutputChange, handleRun, @@ -280,16 +281,18 @@ const Panel: FC> = ({ - -
{t('app.structOutput.modelNotSupported')}
-
{t('app.structOutput.modelNotSupportedTip')}
- - }> -
- -
-
+ {!isModelSupportStructuredOutput && ( + +
{t('app.structOutput.modelNotSupported')}
+
{t('app.structOutput.modelNotSupportedTip')}
+ + }> +
+ +
+
+ )}
{t('app.structOutput.structured')}
{t('app.structOutput.structuredTip')} diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 4e6dac024d..25d213e8f3 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -18,6 +18,8 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run' import { RETRIEVAL_OUTPUT_STRUCT } from '@/app/components/workflow/constants' import { checkHasContextBlock, checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/constants' +import useSWR from 'swr' +import { fetchModelParameterRules } from '@/service/common' const useConfig = (id: string, payload: LLMNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() @@ -277,6 +279,11 @@ const useConfig = (id: string, payload: LLMNodeType) => { setInputs(newInputs) }, [inputs, setInputs]) + // structure output + // TODO: this method has problem, different model has different parameter rules that show support structured output + const { data: parameterRulesData } = useSWR((model?.provider && model?.name) ? `/workspaces/current/model-providers/${model.provider}/models/parameter-rules?model=${model.name}` : null, fetchModelParameterRules) + const isModelSupportStructuredOutput = parameterRulesData?.data?.some((rule: any) => rule.name === 'json_schema') + const handleStructureOutputEnableChange = useCallback((enabled: boolean) => { const newInputs = produce(inputs, (draft) => { draft.structured_output_enabled = enabled @@ -422,6 +429,7 @@ const useConfig = (id: string, payload: LLMNodeType) => { setContexts, varInputs, runningStatus, + isModelSupportStructuredOutput, handleStructureOutputChange, handleStructureOutputEnableChange, handleRun, diff --git a/web/i18n/en-US/app.ts b/web/i18n/en-US/app.ts index 3f5023a5bd..ae09a5e8c2 100644 --- a/web/i18n/en-US/app.ts +++ b/web/i18n/en-US/app.ts @@ -190,6 +190,9 @@ const translation = { structuredTip: 'Structured Outputs is a feature that ensures the model will always generate responses that adhere to your supplied JSON Schema', modelNotSupported: 'Model not supported', modelNotSupportedTip: 'The current model does not support this feature and is automatically downgraded to prompt injection.', + legacy: 'Legacy', + legacyTip: 'JSON Schema will be removed from model parameters, you can use the structured output functionality under nodes instead.', + learnMore: 'Learn more', }, } diff --git a/web/i18n/zh-Hans/app.ts b/web/i18n/zh-Hans/app.ts index ea94412ab0..6f75663851 100644 --- a/web/i18n/zh-Hans/app.ts +++ b/web/i18n/zh-Hans/app.ts @@ -191,6 +191,9 @@ const translation = { structuredTip: '结构化输出是一项功能,可确保模型始终生成符合您提供的 JSON 模式的响应', modelNotSupported: '模型不支持', modelNotSupportedTip: '当前模型不支持此功能,将自动降级为提示注入。', + legacy: '遗留', + legacyTip: '此功能将在未来版本中删除', + learnMore: '了解更多', }, }