Skip to content

Commit

Permalink
4.8 test (#1382)
Browse files Browse the repository at this point in the history
* perf: some log, chatTest histories slice; http request failed tip

* fix: ssr render

* perf: if else node ui and fix value type select
  • Loading branch information
c121914yu authored May 7, 2024
1 parent 2053bbd commit 8f9203c
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const IfElseNode: FlowNodeTemplateType = {
{
id: NodeOutputKeyEnum.ifElseResult,
key: NodeOutputKeyEnum.ifElseResult,
label: 'IF ELSE',
label: '判断结果',
valueType: WorkflowIOValueTypeEnum.string,
type: FlowNodeOutputTypeEnum.static
}
Expand Down
7 changes: 4 additions & 3 deletions packages/global/core/workflow/type/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type FlowNodeCommonType = {
};

export type FlowNodeTemplateType = FlowNodeCommonType & {
id: string; // module id, unique
id: string; // node id, unique
templateType: `${FlowNodeTemplateTypeEnum}`;

// show handle
Expand Down Expand Up @@ -132,11 +132,12 @@ export type ChatDispatchProps = {
chatId?: string;
responseChatItemId?: string;
histories: ChatItemType[];
variables: Record<string, any>;
query: UserChatItemValueItemType[];
variables: Record<string, any>; // global variable
query: UserChatItemValueItemType[]; // trigger query
stream: boolean;
detail: boolean; // response detail
maxRunTimes: number;
isToolCall?: boolean;
};

export type ModuleDispatchProps<T> = ChatDispatchProps & {
Expand Down
5 changes: 3 additions & 2 deletions packages/service/core/ai/rerank/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addLog } from '../../../common/system/log';
import { POST } from '../../../common/api/serverRequest';

type PostReRankResponse = {
Expand Down Expand Up @@ -38,15 +39,15 @@ export function reRankRecall({
}
)
.then((data) => {
console.log('rerank time:', Date.now() - start);
addLog.info('ReRank finish:', { time: Date.now() - start });

return data?.results?.map((item) => ({
id: documents[item.index].id,
score: item.relevance_score
}));
})
.catch((err) => {
console.log('rerank error:', err);
addLog.error('rerank error', err);

return [];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const runToolWithFunctionCall = async (

const toolRunResponse = await dispatchWorkFlow({
...props,
isToolCall: true,
runtimeNodes: runtimeNodes.map((item) =>
item.nodeId === toolNode.nodeId
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const runToolWithPromptCall = async (

const moduleRunResponse = await dispatchWorkFlow({
...props,
isToolCall: true,
runtimeNodes: runtimeNodes.map((item) =>
item.nodeId === toolNode.nodeId
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const runToolWithToolChoice = async (

const toolRunResponse = await dispatchWorkFlow({
...props,
isToolCall: true,
runtimeNodes: runtimeNodes.map((item) =>
item.nodeId === toolNode.nodeId
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ export type UserChatInputProps = ModuleDispatchProps<{
}>;

export const dispatchWorkflowStart = (props: Record<string, any>) => {
const { query } = props as UserChatInputProps;
const {
query,
params: { userChatInput }
} = props as UserChatInputProps;

const { text, files } = chatValue2RuntimePrompt(query);

return {
[NodeInputKeyEnum.userChatInput]: text,
[NodeInputKeyEnum.userChatInput]: text || userChatInput,
[NodeInputKeyEnum.inputFiles]: files
};
};
27 changes: 16 additions & 11 deletions packages/service/core/workflow/dispatch/tools/http468.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
variables,
node: { outputs },
histories,
isToolCall,
params: {
system_httpMethod: httpMethod = 'POST',
system_httpReqUrl: httpReqUrl,
Expand Down Expand Up @@ -156,17 +157,21 @@ export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<H
};
} catch (error) {
addLog.error('Http request error', error);
return {
[NodeOutputKeyEnum.failed]: true,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: 0,
params: Object.keys(params).length > 0 ? params : undefined,
body: Object.keys(requestBody).length > 0 ? requestBody : undefined,
headers: Object.keys(headers).length > 0 ? headers : undefined,
httpResult: { error: formatHttpError(error) }
},
[NodeOutputKeyEnum.httpRawResponse]: getErrText(error)
};

if (isToolCall) {
return {
[NodeOutputKeyEnum.failed]: true,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: 0,
params: Object.keys(params).length > 0 ? params : undefined,
body: Object.keys(requestBody).length > 0 ? requestBody : undefined,
headers: Object.keys(headers).length > 0 ? headers : undefined,
httpResult: { error: formatHttpError(error) }
},
[NodeOutputKeyEnum.httpRawResponse]: getErrText(error)
};
}
return Promise.reject(error);
}
};

Expand Down
8 changes: 6 additions & 2 deletions packages/service/core/workflow/dispatch/tools/runIfElse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import { DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type';
import { VariableConditionEnum } from '@fastgpt/global/core/workflow/template/system/ifElse/constant';
Expand All @@ -15,6 +15,9 @@ type Props = ModuleDispatchProps<{
[NodeInputKeyEnum.condition]: IfElseConditionType;
[NodeInputKeyEnum.ifElseList]: IfElseListItemType[];
}>;
type Response = DispatchNodeResultType<{
[NodeOutputKeyEnum.ifElseResult]: string;
}>;

function checkCondition(condition: VariableConditionEnum, variableValue: any, value: string) {
const operations = {
Expand Down Expand Up @@ -63,7 +66,7 @@ function getResult(
return condition === 'AND' ? listResult.every(Boolean) : listResult.some(Boolean);
}

export const dispatchIfElse = async (props: Props): Promise<DispatchNodeResultType<{}>> => {
export const dispatchIfElse = async (props: Props): Promise<Response> => {
const {
params,
runtimeNodes,
Expand All @@ -88,6 +91,7 @@ export const dispatchIfElse = async (props: Props): Promise<DispatchNodeResultTy
});

return {
[NodeOutputKeyEnum.ifElseResult]: res,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
totalPoints: 0,
ifElseResult: res
Expand Down
4 changes: 3 additions & 1 deletion packages/web/hooks/useBeforeunload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const useBeforeunload = (props?: { callback?: () => any; tip?: string })
e.returnValue = tip;
callback?.();
}
: () => {};
: () => {
callback?.();
};
window.addEventListener('beforeunload', listen);

return () => {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions projects/app/src/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import MyIcon from '@fastgpt/web/components/common/Icon';
import { getFileAndOpen } from '@/web/core/dataset/utils';
import { MARKDOWN_QUOTE_SIGN } from '@fastgpt/global/core/chat/constants';

const CodeLight = dynamic(() => import('./CodeLight'));
const MermaidCodeBlock = dynamic(() => import('./img/MermaidCodeBlock'));
const MdImage = dynamic(() => import('./img/Image'));
const EChartsCodeBlock = dynamic(() => import('./img/EChartsCodeBlock'));
const CodeLight = dynamic(() => import('./CodeLight'), { ssr: false });
const MermaidCodeBlock = dynamic(() => import('./img/MermaidCodeBlock'), { ssr: false });
const MdImage = dynamic(() => import('./img/Image'), { ssr: false });
const EChartsCodeBlock = dynamic(() => import('./img/EChartsCodeBlock'), { ssr: false });

const ChatGuide = dynamic(() => import('./chat/Guide'));
const QuestionGuide = dynamic(() => import('./chat/QuestionGuide'));
const ChatGuide = dynamic(() => import('./chat/Guide'), { ssr: false });
const QuestionGuide = dynamic(() => import('./chat/QuestionGuide'), { ssr: false });

export enum CodeClassName {
guide = 'guide',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ChatTest = (
}
});
});
const history = chatList.slice(-historyMaxLen - 2, -2);
const history = chatList.slice(-(historyMaxLen * 2) - 2, -2);

// 流请求,获取数据
const { responseText, responseData, newVariables } = await streamFetch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import MyInput from '@/components/MyInput';
import { getHandleId } from '@fastgpt/global/core/workflow/utils';
import { SourceHandle } from '../render/Handle';
import { Position, useReactFlow } from 'reactflow';
import { getReferenceDataValueType } from '@/web/core/workflow/utils';

const ListItem = ({
provided,
Expand Down Expand Up @@ -305,19 +306,17 @@ const ConditionSelect = ({
variable?: ReferenceValueProps;
onSelect: (e: VariableConditionEnum) => void;
}) => {
const { t } = useTranslation();
const nodeList = useContextSelector(WorkflowContext, (v) => v.nodeList);

// get condition type
const valueType = useMemo(() => {
if (!variable) return;
const node = nodeList.find((node) => node.nodeId === variable[0]);

if (!node) return WorkflowIOValueTypeEnum.any;
const output = node.outputs.find((item) => item.id === variable[1]);

if (!output) return WorkflowIOValueTypeEnum.any;
return output.valueType;
}, [nodeList, variable]);
return getReferenceDataValueType({
variable,
nodeList,
t
});
}, [nodeList, t, variable]);

const conditionList = useMemo(() => {
if (valueType === WorkflowIOValueTypeEnum.string) return stringConditionList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { SmallAddIcon } from '@chakra-ui/icons';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import { ReferenceValueProps } from '@fastgpt/global/core/workflow/type/io';
import { ReferSelector, useReference } from './render/RenderInput/templates/Reference';
import { getWorkflowGlobalVariables } from '@/web/core/workflow/utils';
import { getReferenceDataValueType } from '@/web/core/workflow/utils';
import { isReferenceValue } from '@fastgpt/global/core/workflow/utils';

const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
Expand Down Expand Up @@ -82,19 +82,11 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) =>
return (
<>
{updateList.map((updateItem, index) => {
const valueType = (() => {
const variable = updateItem.variable;
const variableNodeId = variable?.[0];
const variableNode = nodeList.find((node) => node.nodeId === variableNodeId);
const systemVariables = getWorkflowGlobalVariables(nodeList, t);

const variableInput = !variableNode
? systemVariables.find((item) => item.key === variable?.[1])
: variableNode.outputs.find((output) => output.id === variable?.[1]);

if (!variableInput) return WorkflowIOValueTypeEnum.any;
return variableInput.valueType;
})();
const valueType = getReferenceDataValueType({
variable: updateItem.variable,
nodeList,
t
});

const renderTypeData = menuList.find((item) => item.renderType === updateItem.renderType);
const handleUpdate = (newValue: ReferenceValueProps | string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const NodeCard = (props: Props) => {
return (
<Box position={'relative'}>
{/* debug */}
<NodeDebugResponse nodeId={nodeId} debugResult={debugResult} />
<Box className="custom-drag-handle" px={4} py={3}>
{/* tool target handle */}
{showToolHandle && <ToolTargetHandle nodeId={nodeId} />}
Expand Down Expand Up @@ -134,7 +133,6 @@ const NodeCard = (props: Props) => {
);
}, [
nodeId,
debugResult,
showToolHandle,
avatar,
t,
Expand Down Expand Up @@ -179,6 +177,7 @@ const NodeCard = (props: Props) => {
borderColor: selected ? 'primary.600' : 'borderColor.base'
})}
>
<NodeDebugResponse nodeId={nodeId} debugResult={debugResult} />
{Header}
{children}
<ConnectionSourceHandle nodeId={nodeId} />
Expand Down Expand Up @@ -259,6 +258,22 @@ const MenuRender = React.memo(function MenuRender({
},
[setEdges, setNodes]
);
const onclickSyncVersion = useCallback(async () => {
if (!pluginId) return;
try {
setLoading(true);
onResetNode({
id: nodeId,
node: await getPreviewPluginModule(pluginId)
});
} catch (e) {
return toast({
status: 'error',
title: getErrText(e, t('plugin.Get Plugin Module Detail Failed'))
});
}
setLoading(false);
}, [nodeId, onResetNode, pluginId, setLoading, t, toast]);

const Render = useMemo(() => {
const menuList = [
Expand Down Expand Up @@ -288,25 +303,7 @@ const MenuRender = React.memo(function MenuRender({
icon: 'common/refreshLight',
label: t('plugin.Synchronous version'),
variant: 'whiteBase',
onClick: () => {
if (!pluginId) return;
onOpenConfirmSync(async () => {
try {
setLoading(true);
const pluginModule = await getPreviewPluginModule(pluginId);
onResetNode({
id: nodeId,
module: pluginModule
});
} catch (e) {
return toast({
status: 'error',
title: getErrText(e, t('plugin.Get Plugin Module Detail Failed'))
});
}
setLoading(false);
})();
}
onClick: onOpenConfirmSync(onclickSyncVersion)
}
]
: []),
Expand Down Expand Up @@ -370,12 +367,9 @@ const MenuRender = React.memo(function MenuRender({
onDelNode,
onOpenConfirmDeleteNode,
onOpenConfirmSync,
onResetNode,
onclickSyncVersion,
openDebugNode,
pluginId,
setLoading,
t,
toast
t
]);

return Render;
Expand Down Expand Up @@ -530,7 +524,8 @@ const NodeDebugResponse = React.memo(function NodeDebugResponse({
top={0}
zIndex={10}
w={'420px'}
maxH={'540px'}
maxH={'100%'}
minH={'300px'}
overflowY={'auto'}
border={'base'}
>
Expand Down
Loading

0 comments on commit 8f9203c

Please sign in to comment.