mirror of https://github.com/langgenius/dify.git
fix: json schema
This commit is contained in:
parent
ac7953a32c
commit
8464ec46e6
|
|
@ -73,7 +73,7 @@ const AddOAuthButton = ({
|
|||
is_system_oauth_params_exists,
|
||||
client_params,
|
||||
redirect_uri,
|
||||
} = mergedOAuthData as any
|
||||
} = mergedOAuthData as any || {}
|
||||
const isConfigured = is_system_oauth_params_exists || is_oauth_custom_client_enabled
|
||||
const handleOAuth = useCallback(async () => {
|
||||
const { authorization_url } = await getPluginOAuthUrl()
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-so
|
|||
import type { PromptItem } from '@/models/debug'
|
||||
import { VAR_REGEX } from '@/config'
|
||||
import type { AgentNodeType } from '../../../agent/types'
|
||||
import { getOutputVariableAlias } from '@/app/components/workflow/utils/tool'
|
||||
|
||||
export const isSystemVar = (valueSelector: ValueSelector) => {
|
||||
return valueSelector[0] === 'sys' || valueSelector[1] === 'sys'
|
||||
|
|
@ -413,7 +414,7 @@ const formatItem = (
|
|||
? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]`
|
||||
: `${output.type.slice(0, 1).toLocaleLowerCase()}${output.type.slice(1)}`,
|
||||
description: output.description,
|
||||
alias: output?.properties?.dify_builtin_type?.enum?.[0],
|
||||
alias: getOutputVariableAlias(output.properties),
|
||||
children: output.type === 'object' ? {
|
||||
schema: {
|
||||
type: 'object',
|
||||
|
|
|
|||
|
|
@ -69,13 +69,10 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
|
|||
? `array[${output.items?.type.slice(0, 1).toLocaleLowerCase()}${output.items?.type.slice(1)}]`
|
||||
: `${dataType.slice(0, 1).toLocaleLowerCase()}${dataType.slice(1)}`,
|
||||
description: output.description,
|
||||
alias: output?.properties?.dify_builtin_type?.enum?.[0],
|
||||
children: output.type === 'object' ? {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(output.properties).filter(([key]) => key !== 'dify_builtin_type'),
|
||||
),
|
||||
properties: output.properties,
|
||||
},
|
||||
} : undefined,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import type { FC } from 'react'
|
||||
import {
|
||||
memo,
|
||||
useCallback,
|
||||
} from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { KnowledgeBaseNodeType } from './types'
|
||||
import {
|
||||
ChunkStructureEnum,
|
||||
IndexMethodEnum,
|
||||
} from './types'
|
||||
import ChunkStructure from './components/chunk-structure'
|
||||
|
|
@ -21,6 +23,8 @@ import {
|
|||
import Split from '../_base/components/split'
|
||||
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
|
||||
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
||||
import type { Var } from '@/app/components/workflow/types'
|
||||
import { CHUNK_TYPE_MAP } from '@/app/components/workflow/utils/tool'
|
||||
|
||||
const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
|
||||
id,
|
||||
|
|
@ -43,6 +47,16 @@ const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
|
|||
handleInputVariableChange,
|
||||
} = useConfig(id)
|
||||
|
||||
const filterVar = useCallback((variable: Var) => {
|
||||
if (data.chunk_structure === ChunkStructureEnum.general && variable.alias === CHUNK_TYPE_MAP.general_chunks)
|
||||
return true
|
||||
if (data.chunk_structure === ChunkStructureEnum.parent_child && variable.alias === CHUNK_TYPE_MAP.parent_child_chunks)
|
||||
return true
|
||||
if (data.chunk_structure === ChunkStructureEnum.question_answer && variable.alias === CHUNK_TYPE_MAP.qa_chunks)
|
||||
return true
|
||||
return false
|
||||
}, [data.chunk_structure])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BoxGroupField
|
||||
|
|
@ -61,6 +75,8 @@ const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
|
|||
value={data.index_chunk_variable_selector}
|
||||
onChange={handleInputVariableChange}
|
||||
readonly={nodesReadOnly}
|
||||
filterVar={filterVar}
|
||||
isSupportFileVar={false}
|
||||
/>
|
||||
</BoxGroupField>
|
||||
<Group
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||
return
|
||||
const inputsWithDefaultValue = formattingParameters()
|
||||
setInputs(inputsWithDefaultValue)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [currTool])
|
||||
|
||||
// setting when call
|
||||
|
|
@ -191,7 +190,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
|||
name: outputKey,
|
||||
type: output.type === 'array'
|
||||
? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]`
|
||||
: `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`,
|
||||
: `${output.type?.slice(0, 1).toLocaleUpperCase()}${output.type?.slice(1)}`,
|
||||
description: output.description,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,19 +44,29 @@ export const getToolCheckParams = (
|
|||
}
|
||||
}
|
||||
|
||||
export const CHUNK_TYPE_MAP = {
|
||||
general_chunks: 'GeneralStructureChunk',
|
||||
parent_child_chunks: 'ParentChildStructureChunk',
|
||||
qa_chunks: 'QAStructureChunk',
|
||||
}
|
||||
|
||||
export const getOutputVariableAlias = (variable: Record<string, any>) => {
|
||||
if (variable?.general_chunks)
|
||||
return CHUNK_TYPE_MAP.general_chunks
|
||||
if (variable?.parent_child_chunks)
|
||||
return CHUNK_TYPE_MAP.parent_child_chunks
|
||||
if (variable?.qa_chunks)
|
||||
return CHUNK_TYPE_MAP.qa_chunks
|
||||
}
|
||||
export const wrapStructuredVarItem = (outputItem: any): StructuredOutput => {
|
||||
const dataType = Type.object
|
||||
const properties = Object.fromEntries(
|
||||
Object.entries(outputItem.value?.properties || {}).filter(([key]) => key !== 'dify_builtin_type'),
|
||||
) as Record<string, any>
|
||||
return {
|
||||
schema: {
|
||||
type: dataType,
|
||||
properties: {
|
||||
[outputItem.name]: {
|
||||
...outputItem.value,
|
||||
properties,
|
||||
alias: outputItem.value?.properties?.dify_builtin_type?.enum?.[0],
|
||||
alias: getOutputVariableAlias(outputItem.value?.properties),
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue