Skip to content

Commit e47ad94

Browse files
committed
feat: concat usage code
1 parent 4333eb9 commit e47ad94

File tree

30 files changed

+600
-251
lines changed

30 files changed

+600
-251
lines changed

document/content/docs/toc.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ description: FastGPT 文档目录
103103
- [/docs/upgrading/4-12/4122](/docs/upgrading/4-12/4122)
104104
- [/docs/upgrading/4-12/4123](/docs/upgrading/4-12/4123)
105105
- [/docs/upgrading/4-12/4124](/docs/upgrading/4-12/4124)
106+
- [/docs/upgrading/4-12/4125](/docs/upgrading/4-12/4125)
106107
- [/docs/upgrading/4-8/40](/docs/upgrading/4-8/40)
107108
- [/docs/upgrading/4-8/41](/docs/upgrading/4-8/41)
108109
- [/docs/upgrading/4-8/42](/docs/upgrading/4-8/42)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 'V4.12.5(进行)'
3+
description: 'FastGPT V4.12.5 更新说明'
4+
---
5+
6+
7+
## 🚀 新增内容
8+
9+
10+
## ⚙️ 优化
11+
12+
1. 计量计费账单推送和合并逻辑。
13+
14+
## 🐛 修复
15+
16+
17+
## 🔨 插件更新
18+

document/data/doc-last-modified.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"document/content/docs/upgrading/4-12/4121.mdx": "2025-09-07T14:41:48+08:00",
107107
"document/content/docs/upgrading/4-12/4122.mdx": "2025-09-07T14:41:48+08:00",
108108
"document/content/docs/upgrading/4-12/4123.mdx": "2025-09-07T20:55:14+08:00",
109-
"document/content/docs/upgrading/4-12/4124.mdx": "2025-09-15T20:39:54+08:00",
109+
"document/content/docs/upgrading/4-12/4124.mdx": "2025-09-15T22:21:24+08:00",
110110
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
111111
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
112112
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",
@@ -188,4 +188,4 @@
188188
"document/content/docs/use-cases/external-integration/openapi.mdx": "2025-08-14T18:54:47+08:00",
189189
"document/content/docs/use-cases/external-integration/wecom.mdx": "2025-09-15T20:02:54+08:00",
190190
"document/content/docs/use-cases/index.mdx": "2025-07-24T14:23:04+08:00"
191-
}
191+
}
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { UsageSourceEnum } from './constants';
2-
import type { UsageListItemCountType, UsageListItemType } from './type';
1+
import type { UsageItemTypeEnum, UsageSourceEnum } from './constants';
2+
import type { UsageItemCountType, UsageItemType, UsageListItemType, UsageSchemaType } from './type';
33

