mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 13:56:00 +08:00
fix: handle array item type error in struct output (#18452)
This commit is contained in:
parent
0ba37592f7
commit
5d9c67e97e
@ -57,7 +57,14 @@ const inputVarTypeToVarType = (type: InputVarType): VarType => {
|
|||||||
} as any)[type] || VarType.string
|
} as any)[type] || VarType.string
|
||||||
}
|
}
|
||||||
|
|
||||||
const structTypeToVarType = (type: Type): VarType => {
|
const structTypeToVarType = (type: Type, isArray?: boolean): VarType => {
|
||||||
|
if (isArray) {
|
||||||
|
return ({
|
||||||
|
[Type.string]: VarType.arrayString,
|
||||||
|
[Type.number]: VarType.arrayNumber,
|
||||||
|
[Type.object]: VarType.arrayObject,
|
||||||
|
} as any)[type] || VarType.string
|
||||||
|
}
|
||||||
return ({
|
return ({
|
||||||
[Type.string]: VarType.string,
|
[Type.string]: VarType.string,
|
||||||
[Type.number]: VarType.number,
|
[Type.number]: VarType.number,
|
||||||
@ -82,9 +89,12 @@ const findExceptVarInStructuredProperties = (properties: Record<string, StructFi
|
|||||||
Object.keys(properties).forEach((key) => {
|
Object.keys(properties).forEach((key) => {
|
||||||
const item = properties[key]
|
const item = properties[key]
|
||||||
const isObj = item.type === Type.object
|
const isObj = item.type === Type.object
|
||||||
|
const isArray = item.type === Type.array
|
||||||
|
const arrayType = item.items?.type
|
||||||
|
|
||||||
if (!isObj && !filterVar({
|
if (!isObj && !filterVar({
|
||||||
variable: key,
|
variable: key,
|
||||||
type: structTypeToVarType(item.type),
|
type: structTypeToVarType(isArray ? arrayType! : item.type, isArray),
|
||||||
}, [key])) {
|
}, [key])) {
|
||||||
delete properties[key]
|
delete properties[key]
|
||||||
return
|
return
|
||||||
@ -103,9 +113,11 @@ const findExceptVarInStructuredOutput = (structuredOutput: StructuredOutput, fil
|
|||||||
Object.keys(properties).forEach((key) => {
|
Object.keys(properties).forEach((key) => {
|
||||||
const item = properties[key]
|
const item = properties[key]
|
||||||
const isObj = item.type === Type.object
|
const isObj = item.type === Type.object
|
||||||
|
const isArray = item.type === Type.array
|
||||||
|
const arrayType = item.items?.type
|
||||||
if (!isObj && !filterVar({
|
if (!isObj && !filterVar({
|
||||||
variable: key,
|
variable: key,
|
||||||
type: structTypeToVarType(item.type),
|
type: structTypeToVarType(isArray ? arrayType! : item.type, isArray),
|
||||||
}, [key])) {
|
}, [key])) {
|
||||||
delete properties[key]
|
delete properties[key]
|
||||||
return
|
return
|
||||||
@ -1314,9 +1326,12 @@ const varToValueSelectorList = (v: Var, parentValueSelector: ValueSelector, res:
|
|||||||
}
|
}
|
||||||
if (isStructuredOutput) {
|
if (isStructuredOutput) {
|
||||||
Object.keys((v.children as StructuredOutput)?.schema?.properties || {}).forEach((key) => {
|
Object.keys((v.children as StructuredOutput)?.schema?.properties || {}).forEach((key) => {
|
||||||
|
const type = (v.children as StructuredOutput)?.schema?.properties[key].type
|
||||||
|
const isArray = type === Type.array
|
||||||
|
const arrayType = (v.children as StructuredOutput)?.schema?.properties[key].items?.type
|
||||||
varToValueSelectorList({
|
varToValueSelectorList({
|
||||||
variable: key,
|
variable: key,
|
||||||
type: structTypeToVarType((v.children as StructuredOutput)?.schema?.properties[key].type),
|
type: structTypeToVarType(isArray ? arrayType! : type, isArray),
|
||||||
}, [...parentValueSelector, v.variable], res)
|
}, [...parentValueSelector, v.variable], res)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,9 @@ export enum Type {
|
|||||||
boolean = 'boolean',
|
boolean = 'boolean',
|
||||||
object = 'object',
|
object = 'object',
|
||||||
array = 'array',
|
array = 'array',
|
||||||
|
arrayString = 'array[string]',
|
||||||
|
arrayNumber = 'array[number]',
|
||||||
|
arrayObject = 'array[object]',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ArrayType {
|
export enum ArrayType {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user