mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-25 16:26:51 +08:00
### What problem does this PR solve? Feat: Filter structured output data directly during the rendering stage. #10866 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -2,64 +2,6 @@ import { JSONSchema } from '@/components/jsonjoy-builder';
|
||||
import { get, isPlainObject } from 'lodash';
|
||||
import { JsonSchemaDataType } from '../constant';
|
||||
|
||||
// Loop operators can only accept variables of type list.
|
||||
|
||||
// Recursively traverse the JSON schema, keeping attributes with type "array" and discarding others.
|
||||
|
||||
export function filterLoopOperatorInput(
|
||||
structuredOutput: JSONSchema,
|
||||
type: string,
|
||||
path = [],
|
||||
) {
|
||||
if (typeof structuredOutput === 'boolean') {
|
||||
return structuredOutput;
|
||||
}
|
||||
if (
|
||||
structuredOutput.properties &&
|
||||
isPlainObject(structuredOutput.properties)
|
||||
) {
|
||||
const properties = Object.entries({
|
||||
...structuredOutput.properties,
|
||||
}).reduce(
|
||||
(pre, [key, value]) => {
|
||||
if (
|
||||
typeof value !== 'boolean' &&
|
||||
(value.type === type || hasArrayChild(value))
|
||||
) {
|
||||
pre[key] = filterLoopOperatorInput(value, type, path);
|
||||
}
|
||||
return pre;
|
||||
},
|
||||
{} as Record<string, JSONSchema>,
|
||||
);
|
||||
|
||||
return { ...structuredOutput, properties };
|
||||
}
|
||||
|
||||
return structuredOutput;
|
||||
}
|
||||
|
||||
export function filterAgentStructuredOutput(
|
||||
structuredOutput: JSONSchema,
|
||||
type?: string,
|
||||
) {
|
||||
if (typeof structuredOutput === 'boolean') {
|
||||
return structuredOutput;
|
||||
}
|
||||
if (
|
||||
structuredOutput.properties &&
|
||||
isPlainObject(structuredOutput.properties)
|
||||
) {
|
||||
if (type) {
|
||||
return filterLoopOperatorInput(structuredOutput, type);
|
||||
}
|
||||
|
||||
return structuredOutput;
|
||||
}
|
||||
|
||||
return structuredOutput;
|
||||
}
|
||||
|
||||
export function hasSpecificTypeChild(
|
||||
data: Record<string, any> | Array<any>,
|
||||
type: string,
|
||||
|
||||
Reference in New Issue
Block a user