Skip to content

Commit

Permalink
fix: toolNode max tokens and toolDescription i18n (#2655)
Browse files Browse the repository at this point in the history
* fix: toolNode max tokens

* fix: toolNode max tokens

* fix: workflow  tool desc i18n
  • Loading branch information
c121914yu authored Sep 9, 2024
1 parent 6a85c8c commit 08190c2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 58 deletions.
89 changes: 45 additions & 44 deletions projects/app/src/components/support/wallet/QRCodePayModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import MyModal from '@fastgpt/web/components/common/MyModal';
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import { useTranslation } from 'next-i18next';
import { Box, ModalBody } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { checkBalancePayResult } from '@/web/support/wallet/bill/api';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { useRouter } from 'next/router';
Expand All @@ -24,52 +23,54 @@ const QRCodePayModal = ({
const router = useRouter();
const { t } = useTranslation();
const { toast } = useToast();
const dom = document.getElementById('payQRCode');
const dom = useRef<HTMLDivElement>(null);

useEffect(() => {
if (dom && window.QRCode) {
new window.QRCode(dom, {
text: codeUrl,
width: 128,
height: 128,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: window.QRCode.CorrectLevel.H
});
}
}, [dom]);
let timer: NodeJS.Timeout;
const drawCode = () => {
if (dom.current && window.QRCode && !dom.current.innerHTML) {
new window.QRCode(dom.current, {
text: codeUrl,
width: 128,
height: 128,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: window.QRCode.CorrectLevel.H
});
}
};
const check = async () => {
try {
const res = await checkBalancePayResult(billId);
if (res) {
try {
await onSuccess?.();
toast({
title: res,
status: 'success'
});
setTimeout(() => {
router.reload();
}, 1000);
return;
} catch (error) {
toast({
title: getErrText(error),
status: 'error'
});
}
}
} catch (error) {}

useQuery(
[billId],
() => {
if (!billId) return null;
return checkBalancePayResult(billId);
},
{
enabled: !!billId,
refetchInterval: 3000,
onSuccess: async (res) => {
if (!res) return;
drawCode();

try {
await onSuccess?.();
toast({
title: res,
status: 'success'
});
} catch (error) {
toast({
title: getErrText(error),
status: 'error'
});
}
timer = setTimeout(check, 2000);
};

setTimeout(() => {
router.reload();
}, 1000);
}
}
);
check();

return () => clearTimeout(timer);
}, [billId, onSuccess, toast]);

return (
<MyModal isOpen title={t('common:user.Pay')} iconSrc="/imgs/modal/pay.svg">
Expand All @@ -79,7 +80,7 @@ const QRCodePayModal = ({
{tip}
</Box>
)}
<Box id={'payQRCode'} display={'inline-block'} h={'128px'}></Box>
<Box ref={dom} id={'payQRCode'} display={'inline-block'} h={'128px'}></Box>
<Box mt={3} textAlign={'center'}>
{t('common:pay.wechat', { price: readPrice })}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ const NodeDatasetConcat = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
const quoteList = useMemo(() => inputs.filter((item) => item.canEdit), [inputs]);

const tokenLimit = useMemo(() => {
let maxTokens = 3000;
let maxTokens = 13000;

nodeList.forEach((item) => {
if (item.flowNodeType === FlowNodeTypeEnum.chatNode) {
if ([FlowNodeTypeEnum.chatNode, FlowNodeTypeEnum.tools].includes(item.flowNodeType)) {
const model =
item.inputs.find((item) => item.key === NodeInputKeyEnum.aiModel)?.value || '';
const quoteMaxToken = getWebLLMModel(model)?.quoteMaxToken || 3000;
const quoteMaxToken = getWebLLMModel(model)?.quoteMaxToken || 13000;

maxTokens = Math.max(maxTokens, quoteMaxToken);
}
});

return maxTokens;
}, [llmModelList, nodeList]);
}, [nodeList, llmModelList]);

const CustomComponent = useMemo(() => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,13 @@ const MenuRender = React.memo(function MenuRender({
outputs: template.outputs,
version: template.version
},
selected: true
selected: true,
t
})
);
});
},
[computedNewNodeName, setNodes]
[computedNewNodeName, setNodes, t]
);
const onDelNode = useCallback(
(nodeId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ const SelectDatasetParam = ({ inputs = [], nodeId }: RenderInputProps) => {
});

const tokenLimit = useMemo(() => {
let maxTokens = 3000;
let maxTokens = 13000;

nodeList.forEach((item) => {
if (item.flowNodeType === FlowNodeTypeEnum.chatNode) {
if ([FlowNodeTypeEnum.chatNode, FlowNodeTypeEnum.tools].includes(item.flowNodeType)) {
const model =
item.inputs.find((item) => item.key === NodeInputKeyEnum.aiModel)?.value || '';
const quoteMaxToken = getWebLLMModel(model)?.quoteMaxToken || 3000;
const quoteMaxToken = getWebLLMModel(model)?.quoteMaxToken || 13000;

maxTokens = Math.max(maxTokens, quoteMaxToken);
}
});

return maxTokens;
}, [llmModelList, nodeList]);
}, [nodeList, llmModelList]);

