mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
fix: toolNode max tokens and toolDescription i18n (#2655)
* fix: toolNode max tokens * fix: toolNode max tokens * fix: workflow tool desc i18n
This commit is contained in:
@@ -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';
|
||||
@@ -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]);
|
||||
|
||||
useQuery(
|
||||
[billId],
|
||||
() => {
|
||||
if (!billId) return null;
|
||||
return checkBalancePayResult(billId);
|
||||
},
|
||||
{
|
||||
enabled: !!billId,
|
||||
refetchInterval: 3000,
|
||||
onSuccess: async (res) => {
|
||||
if (!res) return;
|
||||
|
||||
try {
|
||||
await onSuccess?.();
|
||||
toast({
|
||||
title: res,
|
||||
status: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: getErrText(error),
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
router.reload();
|
||||
}, 1000);
|
||||
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) {}
|
||||
|
||||
drawCode();
|
||||
|
||||
timer = setTimeout(check, 2000);
|
||||
};
|
||||
|
||||
check();
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [billId, onSuccess, toast]);
|
||||
|
||||
return (
|
||||
<MyModal isOpen title={t('common:user.Pay')} iconSrc="/imgs/modal/pay.svg">
|
||||
@@ -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>
|
||||
|
@@ -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 {
|
||||
|
@@ -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) => {
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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;
|
||||
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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 =
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user