mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: package plus request (#4492)
* fix plus request (#4476) * perf: package plus request * perf: plus request fix * fix: doc --------- Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
|
||||
import { updateApiKeyUsedTime } from './tools';
|
||||
import { MongoOpenApi } from './schema';
|
||||
import { POST } from '../../common/api/plusRequest';
|
||||
import type { OpenApiSchema } from '@fastgpt/global/support/openapi/type';
|
||||
|
||||
export type AuthOpenApiLimitProps = { openApi: OpenApiSchema };
|
||||
@@ -17,11 +16,10 @@ export async function authOpenApiKey({ apikey }: { apikey: string }) {
|
||||
}
|
||||
|
||||
// auth limit
|
||||
// @ts-ignore
|
||||
if (global.feConfigs?.isPlus) {
|
||||
await POST('/support/openapi/authLimit', {
|
||||
await global.authOpenApiHandler({
|
||||
openApi
|
||||
} as AuthOpenApiLimitProps);
|
||||
});
|
||||
}
|
||||
|
||||
updateApiKeyUsedTime(openApi._id);
|
||||
|
@@ -1,67 +1,21 @@
|
||||
import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants';
|
||||
import { MongoUsage } from './schema';
|
||||
import { ClientSession, Types } from '../../../common/mongo';
|
||||
import { ClientSession } from '../../../common/mongo';
|
||||
import { addLog } from '../../../common/system/log';
|
||||
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
|
||||
import { ConcatUsageProps, CreateUsageProps } from '@fastgpt/global/support/wallet/usage/api';
|
||||
import { i18nT } from '../../../../web/i18n/utils';
|
||||
import { pushConcatBillTask, pushReduceTeamAiPointsTask } from './utils';
|
||||
|
||||
import { POST } from '../../../common/api/plusRequest';
|
||||
import { isFastGPTMainService } from '../../../common/system/constants';
|
||||
|
||||
export async function createUsage(data: CreateUsageProps) {
|
||||
try {
|
||||
// In FastGPT server
|
||||
if (isFastGPTMainService) {
|
||||
await POST('/support/wallet/usage/createUsage', data);
|
||||
} else if (global.reduceAiPointsQueue) {
|
||||
// In FastGPT pro server
|
||||
await MongoUsage.create(data);
|
||||
pushReduceTeamAiPointsTask({ teamId: data.teamId, totalPoints: data.totalPoints });
|
||||
|
||||
if (data.totalPoints === 0) {
|
||||
addLog.info('0 totalPoints', data);
|
||||
}
|
||||
}
|
||||
await global.createUsageHandler(data);
|
||||
} catch (error) {
|
||||
addLog.error('createUsage error', error);
|
||||
}
|
||||
}
|
||||
export async function concatUsage(data: ConcatUsageProps) {
|
||||
try {
|
||||
// In FastGPT server
|
||||
if (isFastGPTMainService) {
|
||||
await POST('/support/wallet/usage/concatUsage', data);
|
||||
} else if (global.reduceAiPointsQueue) {
|
||||
const {
|
||||
teamId,
|
||||
billId,
|
||||
totalPoints = 0,
|
||||
listIndex,
|
||||
inputTokens = 0,
|
||||
outputTokens = 0
|
||||
} = data;
|
||||
|
||||
// billId is required and valid
|
||||
if (!billId || !Types.ObjectId.isValid(billId)) return;
|
||||
|
||||
// In FastGPT pro server
|
||||
pushConcatBillTask([
|
||||
{
|
||||
billId,
|
||||
listIndex,
|
||||
inputTokens,
|
||||
outputTokens,
|
||||
totalPoints
|
||||
}
|
||||
]);
|
||||
pushReduceTeamAiPointsTask({ teamId, totalPoints });
|
||||
|
||||
if (data.totalPoints === 0) {
|
||||
addLog.info('0 totalPoints', data);
|
||||
}
|
||||
}
|
||||
await global.concatUsageHandler(data);
|
||||
} catch (error) {
|
||||
addLog.error('concatUsage error', error);
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { findAIModel } from '../../../core/ai/model';
|
||||
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
|
||||
import { ConcatBillQueueItemType } from './type';
|
||||
|
||||
export const formatModelChars2Points = ({
|
||||
model,
|
||||
@@ -35,20 +34,3 @@ export const formatModelChars2Points = ({
|
||||
totalPoints
|
||||
};
|
||||
};
|
||||
|
||||
export const pushReduceTeamAiPointsTask = ({
|
||||
teamId,
|
||||
totalPoints
|
||||
}: {
|
||||
teamId: string;
|
||||
totalPoints: number;
|
||||
}) => {
|
||||
global.reduceAiPointsQueue.push({
|
||||
teamId: String(teamId),
|
||||
totalPoints
|
||||
});
|
||||
};
|
||||
|
||||
export const pushConcatBillTask = (data: ConcatBillQueueItemType[]) => {
|
||||
global.concatBillQueue.push(...data);
|
||||
};
|
||||
|
Reference in New Issue
Block a user