44
export type CreateTrainingUsageProps = {
55
name: string;
@@ -22,21 +22,15 @@ export type GetUsageDashboardResponseItem = {
2222
totalPoints: number;
2323
};
2424

25-
export type ConcatUsageProps = UsageListItemCountType & {
25+
export type CreateUsageProps = Omit<UsageSchemaType, '_id' | 'time'>;
26+
export type ConcatUsageProps = {
2627
teamId: string;
27-
tmbId: string;
28-
billId?: string;
28+
usageId: string;
2929
totalPoints: number;
30-
listIndex?: number;
31-
};
32-
33-
export type CreateUsageProps = {
30+
itemType: UsageItemTypeEnum;
31+
} & UsageItemCountType;
32+
export type PushUsageItemsProps = {
3433
teamId: string;
35-
tmbId: string;
36-
appName: string;
37-
appId?: string;
38-
pluginId?: string;
39-
totalPoints: number;
40-
source: `${UsageSourceEnum}`;
41-
list: UsageListItemType[];
34+
usageId: string;
35+
list: UsageItemType[];
4236
};

packages/global/support/wallet/usage/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ export const UsageSourceMap = {
6161
label: i18nT('common:support.wallet.usage.Optimize Prompt')
6262
}
6363
};
64+
65+
export enum UsageItemTypeEnum {
66+
training_vector = 1,
67+
training_qa = 2,
68+
training_autoIndex = 3,
69+
training_imageIndex = 4,
70+
training_paragraph = 5,
71+
training_imageParse = 6,
72+
73+
evaluation_generateAnswer = 7,
74+
evaluation_answerAccuracy = 8
75+
}
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
import type { SourceMemberType } from '../../../support/user/type';
2-
import type { CreateUsageProps } from './api';
3-
import { UsageSourceEnum } from './constants';
2+
import type { UsageItemTypeEnum, UsageSourceEnum } from './constants';
43

5-
export type UsageListItemCountType = {
4+
export type UsageSchemaType = {
5+
_id: string;
6+
time: Date;
7+
8+
teamId: string;
9+
tmbId: string;
10+
appName: string;
11+
appId?: string;
12+
pluginId?: string;
13+
totalPoints: number;
14+
source: `${UsageSourceEnum}`;
15+
16+
// @deprecated
17+
list?: UsageItemType[];
18+
};
19+
export type UsageItemSchemaType = {
20+
_id: string;
21+
teamId: string;
22+
usageId: string;
23+
name: string;
24+
amount: number;
25+
time: Date;
26+
itemType?: UsageItemTypeEnum; // Use in usage concat
27+
} & UsageItemCountType;
28+
29+
export type UsageItemCountType = {
30+
model?: string;
631
inputTokens?: number;
732
outputTokens?: number;
833
charsLength?: number;
@@ -14,24 +39,18 @@ export type UsageListItemCountType = {
1439
tokens?: number;
1540
};
1641

17-
export type UsageListItemType = UsageListItemCountType & {
42+
export type UsageItemType = UsageItemCountType & {
1843
moduleName: string;
1944
amount: number;
20-
model?: string;
21-
count?: number;
22-
};
23-
24-
export type UsageSchemaType = CreateUsageProps & {
25-
_id: string;
26-
time: Date;
45+
itemType?: UsageItemTypeEnum;
2746
};
2847

29-
export type UsageItemType = {
48+
export type UsageListItemType = {
3049
id: string;
3150
time: Date;
3251
appName: string;
3352
source: UsageSchemaType['source'];
3453
totalPoints: number;
35-
list: UsageSchemaType['list'];
54+
list: Omit<UsageItemType, 'itemType'>[];
3655
sourceMember: SourceMemberType;
3756
};

packages/service/common/api/type.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ import type {
88
SearchDatasetDataResponse
99
} from '../../core/dataset/search/controller';
1010
import type { AuthOpenApiLimitProps } from '../../support/openapi/auth';
11-
import type { CreateUsageProps, ConcatUsageProps } from '@fastgpt/global/support/wallet/usage/api';
11+
import type {
12+
CreateUsageProps,
13+
ConcatUsageProps,
14+
PushUsageItemsProps
15+
} from '@fastgpt/global/support/wallet/usage/api';
1216

1317
declare global {
1418
var textCensorHandler: (params: { text: string }) => Promise<{ code: number; message?: string }>;
1519
var deepRagHandler: (data: DeepRagSearchProps) => Promise<SearchDatasetDataResponse>;
1620
var authOpenApiHandler: (data: AuthOpenApiLimitProps) => Promise<any>;
1721
var createUsageHandler: (data: CreateUsageProps) => any;
1822
var concatUsageHandler: (data: ConcatUsageProps) => any;
23+
var pushUsageItemsHandler: (data: PushUsageItemsProps) => any;
1924
}

packages/service/common/file/gridfs/controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,16 @@ export const readFileContentFromMongo = async ({
196196
bucketName,
197197
fileId,
198198
customPdfParse = false,
199-
getFormatText
199+
getFormatText,
200+
usageId
200201
}: {
201202
teamId: string;
202203
tmbId: string;
203204
bucketName: `${BucketNameEnum}`;
204205
fileId: string;
205206
customPdfParse?: boolean;
206207
getFormatText?: boolean; // 数据类型都尽可能转化成 markdown 格式
208+
usageId?: string;
207209
}): Promise<{
208210
rawText: string;
209211
filename: string;
@@ -237,6 +239,7 @@ export const readFileContentFromMongo = async ({
237239
// Get raw text
238240
const { rawText } = await readRawContentByFileBuffer({
239241
customPdfParse,
242+
usageId,
240243
getFormatText,
241244
extension,
242245
teamId,

packages/service/common/file/read/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const readRawContentByFileBuffer = async ({
4747
encoding,
4848
metadata,
4949
customPdfParse = false,
50+
usageId,
5051
getFormatText = true
5152
}: {
5253
teamId: string;
@@ -58,6 +59,7 @@ export const readRawContentByFileBuffer = async ({
5859
metadata?: Record<string, any>;
5960

6061
customPdfParse?: boolean;
62+
usageId?: string;
6163
getFormatText?: boolean;
6264
}): Promise<{
6365
rawText: string;
@@ -104,7 +106,8 @@ export const readRawContentByFileBuffer = async ({
104106
createPdfParseUsage({
105107
teamId,
106108
tmbId,
107-
pages: response.pages
109+
pages: response.pages,
110+
usageId
108111
});
109112

110113
return {
@@ -123,7 +126,8 @@ export const readRawContentByFileBuffer = async ({
123126
createPdfParseUsage({
124127
teamId,
125128
tmbId,
126-
pages
129+
pages,
130+
usageId
127131
});
128132

129133
return {

packages/service/core/app/evaluation/evalSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import { connectionMongo, getMongoModel } from '../../../common/mongo';
66
import { AppCollectionName } from '../schema';
77
import type { EvaluationSchemaType } from '@fastgpt/global/core/app/evaluation/type';
8-
import { UsageCollectionName } from '../../../support/wallet/usage/schema';
8+
import { UsageCollectionName } from '../../../support/wallet/usage/constants';
99
const { Schema } = connectionMongo;
1010

1111
export const EvaluationCollectionName = 'eval';

0 commit comments

Comments
 (0)