Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Sep 12, 2024
1 parent 5ae8318 commit 337020b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 35 deletions.
3 changes: 2 additions & 1 deletion packages/global/core/workflow/template/system/loopEnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const LoopEndNode: FlowNodeTemplateType = {
valueType: WorkflowIOValueTypeEnum.any,
label: '',
required: true,
value: []
value: [],
showType: true
}
],
outputs: []
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/workflow/type/io.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type FlowNodeInputItemType = InputComponentPropsType & {
// render components params
canEdit?: boolean; // dynamic inputs
isPro?: boolean; // Pro version field
showType?: boolean; // show data type
};

export type FlowNodeOutputItemType = {
Expand Down
10 changes: 9 additions & 1 deletion packages/service/core/workflow/dispatch/tools/runLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
const runNodes = runtimeNodes.filter((node) => childNodes.includes(node.nodeId));
const outputArray = [];
const loopDetail: ChatHistoryItemResType[] = [];
let totalPoints = 0;
let totalTokens = 0;

for (const element of loopInputArray) {
for await (const element of loopInputArray) {
const response = await dispatchWorkFlow({
...props,
runtimeNodes: runNodes.map((node) =>
Expand Down Expand Up @@ -54,10 +56,16 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
)?.loopOutputElement;
outputArray.push(loopOutputElement);
loopDetail.push(...response.flowResponses);
response.flowResponses.forEach((res) => {
totalPoints = totalPoints + (res.totalPoints ?? 0);
totalTokens = totalTokens + (res.tokens ?? 0);
});
}

return {
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: totalPoints,
tokens: totalTokens,
loopInput: loopInputArray,
loopResult: outputArray,
loopDetail: loopDetail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const WholeResponseContent = ({
showDetail: boolean;
}) => {
const { t } = useTranslation();
console.log('activeModule', activeModule);

// Auto scroll to top
const ContentRef = useRef<HTMLDivElement>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ export const useWorkflow = () => {
}
}

customApplyNodeChanges(changes, nodes);

onNodesChange(changes);
};

Expand Down Expand Up @@ -439,7 +437,6 @@ export const useWorkflow = () => {
change.selected = true;
} else {
return (() => {
customApplyNodeChanges(changes, nodes);
onNodesChange(changes);
})();
}
Expand All @@ -458,25 +455,23 @@ export const useWorkflow = () => {
onNodesChange(changes);
resetNodeSizeAndPosition(rect, parentId);
})();
} else if (nodes.find((item) => item.data.parentNodeId === node.id)) {
} else if (nodes.some((item) => item.data.parentNodeId === node.id)) {
const parentId = node.id;
const childNodes = nodes.filter((n) => n.data.parentNodeId === parentId);
const initPosition = node.position;
const deltaX = change.position?.x ? change.position.x - initPosition.x : 0;
const deltaY = change.position?.y ? change.position.y - initPosition.y : 0;
const childNodesChange = childNodes.map((node) => {
const childNodesChange: NodePositionChange[] = childNodes.map((node) => {
if (change.dragging) {
const position = {
x: node.position.x + deltaX,
y: node.position.y + deltaY
};
return {
...change,
id: node.id,
position: {
x: node.position.x + deltaX,
y: node.position.y + deltaY
},
positionAbsolute: {
x: node.position.x + deltaX,
y: node.position.y + deltaY
}
position,
positionAbsolute: position
};
} else {
return {
Expand All @@ -490,11 +485,14 @@ export const useWorkflow = () => {
// changes,
// nodes.filter((node) => !node.data.parentNodeId)
// );
onNodesChange(changes.concat(childNodesChange));
onNodesChange([...changes, ...childNodesChange]);
})();
} else {
return (() => {
customApplyNodeChanges(changes, nodes);
customApplyNodeChanges(
changes,
nodes.filter((node) => !node.data.parentNodeId)
);
onNodesChange(changes);
})();
}
Expand All @@ -509,6 +507,7 @@ export const useWorkflow = () => {

const onNodeDragStop = useCallback(
(_: any, node: Node) => {
if (!node) return;
const intersections = getIntersectingNodes(node);
const parentNode = intersections.find((item) => item.type === FlowNodeTypeEnum.loop);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FlowNodeItemType } from '@fastgpt/global/core/workflow/type/node';
import React, { useCallback, useEffect } from 'react';
import { Background, NodeProps, NodeResizeControl, NodeResizer, OnResize } from 'reactflow';
import React, { useEffect } from 'react';
import { Background, NodeProps } from 'reactflow';
import NodeCard from './render/NodeCard';
import Container from '../components/Container';
import IOTitle from '../components/IOTitle';
import { useTranslation } from 'react-i18next';
import RenderInput from './render/RenderInput';
import { Box, Center, Flex } from '@chakra-ui/react';
import { Box } from '@chakra-ui/react';
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
import RenderOutput from './render/RenderOutput';
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { FlowNodeItemType } from '@fastgpt/global/core/workflow/type/node';
import { useTranslation } from 'react-i18next';
import { NodeProps } from 'reactflow';
import NodeCard from './render/NodeCard';
import EmptyTip from '@fastgpt/web/components/common/EmptyTip';
import Reference from './render/RenderInput/templates/Reference';
import { Box } from '@chakra-ui/react';
import React from 'react';
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';

const NodeLoopEnd = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
const { t } = useTranslation();
const { nodeId, inputs } = data;
const inputItem = inputs.find((input) => input.key === 'loopOutputArrayElement');
const inputItem = inputs.find((input) => input.key === NodeInputKeyEnum.loopOutputArrayElement);

if (!inputItem) return null;
return (
<NodeCard
selected={selected}
Expand All @@ -23,10 +23,10 @@ const NodeLoopEnd = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
}}
>
<Box px={4} pb={4}>
{inputItem && <Reference item={inputItem} nodeId={nodeId} />}
<Reference item={inputItem} nodeId={nodeId} />
</Box>
</NodeCard>
);
};

export default NodeLoopEnd;
export default React.memo(NodeLoopEnd);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@fastgpt/global/core/workflow/constants';
import VariableTable from './NodePluginIO/VariableTable';
import { Box } from '@chakra-ui/react';
import { useEffect } from 'react';
import React, { useEffect } from 'react';
import { FlowNodeOutputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';

const typeMap = {
Expand Down Expand Up @@ -109,4 +109,4 @@ const NodeLoopStart = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
);
};

export default NodeLoopStart;
export default React.memo(NodeLoopStart);
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ type SelectProps = {
children: {
label: string;
value: string;
valueType?: WorkflowIOValueTypeEnum;
}[];
}[];
onSelect: (val: ReferenceValueProps) => void;
styles?: ButtonProps;
showType?: boolean;
};

const Reference = ({ item, nodeId }: RenderInputProps) => {
Expand Down Expand Up @@ -83,6 +85,7 @@ const Reference = ({ item, nodeId }: RenderInputProps) => {
list={referenceList}
value={formatValue}
onSelect={onSelect}
showType={item.showType}
/>
);
};
Expand Down Expand Up @@ -139,7 +142,8 @@ export const useReference = ({
.map((output) => {
return {
label: t((output.label as any) || ''),
value: output.id
value: output.id,
valueType: output.valueType
};
})
};
Expand All @@ -166,7 +170,13 @@ export const useReference = ({
formatValue
};
};
export const ReferSelector = ({ placeholder, value, list = [], onSelect }: SelectProps) => {
export const ReferSelector = ({
placeholder,
value,
list = [],
onSelect,
showType
}: SelectProps) => {
const selectItemLabel = useMemo(() => {
if (!value) {
return;
Expand All @@ -179,7 +189,12 @@ export const ReferSelector = ({ placeholder, value, list = [], onSelect }: Selec
if (!secondColumn) {
return;
}
return [firstColumn, secondColumn];
const valueType = secondColumn.valueType;
return {
firstColumn: firstColumn,
secondColumn: secondColumn,
valueType: valueType
};
}, [list, value]);

const Render = useMemo(() => {
Expand All @@ -188,9 +203,24 @@ export const ReferSelector = ({ placeholder, value, list = [], onSelect }: Selec
label={
selectItemLabel ? (
<Flex alignItems={'center'}>
{selectItemLabel[0].label}
{selectItemLabel.firstColumn.label}
<MyIcon name={'common/rightArrowLight'} mx={1} w={'14px'}></MyIcon>
{selectItemLabel[1].label}
{selectItemLabel.secondColumn.label}
{showType && (
<Box
as={'span'}
border={'base'}
bg={'myGray.100'}
color={'myGray.500'}
px={1.5}
py={'3px'}
rounded={'sm'}
fontSize={'12px'}
ml={2}
>
{selectItemLabel.valueType}
</Box>
)}
</Flex>
) : (
<Box>{placeholder}</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ const WorkflowContextProvider = ({
);

if (isPastEqual) return false;
console.log(currentNodes);

setPast((past) => [
{
Expand Down

0 comments on commit 337020b

Please sign in to comment.