const { isOpen, onOpen, onClose } = useDisclosure();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ const WorkflowContextProvider = ({
return resetSnapshot(past[0]);
}

setNodes(e.nodes?.map((item) => storeNode2FlowNode({ item })) || []);
setNodes(e.nodes?.map((item) => storeNode2FlowNode({ item, t })) || []);
setEdges(e.edges?.map((item) => storeEdgesRenderEdge({ edge: item })) || []);

const chatConfig = e.chatConfig;
Expand All @@ -553,7 +553,7 @@ const WorkflowContextProvider = ({
// If it is the initial data, save the initial snapshot
if (isInit) {
saveSnapshot({
pastNodes: e.nodes?.map((item) => storeNode2FlowNode({ item })) || [],
pastNodes: e.nodes?.map((item) => storeNode2FlowNode({ item, t })) || [],
pastEdges: e.edges?.map((item) => storeEdgesRenderEdge({ edge: item })) || [],
customTitle: t(`app:app.version_initial`),
chatConfig: appDetail.chatConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const TeamCloud = () => {
if (!versionDetail) return;

const state = {
nodes: versionDetail.nodes?.map((item) => storeNode2FlowNode({ item })),
nodes: versionDetail.nodes?.map((item) => storeNode2FlowNode({ item, t })),
edges: versionDetail.edges?.map((item) => storeEdgesRenderEdge({ edge: item })),
title: versionItem.versionName,
chatConfig: versionDetail.chatConfig
Expand Down
9 changes: 8 additions & 1 deletion projects/app/src/web/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export const nodeTemplate2FlowNode = ({
};
export const storeNode2FlowNode = ({
item: storeNode,
selected = false
selected = false,
t
}: {
item: StoreNodeItemType;
selected?: boolean;
t: TFunction;
}): Node<FlowNodeItemType> => {
// init some static data
const template =
Expand Down Expand Up @@ -99,6 +101,9 @@ export const storeNode2FlowNode = ({
...storeInput,
...templateInput,

debugLabel: t(templateInput.debugLabel ?? (storeInput.debugLabel as any)),
toolDescription: t(templateInput.toolDescription ?? (storeInput.toolDescription as any)),

selectedTypeIndex: storeInput.selectedTypeIndex ?? templateInput.selectedTypeIndex,
value: storeInput.value ?? templateInput.value,
label: storeInput.label ?? templateInput.label
Expand Down Expand Up @@ -126,6 +131,8 @@ export const storeNode2FlowNode = ({
...storeOutput,
...templateOutput,

description: t(templateOutput.description ?? (storeOutput.description as any)),

id: storeOutput.id ?? templateOutput.id,
label: storeOutput.label ?? templateOutput.label,
value: storeOutput.value ?? templateOutput.value
Expand Down

0 comments on commit 08190c2

Please sign in to comment.