diff --git a/web/app/components/datasets/documents/create-from-pipeline/data-source-options/option-card.tsx b/web/app/components/datasets/documents/create-from-pipeline/data-source-options/option-card.tsx index 7853805631..a3ea97ac42 100644 --- a/web/app/components/datasets/documents/create-from-pipeline/data-source-options/option-card.tsx +++ b/web/app/components/datasets/documents/create-from-pipeline/data-source-options/option-card.tsx @@ -33,7 +33,7 @@ const OptionCard = ({
{label} diff --git a/web/app/components/rag-pipeline/components/panel/test-run/preparation/data-source-options/option-card.tsx b/web/app/components/rag-pipeline/components/panel/test-run/preparation/data-source-options/option-card.tsx index 83a0f53770..8908c90cb6 100644 --- a/web/app/components/rag-pipeline/components/panel/test-run/preparation/data-source-options/option-card.tsx +++ b/web/app/components/rag-pipeline/components/panel/test-run/preparation/data-source-options/option-card.tsx @@ -43,7 +43,7 @@ const OptionCard = ({ />
{label} diff --git a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show/field.tsx b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show/field.tsx index 63b4880851..f95c2353f3 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show/field.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show/field.tsx @@ -44,7 +44,7 @@ const Field: FC = ({ /> )}
{name}
-
{getFieldType(payload)}
+
{getFieldType(payload)}{payload.schemaType && ` (${payload.schemaType})`}
{required &&
{t('app.structOutput.required')}
}
{payload.description && ( diff --git a/web/app/components/workflow/nodes/_base/components/variable/use-match-schema-type.ts b/web/app/components/workflow/nodes/_base/components/variable/use-match-schema-type.ts index 8c6a47a735..6d29a77e57 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/use-match-schema-type.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/use-match-schema-type.ts @@ -1,3 +1,5 @@ +import { useSchemaTypeDefinitions } from '@/service/use-common' + type AnyObj = Record | null // only compare type in object @@ -29,3 +31,17 @@ export function deepEqualByType(a: AnyObj, b: AnyObj): boolean { return cmp(a, b) } + +const useMatchSchemaType = () => { + const { data: schemaTypeDefinitions } = useSchemaTypeDefinitions() + const getMatchedSchemaType = (obj: AnyObj): string => { + if(!schemaTypeDefinitions) return '' + const matched = schemaTypeDefinitions.find(def => deepEqualByType(obj, def.schema)) + return matched ? matched.name : '' + } + return { + getMatchedSchemaType, + } +} + +export default useMatchSchemaType diff --git a/web/app/components/workflow/nodes/llm/types.ts b/web/app/components/workflow/nodes/llm/types.ts index ff2a5fc5f4..f68edf4040 100644 --- a/web/app/components/workflow/nodes/llm/types.ts +++ b/web/app/components/workflow/nodes/llm/types.ts @@ -55,7 +55,7 @@ export type Field = { items?: ArrayItems // Array has items. Define the item type enum?: SchemaEnumType // Enum values additionalProperties?: false // Required in object by api. Just set false - alias?: string // Alias of the field + schemaType?: string // an another type defined in backend schemas } export type StructuredOutput = { diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts index af9eef5d23..5933def441 100644 --- a/web/app/components/workflow/nodes/llm/utils.ts +++ b/web/app/components/workflow/nodes/llm/utils.ts @@ -10,14 +10,11 @@ export const checkNodeValid = (_payload: LLMNodeType) => { } export const getFieldType = (field: Field) => { - const { type, items, alias } = field - if (type !== Type.array || !items) { - if (alias) - return alias + const { type, items } = field + if (type !== Type.array || !items) return type - } - return ArrayType[items.type] + return ArrayType[items.type as keyof typeof ArrayType] } export const getHasChildren = (schema: Field) => { diff --git a/web/app/components/workflow/nodes/tool/panel.tsx b/web/app/components/workflow/nodes/tool/panel.tsx index 5ab894c0d1..c914e2fc61 100644 --- a/web/app/components/workflow/nodes/tool/panel.tsx +++ b/web/app/components/workflow/nodes/tool/panel.tsx @@ -13,6 +13,7 @@ import StructureOutputItem from '@/app/components/workflow/nodes/_base/component import { useStore } from '@/app/components/workflow/store' import { wrapStructuredVarItem } from '@/app/components/workflow/utils/tool' import { useInitial } from './use-initial' +import useMatchSchemaType from '../_base/components/variable/use-match-schema-type' const i18nPrefix = 'workflow.nodes.tool' @@ -41,6 +42,7 @@ const Panel: FC> = ({ const [collapsed, setCollapsed] = React.useState(false) const pipelineId = useStore(s => s.pipelineId) const setShowInputFieldPanel = useStore(s => s.setShowInputFieldPanel) + const { getMatchedSchemaType } = useMatchSchemaType() if (isLoading) { return
@@ -122,7 +124,7 @@ const Panel: FC> = ({ {outputItem.value?.type === 'object' ? ( + payload={wrapStructuredVarItem(outputItem, getMatchedSchemaType(outputItem.value))} /> ) : ( ) => { if (variable?.general_chunks) return CHUNK_TYPE_MAP.general_chunks @@ -60,16 +61,16 @@ export const getOutputVariableAlias = (variable: Record) => { if (variable?.file_type) return 'file' } -export const wrapStructuredVarItem = (outputItem: any): StructuredOutput => { + +export const wrapStructuredVarItem = (outputItem: any, matchedSchemaType: string): StructuredOutput => { const dataType = Type.object - // console.log(outputItem) return { schema: { type: dataType, properties: { [outputItem.name]: { ...outputItem.value, - alias: getOutputVariableAlias(outputItem.value?.properties), + schemaType: matchedSchemaType, }, }, additionalProperties: false, diff --git a/web/service/use-common.ts b/web/service/use-common.ts index ae9300ef57..8fdd0b6c77 100644 --- a/web/service/use-common.ts +++ b/web/service/use-common.ts @@ -60,3 +60,17 @@ export const useFilePreview = (fileID: string) => { enabled: !!fileID, }) } + +type SchemaTypeDefinition = { + name: string + schema: { + properties: Record + } +} + +export const useSchemaTypeDefinitions = () => { + return useQuery({ + queryKey: [NAME_SPACE, 'schema-type-definitions'], + queryFn: () => get('/spec/schema-definitions'), + }) +}