Skip to content

Commit 76dc23c

Browse files
authored
perF: getInitData api cache;perf: tool description field;signoz store level (#5465)
* perf: auto focus * perF: getInitData api cache * perf: tool description field * signoz store level * perF: chat logs index
1 parent d78a0e9 commit 76dc23c

File tree

20 files changed

+91
-71
lines changed

20 files changed

+91
-71
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 服务端资源版本 ID 缓存方案
2+
3+
## 背景
4+
5+
FastGPT 会采用多节点部署方式,有部分数据缓存会存储在内存里。当需要使用这部分数据时(不管是通过 API 获取,还是后端服务自己获取),都是直接拉取内存数据,这可能会导致数据不一致问题,尤其是用户通过 API 更新数据后再获取,就容易获取未修改数据的节点。
6+
7+
## 解决方案
8+
9+
1. 给每一个缓存数据加上一个版本 ID。
10+
2. 获取该数据时候,不直接引用该数据,而是通过一个 function 获取,该 function 可选的传入一个 versionId。
11+
3. 获取数据时,先检查该 versionId 与 redis 中,资源版本id 与传入的 versionId 是否一致。
12+
4. 如果数据一致,则直接返回数据。
13+
5. 如果数据不一致,则重新获取数据,并返回最新的 versionId。调用方则需要更新其缓存的 versionId。
14+
15+
## 代码方案
16+
17+
* 获取和更新缓存的代码,直接复用 FastGPT/packages/service/common/redis/cache.ts
18+
* 每个资源,自己维护一个 cacheKey
19+
* 每次更新资源/触发拉取最新资源时,都需要更新 cacheKey 的值。
20+
21+
## 涉及的业务
22+
23+
* [ ] FastGPT/projects/app/src/pages/api/common/system/getInitData.ts,获取初始数据

document/components/docs/not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const exactMap: Record<string, string> = {
1010
'/docs/guide/admin/sso_dingtalk':
1111
'/docs/introduction/guide/admin/sso#/docs/introduction/guide/admin/sso#钉钉',
1212
'/docs/guide/knowledge_base/rag': '/docs/introduction/guide/knowledge_base/RAG',
13-
'/docs/commercial/intro/': '/docs/introduction',
13+
'/docs/commercial/intro/': '/docs/introduction/commercial',
1414
'/docs/upgrading/intro/': '/docs/upgrading',
1515
'/docs/introduction/shopping_cart/intro/': '/docs/introduction/commercial'
1616
};

document/content/docs/upgrading/4-12/4121.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description: 'FastGPT V4.12.1 更新说明'
77
## 🚀 新增内容
88

99
1. Prompt 自动生成和优化。
10+
2. 增加`SIGNOZ_STORE_LEVEL`参数,可以控制 Signoz 日志存储级别。
1011

1112
## ⚙️ 优化
1213

@@ -21,3 +22,5 @@ description: 'FastGPT V4.12.1 更新说明'
2122
3. 对话日志看板数据表索引不正确。
2223

2324
## 🔨 工具更新
25+
26+
1. 支持对系统工具单独配置 Tool description,更利于模型理解。

document/data/doc-last-modified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"document/content/docs/upgrading/4-11/4110.mdx": "2025-08-05T23:20:39+08:00",
104104
"document/content/docs/upgrading/4-11/4111.mdx": "2025-08-07T22:49:09+08:00",
105105
"document/content/docs/upgrading/4-12/4120.mdx": "2025-08-12T22:45:19+08:00",
106-
"document/content/docs/upgrading/4-12/4121.mdx": "2025-08-14T22:01:36+08:00",
106+
"document/content/docs/upgrading/4-12/4121.mdx": "2025-08-15T14:27:32+08:00",
107107
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
108108
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
109109
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",

packages/service/common/system/log.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ const envLogLevelMap: Record<string, number> = {
3434
error: LogLevelEnum.error
3535
};
3636

37-
const { LOG_LEVEL, STORE_LOG_LEVEL } = (() => {
37+
const { LOG_LEVEL, STORE_LOG_LEVEL, SIGNOZ_STORE_LEVEL } = (() => {
3838
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info').toLocaleLowerCase();
3939
const STORE_LOG_LEVEL = (process.env.STORE_LOG_LEVEL || '').toLocaleLowerCase();
40+
const SIGNOZ_STORE_LEVEL = (process.env.SIGNOZ_STORE_LEVEL || 'warn').toLocaleLowerCase();
4041

4142
return {
4243
LOG_LEVEL: envLogLevelMap[LOG_LEVEL] ?? LogLevelEnum.info,
43-
STORE_LOG_LEVEL: envLogLevelMap[STORE_LOG_LEVEL] ?? 99
44+
STORE_LOG_LEVEL: envLogLevelMap[STORE_LOG_LEVEL] ?? 99,
45+
SIGNOZ_STORE_LEVEL: envLogLevelMap[SIGNOZ_STORE_LEVEL] ?? LogLevelEnum.warn
4446
};
4547
})();
4648

@@ -60,7 +62,7 @@ export const addLog = {
6062

6163
level === LogLevelEnum.error && console.error(obj);
6264

63-
if (logger) {
65+
if (logger && level >= SIGNOZ_STORE_LEVEL) {
6466
logger.emit({
6567
severityNumber: level.valueOf(),
6668
severityText: ['debug', 'info', 'warn', 'error'][level],

packages/service/core/ai/config/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ export const loadSystemModels = async (init = false) => {
173173
const providerB = getModelProvider(b.provider);
174174
return providerA.order - providerB.order;
175175
});
176+
global.systemActiveDesensitizedModels = global.systemActiveModelList.map((model) => ({
177+
...model,
178+
defaultSystemChatPrompt: undefined,
179+
fieldMap: undefined,
180+
defaultConfig: undefined,
181+
weight: undefined,
182+
dbConfig: undefined,
183+
queryConfig: undefined,
184+
requestUrl: undefined,
185+
requestAuth: undefined
186+
})) as SystemModelItemType[];
176187

177188
console.log(
178189
`Load models success, total: ${global.systemModelList.length}, active: ${global.systemActiveModelList.length}`,

packages/service/core/ai/type.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ declare global {
4141
var reRankModelMap: Map<string, RerankModelItemType>;
4242

4343
var systemActiveModelList: SystemModelItemType[];
44+
var systemActiveDesensitizedModels: SystemModelItemType[];
4445
var systemDefaultModel: SystemDefaultModelType;
4546
}

packages/service/core/app/plugin/controller.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,7 @@ export async function getChildAppPreviewNode({
314314
}))
315315
}
316316
}
317-
: {
318-
systemTool: {
319-
toolId: app.id
320-
}
321-
})
317+
: { systemTool: { toolId: app.id } })
322318
},
323319
showSourceHandle: app.isFolder ? false : true,
324320
showTargetHandle: app.isFolder ? false : true
@@ -541,23 +537,6 @@ export const getSystemTools = async (): Promise<SystemPluginTemplateItemType[]>
541537
const systemToolsArray = await MongoSystemPlugin.find({}).lean();
542538
const systemTools = new Map(systemToolsArray.map((plugin) => [plugin.pluginId, plugin]));
543539

544-
// tools.forEach((tool) => {
545-
// // 如果有插件的配置信息,则需要进行替换
546-
// const dbPluginConfig = systemTools.get(tool.id);
547-
548-
// if (dbPluginConfig) {
549-
// const children = tools.filter((item) => item.parentId === tool.id);
550-
// const list = [tool, ...children];
551-
// list.forEach((item) => {
552-
// item.isActive = dbPluginConfig.isActive ?? item.isActive ?? true;
553-
// item.originCost = dbPluginConfig.originCost ?? 0;
554-
// item.currentCost = dbPluginConfig.currentCost ?? 0;
555-
// item.hasTokenFee = dbPluginConfig.hasTokenFee ?? false;
556-
// item.pluginOrder = dbPluginConfig.pluginOrder ?? 0;
557-
// });
558-
// }
559-
// });
560-
561540
const formatTools = tools.map<SystemPluginTemplateItemType>((item) => {
562541
const dbPluginConfig = systemTools.get(item.id);
563542
const isFolder = tools.some((tool) => tool.parentId === item.id);

packages/service/core/app/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export async function rewriteAppWorkflowToDetail({
8888
node.isFolder = preview.isFolder;
8989

9090
node.toolConfig = preview.toolConfig;
91+
node.toolDescription = preview.toolDescription;
9192

9293
// Latest version
9394
if (!node.version) {

packages/web/i18n/en/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"Optimizer_Placeholder_loading": "Generating...please wait",
2222
"Optimizer_Reoptimize": "Re-optimize",
2323
"Optimizer_Replace": "replace",
24-
"Optimizer_Tooltip": "AI Optimization",
24+
"Optimizer_Tooltip": "AI optimization prompt words",
2525
"Role_setting": "Permission",
2626
"Run": "Execute",
2727
"Search_dataset": "Search dataset",

0 commit comments

Comments
 (0)