mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
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:
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user