Просмотр исходного кода

Feat: Reference the output variable of the upstream operator #3221 (#8111)

### What problem does this PR solve?
Feat: Reference the output variable of the upstream operator #3221
### Type of change


- [x] New Feature (non-breaking change which adds functionality)
tags/v0.19.1
balibabu 5 месяцев назад
Родитель
Сommit
06463135ef
Аккаунт пользователя с таким Email не найден

+ 3
- 8
web/src/pages/agent/form/components/prompt-editor/variable-picker-plugin.tsx Просмотреть файл



const [queryString, setQueryString] = React.useState<string | null>(''); const [queryString, setQueryString] = React.useState<string | null>('');


const buildGroupedOptions = useBuildComponentIdSelectOptions(
node?.id,
node?.parentId,
);
const options = useBuildComponentIdSelectOptions(node?.id, node?.parentId);


const buildNextOptions = useCallback(() => { const buildNextOptions = useCallback(() => {
const options = buildGroupedOptions();
let filteredOptions = options; let filteredOptions = options;


if (queryString) { if (queryString) {
); );


return nextOptions; return nextOptions;
}, [buildGroupedOptions, queryString]);
}, [options, queryString]);


const findLabelByValue = useCallback( const findLabelByValue = useCallback(
(value: string) => { (value: string) => {
const options = buildGroupedOptions();
const children = options.reduce<Array<{ label: string; value: string }>>( const children = options.reduce<Array<{ label: string; value: string }>>(
(pre, cur) => { (pre, cur) => {
return pre.concat(cur.options); return pre.concat(cur.options);


return children.find((x) => x.value === value)?.label; return children.find((x) => x.value === value)?.label;
}, },
[buildGroupedOptions],
[options],
); );


const onSelectOption = useCallback( const onSelectOption = useCallback(

+ 2
- 1
web/src/pages/agent/form/invoke-form/dynamic-variables.tsx Просмотреть файл

import { Button, Collapse, Flex, Input, Select, Table, TableProps } from 'antd'; import { Button, Collapse, Flex, Input, Select, Table, TableProps } from 'antd';
import { trim } from 'lodash'; import { trim } from 'lodash';
import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query'; import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query';
import { IInvokeVariable, RAGFlowNodeType } from '../../interface';
import { IInvokeVariable } from '../../interface';
import { useHandleOperateParameters } from './hooks'; import { useHandleOperateParameters } from './hooks';


import { RAGFlowNodeType } from '@/interfaces/database/flow';
import styles from './index.less'; import styles from './index.less';


interface IProps { interface IProps {

+ 65
- 6
web/src/pages/agent/hooks/use-get-begin-query.tsx Просмотреть файл

import { RAGFlowNodeType } from '@/interfaces/database/flow'; import { RAGFlowNodeType } from '@/interfaces/database/flow';
import { Edge } from '@xyflow/react';
import { DefaultOptionType } from 'antd/es/select'; import { DefaultOptionType } from 'antd/es/select';
import { isEmpty } from 'lodash';
import get from 'lodash/get'; import get from 'lodash/get';
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from 'react';
import { BeginId, Operator } from '../constant'; import { BeginId, Operator } from '../constant';
return isBeginNodeDataQuerySafe; return isBeginNodeDataQuerySafe;
}; };


function filterAllUpstreamNodeIds(edges: Edge[], nodeIds: string[]) {
return nodeIds.reduce<string[]>((pre, nodeId) => {
const currentEdges = edges.filter((x) => x.target === nodeId);

const upstreamNodeIds: string[] = currentEdges.map((x) => x.source);

const ids = upstreamNodeIds.concat(
filterAllUpstreamNodeIds(edges, upstreamNodeIds),
);

ids.forEach((x) => {
if (pre.every((y) => y !== x)) {
pre.push(x);
}
});

return pre;
}, []);
}

function buildOutputOptions(outputs: Record<string, any> = {}) {
return Object.keys(outputs).map((x) => ({
label: x,
value: x,
}));
}

export function useBuildNodeOutputOptions(nodeId?: string) {
const nodes = useGraphStore((state) => state.nodes);
const edges = useGraphStore((state) => state.edges);

const nodeOutputOptions = useMemo(() => {
if (!nodeId) {
return [];
}
const upstreamIds = filterAllUpstreamNodeIds(edges, [nodeId]);

const nodeWithOutputList = nodes.filter(
(x) =>
upstreamIds.some((y) => y === x.id) && !isEmpty(x.data?.form?.outputs),
);

return nodeWithOutputList
.filter((x) => x.id !== nodeId)
.map((x) => ({
label: x.data.name,
value: x.id,
title: x.data.name,
options: buildOutputOptions(x.data.form.outputs),
}));
}, [edges, nodeId, nodes]);

return nodeOutputOptions;
}

// exclude nodes with branches // exclude nodes with branches
const ExcludedNodes = [ const ExcludedNodes = [
Operator.Categorize, Operator.Categorize,
const nodes = useGraphStore((state) => state.nodes); const nodes = useGraphStore((state) => state.nodes);
const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); const getBeginNodeDataQuery = useGetBeginNodeDataQuery();


const nodeOutputOptions = useBuildNodeOutputOptions(nodeId);

// Limit the nodes inside iteration to only reference peer nodes with the same parentId and other external nodes other than their parent nodes // Limit the nodes inside iteration to only reference peer nodes with the same parentId and other external nodes other than their parent nodes
const filterChildNodesToSameParentOrExternal = useCallback( const filterChildNodesToSameParentOrExternal = useCallback(
(node: RAGFlowNodeType) => { (node: RAGFlowNodeType) => {
.map((x) => ({ label: x.data.name, value: x.id })); .map((x) => ({ label: x.data.name, value: x.id }));
}, [nodes, nodeId, filterChildNodesToSameParentOrExternal]); }, [nodes, nodeId, filterChildNodesToSameParentOrExternal]);


const buildGroupedOptions = useCallback(() => {
const options = useMemo(() => {
const query: BeginQuery[] = getBeginNodeDataQuery(); const query: BeginQuery[] = getBeginNodeDataQuery();
return [ return [
{ {
value: `begin@${x.key}`, value: `begin@${x.key}`,
})), })),
}, },
...nodeOutputOptions,
]; ];
}, [componentIdOptions, getBeginNodeDataQuery]);
}, [componentIdOptions, getBeginNodeDataQuery, nodeOutputOptions]);


return buildGroupedOptions;
return options;
}; };


export const useGetComponentLabelByValue = (nodeId: string) => { export const useGetComponentLabelByValue = (nodeId: string) => {
const buildGroupedOptions = useBuildComponentIdSelectOptions(nodeId);
const options = useBuildComponentIdSelectOptions(nodeId);


const flattenOptions = useMemo(() => { const flattenOptions = useMemo(() => {
const options = buildGroupedOptions();
return options.reduce<DefaultOptionType[]>((pre, cur) => { return options.reduce<DefaultOptionType[]>((pre, cur) => {
return [...pre, ...cur.options]; return [...pre, ...cur.options];
}, []); }, []);
}, [buildGroupedOptions]);
}, [options]);


const getLabel = useCallback( const getLabel = useCallback(
(val?: string) => { (val?: string) => {

Загрузка…
Отмена
Сохранить