feat: fetch model support struct output

This commit is contained in:
Joel 2025-03-25 10:44:42 +08:00
parent abbafd56ef
commit 5cdf70503d
2 changed files with 8 additions and 6 deletions

View File

@ -59,6 +59,7 @@ export enum ModelFeatureEnum {
video = 'video', video = 'video',
document = 'document', document = 'document',
audio = 'audio', audio = 'audio',
StructuredOutput = 'structured-output',
} }
export enum ModelFeatureTextEnum { export enum ModelFeatureTextEnum {

View File

@ -10,16 +10,15 @@ import {
import useAvailableVarList from '../_base/hooks/use-available-var-list' import useAvailableVarList from '../_base/hooks/use-available-var-list'
import useConfigVision from '../../hooks/use-config-vision' import useConfigVision from '../../hooks/use-config-vision'
import type { LLMNodeType, StructuredOutput } from './types' 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 { import {
ModelFeatureEnum,
ModelTypeEnum, ModelTypeEnum,
} from '@/app/components/header/account-setting/model-provider-page/declarations' } from '@/app/components/header/account-setting/model-provider-page/declarations'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' 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 useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
import { RETRIEVAL_OUTPUT_STRUCT } from '@/app/components/workflow/constants' import { RETRIEVAL_OUTPUT_STRUCT } from '@/app/components/workflow/constants'
import { checkHasContextBlock, checkHasHistoryBlock, checkHasQueryBlock } from '@/app/components/base/prompt-editor/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 useConfig = (id: string, payload: LLMNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly() const { nodesReadOnly: readOnly } = useNodesReadOnly()
@ -280,9 +279,11 @@ const useConfig = (id: string, payload: LLMNodeType) => {
}, [inputs, setInputs]) }, [inputs, setInputs])
// structure output // structure output
// TODO: this method has problem, different model has different parameter rules that show support structured output const { data: modelList } = useModelList(ModelTypeEnum.textGeneration)
const { data: parameterRulesData } = useSWR((model?.provider && model?.name) ? `/workspaces/current/model-providers/${model.provider}/models/parameter-rules?model=${model.name}` : null, fetchModelParameterRules) const isModelSupportStructuredOutput = modelList
const isModelSupportStructuredOutput = parameterRulesData?.data?.some((rule: any) => rule.name === 'json_schema') ?.find(provideItem => provideItem.provider === model?.provider)
?.models.find(modelItem => modelItem.model === model?.name)
?.features?.includes(ModelFeatureEnum.StructuredOutput)
const handleStructureOutputEnableChange = useCallback((enabled: boolean) => { const handleStructureOutputEnableChange = useCallback((enabled: boolean) => {
const newInputs = produce(inputs, (draft) => { const newInputs = produce(inputs, (draft) => {