mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 04:06:18 +00:00
perf: isPc check;perf: dataset max token checker (#4872)
* perf: isPc check * perf: dataset max token checker * perf: dataset max token checker
This commit is contained in:
@@ -60,5 +60,3 @@ export enum AppTemplateTypeEnum {
|
||||
// special type
|
||||
contribute = 'contribute'
|
||||
}
|
||||
|
||||
export const defaultDatasetMaxTokens = 16000;
|
||||
|
@@ -11,40 +11,6 @@ export const beforeUpdateAppFormat = <T extends AppSchema['modules'] | undefined
|
||||
nodes: T;
|
||||
isPlugin: boolean;
|
||||
}) => {
|
||||
if (nodes) {
|
||||
// Check dataset maxTokens
|
||||
if (isPlugin) {
|
||||
let maxTokens = 16000;
|
||||
|
||||
nodes.forEach((item) => {
|
||||
if (
|
||||
item.flowNodeType === FlowNodeTypeEnum.chatNode ||
|
||||
item.flowNodeType === FlowNodeTypeEnum.tools
|
||||
) {
|
||||
const model =
|
||||
item.inputs.find((item) => item.key === NodeInputKeyEnum.aiModel)?.value || '';
|
||||
const chatModel = getLLMModel(model);
|
||||
const quoteMaxToken = chatModel.quoteMaxToken || 16000;
|
||||
|
||||
maxTokens = Math.max(maxTokens, quoteMaxToken);
|
||||
}
|
||||
});
|
||||
|
||||
nodes.forEach((item) => {
|
||||
if (item.flowNodeType === FlowNodeTypeEnum.datasetSearchNode) {
|
||||
item.inputs.forEach((input) => {
|
||||
if (input.key === NodeInputKeyEnum.datasetMaxTokens) {
|
||||
const val = input.value as number;
|
||||
if (val > maxTokens) {
|
||||
input.value = maxTokens;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
nodes
|
||||
};
|
||||
|
@@ -18,10 +18,10 @@ export const getWebReqUrl = (url: string = '') => {
|
||||
};
|
||||
|
||||
export const isMobile = () => {
|
||||
// 服务端渲染时返回 false
|
||||
// SSR return false
|
||||
if (typeof window === 'undefined') return false;
|
||||
|
||||
// 1. 检查 User-Agent
|
||||
// 1. Check User-Agent
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
const mobileKeywords = [
|
||||
'android',
|
||||
@@ -36,12 +36,12 @@ export const isMobile = () => {
|
||||
];
|
||||
const isMobileUA = mobileKeywords.some((keyword) => userAgent.includes(keyword));
|
||||
|
||||
// 2. 检查屏幕宽度
|
||||
// 2. Check screen width
|
||||
const isMobileWidth = window.innerWidth <= 900;
|
||||
|
||||
// 3. 检查是否支持触摸事件(排除触控屏PC)
|
||||
// 3. Check if touch events are supported (exclude touch screen PCs)
|
||||
const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
||||
|
||||
// 综合判断:满足以下任一条件即视为移动端
|
||||
// If any of the following conditions are met, it is considered a mobile device
|
||||
return isMobileUA || (isMobileWidth && isTouchDevice);
|
||||
};
|
||||
|
Reference in New Issue
Block a user