Feat: Add the example component of the classification operator #3221 (#7986)

### What problem does this PR solve?

Feat: Add the example component of the classification operator #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-05-30 19:25:32 +08:00
committed by GitHub
parent 93f5df716f
commit 259a7fc7f1
5 changed files with 147 additions and 95 deletions

View File

@ -1,9 +1,8 @@
import {
DSLComponents,
ICategorizeItem,
ICategorizeItemResult,
RAGFlowNodeType,
} from '@/interfaces/database/flow';
} from '@/interfaces/database/agent';
import { DSLComponents, RAGFlowNodeType } from '@/interfaces/database/flow';
import { removeUselessFieldsFromValues } from '@/utils/form';
import { Edge, Node, Position, XYPosition } from '@xyflow/react';
import { FormInstance, FormListFieldData } from 'antd';
@ -391,6 +390,22 @@ export const generateDuplicateNode = (
};
};
export function convertToStringArray(
list?: Array<{ value: string | number | boolean }>,
) {
if (!Array.isArray(list)) {
return [];
}
return list.map((x) => x.value);
}
export function convertToObjectArray(list: Array<string | number | boolean>) {
if (!Array.isArray(list)) {
return [];
}
return list.map((x) => ({ value: x }));
}
/**
* convert the following object into a list
*
@ -411,7 +426,11 @@ export const buildCategorizeListFromObject = (
.reduce<Array<ICategorizeItem>>((pre, cur) => {
// synchronize edge data to the to field
pre.push({ name: cur, ...categorizeItem[cur] });
pre.push({
name: cur,
...categorizeItem[cur],
examples: convertToObjectArray(categorizeItem[cur].examples),
});
return pre;
}, [])
.sort((a, b) => a.index - b.index);
@ -424,7 +443,7 @@ export const buildCategorizeListFromObject = (
{
"name": "Categorize 1",
"description": "111",
"examples": "ddd",
"examples": ["ddd"],
"to": "Retrieval:LazyEelsStick"
}
]
@ -433,24 +452,11 @@ export const buildCategorizeListFromObject = (
export const buildCategorizeObjectFromList = (list: Array<ICategorizeItem>) => {
return list.reduce<ICategorizeItemResult>((pre, cur) => {
if (cur?.name) {
pre[cur.name] = omit(cur, 'name');
pre[cur.name] = {
...omit(cur, 'name', 'examples'),
examples: convertToStringArray(cur.examples),
};
}
return pre;
}, {});
};
export function convertToStringArray(
list: Array<{ value: string | number | boolean }>,
) {
if (!Array.isArray(list)) {
return [];
}
return list.map((x) => x.value);
}
export function convertToObjectArray(list: Array<string | number | boolean>) {
if (!Array.isArray(list)) {
return [];
}
return list.map((x) => ({ value: x }));
}