V4.8.17 feature (#3493)

* split tokens into input and output (#3477)

* split tokens into input and output

* query extension & tool call & question guide

* fix

* perf: input and output tokens

* perf: tool call if else

* perf: remove code

* fix: extract usage count

* fix: qa usage count

---------

Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
Archer
2024-12-30 10:13:25 +08:00
committed by GitHub
parent da2831b948
commit 50bf7f9a3b
46 changed files with 467 additions and 230 deletions

View File

@@ -31,20 +31,23 @@ export const createTrainingUsage = async ({
{
moduleName: 'support.wallet.moduleName.index',
model: vectorModel,
tokens: 0,
amount: 0
amount: 0,
inputTokens: 0,
outputTokens: 0
},
{
moduleName: 'support.wallet.moduleName.qa',
model: agentModel,
tokens: 0,
amount: 0
amount: 0,
inputTokens: 0,
outputTokens: 0
},
{
moduleName: 'core.dataset.training.Auto mode',
model: agentModel,
tokens: 0,
amount: 0
amount: 0,
inputTokens: 0,
outputTokens: 0
}
]
}

View File

@@ -1,7 +1,7 @@
import { connectionMongo, getMongoModel, type Model } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
const { Schema } = connectionMongo;
import { UsageSchemaType } from '@fastgpt/global/support/wallet/usage/type';
import { UsageSourceMap } from '@fastgpt/global/support/wallet/usage/constants';
import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants';
import {
TeamCollectionName,
TeamMemberCollectionName
@@ -22,7 +22,7 @@ const UsageSchema = new Schema({
},
source: {
type: String,
enum: Object.keys(UsageSourceMap),
enum: Object.values(UsageSourceEnum),
required: true
},
appName: {
@@ -65,7 +65,7 @@ try {
// timer task. clear dead team
// UsageSchema.index({ teamId: 1, time: -1 }, { background: true });
UsageSchema.index({ time: 1 }, { background: true, expireAfterSeconds: 720 * 24 * 60 * 60 });
UsageSchema.index({ time: 1 }, { background: true, expireAfterSeconds: 360 * 24 * 60 * 60 });
} catch (error) {
console.log(error);
}

View File

@@ -1,17 +1,20 @@
import { LLMModelItemType } from '@fastgpt/global/core/ai/model.d';
import { ModelTypeEnum, getModelMap } from '../../../core/ai/model';
export const formatModelChars2Points = ({
model,
tokens = 0,
inputTokens = 0,
outputTokens = 0,
modelType,
multiple = 1000
}: {
model: string;
tokens: number;
inputTokens?: number;
outputTokens?: number;
modelType: `${ModelTypeEnum}`;
multiple?: number;
}) => {
const modelData = getModelMap?.[modelType]?.(model);
const modelData = getModelMap?.[modelType]?.(model) as LLMModelItemType;
if (!modelData) {
return {
totalPoints: 0,
@@ -19,7 +22,12 @@ export const formatModelChars2Points = ({
};
}
const totalPoints = (modelData.charsPointsPrice || 0) * (tokens / multiple);
const isIOPriceType = typeof modelData.inputPrice === 'number';
const totalPoints = isIOPriceType
? (modelData.inputPrice || 0) * (inputTokens / multiple) +
(modelData.outputPrice || 0) * (outputTokens / multiple)
: (modelData.charsPointsPrice || 0) * ((inputTokens + outputTokens) / multiple);
return {
modelName: modelData.name,