mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-26 00:46:52 +08:00
Feat: The query variables of the subsequent operators can reference the structured variables defined in the agent operator. #10866 (#10902)
### What problem does this PR solve? Feat: The query variables of the subsequent operators can reference the structured variables defined in the agent operator. #10866 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
44
web/src/pages/agent/utils/filter-agent-structured-output.ts
Normal file
44
web/src/pages/agent/utils/filter-agent-structured-output.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { JSONSchema } from '@/components/jsonjoy-builder';
|
||||
import { Operator } from '@/constants/agent';
|
||||
import { isPlainObject } from 'lodash';
|
||||
|
||||
export function filterAgentStructuredOutput(
|
||||
structuredOutput: JSONSchema,
|
||||
operator?: string,
|
||||
) {
|
||||
if (typeof structuredOutput === 'boolean') {
|
||||
return structuredOutput;
|
||||
}
|
||||
if (
|
||||
structuredOutput.properties &&
|
||||
isPlainObject(structuredOutput.properties)
|
||||
) {
|
||||
const filterByPredicate = (predicate: (value: JSONSchema) => boolean) => {
|
||||
const properties = Object.entries({
|
||||
...structuredOutput.properties,
|
||||
}).reduce(
|
||||
(pre, [key, value]) => {
|
||||
if (predicate(value)) {
|
||||
pre[key] = value;
|
||||
}
|
||||
return pre;
|
||||
},
|
||||
{} as Record<string, JSONSchema>,
|
||||
);
|
||||
|
||||
return { ...structuredOutput, properties };
|
||||
};
|
||||
|
||||
if (operator === Operator.Iteration) {
|
||||
return filterByPredicate(
|
||||
(value) => typeof value !== 'boolean' && value.type === 'array',
|
||||
);
|
||||
} else {
|
||||
return filterByPredicate(
|
||||
(value) => typeof value !== 'boolean' && value.type !== 'array',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return structuredOutput;
|
||||
}
|
||||
Reference in New Issue
Block a user