mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-04 01:25:07 +08:00
### What problem does this PR solve? Feat: Add a form for variable aggregation operators #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
import { get } from 'lodash';
|
||||
import { get, isPlainObject } from 'lodash';
|
||||
import { ReactNode, useCallback } from 'react';
|
||||
import { AgentStructuredOutputField, Operator } from '../constant';
|
||||
import {
|
||||
AgentStructuredOutputField,
|
||||
JsonSchemaDataType,
|
||||
Operator,
|
||||
} from '../constant';
|
||||
import useGraphStore from '../store';
|
||||
|
||||
function getNodeId(value: string) {
|
||||
@ -82,3 +86,70 @@ export function useFindAgentStructuredOutputLabel() {
|
||||
|
||||
return findAgentStructuredOutputLabel;
|
||||
}
|
||||
|
||||
export function useFindAgentStructuredOutputTypeByValue() {
|
||||
const { getOperatorTypeFromId } = useGraphStore((state) => state);
|
||||
const filterStructuredOutput = useGetStructuredOutputByValue();
|
||||
|
||||
const findTypeByValue = useCallback(
|
||||
(
|
||||
values: unknown,
|
||||
target: string,
|
||||
path: string = '',
|
||||
): string | undefined => {
|
||||
const properties =
|
||||
get(values, 'properties') || get(values, 'items.properties');
|
||||
|
||||
if (isPlainObject(values) && properties) {
|
||||
for (const [key, value] of Object.entries(properties)) {
|
||||
const nextPath = path ? `${path}.${key}` : key;
|
||||
const dataType = get(value, 'type');
|
||||
|
||||
if (nextPath === target) {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
if (
|
||||
[JsonSchemaDataType.Object, JsonSchemaDataType.Array].some(
|
||||
(x) => x === dataType,
|
||||
)
|
||||
) {
|
||||
const type = findTypeByValue(value, target, nextPath);
|
||||
if (type) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const findAgentStructuredOutputTypeByValue = useCallback(
|
||||
(value?: string) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
const fields = value.split('@');
|
||||
const nodeId = fields.at(0);
|
||||
const jsonSchema = filterStructuredOutput(value);
|
||||
|
||||
if (
|
||||
getOperatorTypeFromId(nodeId) === Operator.Agent &&
|
||||
fields.at(1)?.startsWith(AgentStructuredOutputField)
|
||||
) {
|
||||
const jsonSchemaFields = fields
|
||||
.at(1)
|
||||
?.slice(AgentStructuredOutputField.length + 1);
|
||||
|
||||
if (jsonSchemaFields) {
|
||||
const type = findTypeByValue(jsonSchema, jsonSchemaFields);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
},
|
||||
[filterStructuredOutput, findTypeByValue, getOperatorTypeFromId],
|
||||
);
|
||||
|
||||
return findAgentStructuredOutputTypeByValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user