From 5cdf70503d04ce6cc2a8b9eaa27a857ebf4bb345 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 25 Mar 2025 10:44:42 +0800 Subject: [PATCH] feat: fetch model support struct output --- .../model-provider-page/declarations.ts | 1 + web/app/components/workflow/nodes/llm/use-config.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/declarations.ts b/web/app/components/header/account-setting/model-provider-page/declarations.ts index 486a1e44f5..700ebb00e3 100644 --- a/web/app/components/header/account-setting/model-provider-page/declarations.ts +++ b/web/app/components/header/account-setting/model-provider-page/declarations.ts @@ -59,6 +59,7 @@ export enum ModelFeatureEnum { video = 'video', document = 'document', audio = 'audio', + StructuredOutput = 'structured-output', } export enum ModelFeatureTextEnum { diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 25d213e8f3..c9e54f3e5a 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -10,16 +10,15 @@ import { import useAvailableVarList from '../_base/hooks/use-available-var-list' import useConfigVision from '../../hooks/use-config-vision' import type { LLMNodeType, StructuredOutput } from './types' -import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' +import { useModelList, useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' import { + ModelFeatureEnum, ModelTypeEnum, } from '@/app/components/header/account-setting/model-provider-page/declarations' import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' 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() @@ -280,9 +279,11 @@ const useConfig = (id: string, payload: LLMNodeType) => { }, [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 { data: modelList } = useModelList(ModelTypeEnum.textGeneration) + const isModelSupportStructuredOutput = modelList + ?.find(provideItem => provideItem.provider === model?.provider) + ?.models.find(modelItem => modelItem.model === model?.name) + ?.features?.includes(ModelFeatureEnum.StructuredOutput) const handleStructureOutputEnableChange = useCallback((enabled: boolean) => { const newInputs = produce(inputs, (draft) => {