mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-13 04:03:45 +08:00
v 2.4.5
This commit is contained in:
16
dist/modules/chatgpt/chatgpt.service.js
vendored
16
dist/modules/chatgpt/chatgpt.service.js
vendored
@@ -72,7 +72,7 @@ let ChatgptService = class ChatgptService {
|
||||
};
|
||||
}
|
||||
async onModuleInit() {
|
||||
let chatgpt = await (0, utils_1.importDynamic)('chatgpt-nine-ai');
|
||||
let chatgpt = await (0, utils_1.importDynamic)('chatgpt-ai-web');
|
||||
let KeyvRedis = await (0, utils_1.importDynamic)('@keyv/redis');
|
||||
let Keyv = await (0, utils_1.importDynamic)('keyv');
|
||||
chatgpt = (chatgpt === null || chatgpt === void 0 ? void 0 : chatgpt.default) ? chatgpt.default : chatgpt;
|
||||
@@ -149,7 +149,7 @@ let ChatgptService = class ChatgptService {
|
||||
if (!currentRequestModelKey) {
|
||||
throw new common_1.HttpException('当前流程所需要的模型已被管理员下架、请联系管理员上架专属模型!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { deduct, deductType, key: modelKey, secret, modelName, id: keyId, accessToken } = currentRequestModelKey;
|
||||
const { deduct, isTokenBased, deductType, key: modelKey, secret, modelName, id: keyId, accessToken } = currentRequestModelKey;
|
||||
await this.userService.checkUserStatus(req.user);
|
||||
await this.userBalanceService.validateBalance(req, deductType === 1 ? 'model3' : 'model4', deduct);
|
||||
res && res.setHeader('Content-type', 'application/octet-stream; charset=utf-8');
|
||||
@@ -247,7 +247,11 @@ let ChatgptService = class ChatgptService {
|
||||
temperature,
|
||||
}),
|
||||
});
|
||||
await this.userBalanceService.deductFromBalance(req.user.id, `model${deductType === 1 ? 3 : 4}`, deduct, total_tokens);
|
||||
let charge = deduct;
|
||||
if (isTokenBased === true) {
|
||||
charge = deduct * total_tokens;
|
||||
}
|
||||
await this.userBalanceService.deductFromBalance(req.user.id, `model${deductType === 1 ? 3 : 4}`, charge, total_tokens);
|
||||
});
|
||||
if (Number(keyType) === 1) {
|
||||
const { key, maxToken, maxTokenRes, proxyResUrl } = await this.formatModelToken(currentRequestModelKey);
|
||||
@@ -354,7 +358,11 @@ let ChatgptService = class ChatgptService {
|
||||
}
|
||||
const formatResponse = await (0, helper_1.unifiedFormattingResponse)(keyType, response, othersInfo);
|
||||
const { prompt_tokens = 0, completion_tokens = 0, total_tokens = 0 } = formatResponse.usage;
|
||||
await this.userBalanceService.deductFromBalance(req.user.id, `model${deductType === 1 ? 3 : 4}`, deduct, total_tokens);
|
||||
let charge = deduct;
|
||||
if (isTokenBased === true) {
|
||||
charge = deduct * total_tokens;
|
||||
}
|
||||
await this.userBalanceService.deductFromBalance(req.user.id, `model${deductType === 1 ? 3 : 4}`, charge, total_tokens);
|
||||
await this.modelsService.saveUseLog(keyId, total_tokens);
|
||||
const curIp = (0, utils_1.getClientIp)(req);
|
||||
await this.chatLogService.saveChatLog({
|
||||
|
||||
2
dist/modules/database/database.service.js
vendored
2
dist/modules/database/database.service.js
vendored
@@ -24,7 +24,7 @@ let DatabaseService = class DatabaseService {
|
||||
async checkSuperAdmin() {
|
||||
const user = await this.connection.query(`SELECT * FROM users WHERE role = 'super'`);
|
||||
if (!user || user.length === 0) {
|
||||
const superPassword = bcrypt.hashSync('nine-super', 10);
|
||||
const superPassword = bcrypt.hashSync('123456', 10);
|
||||
const adminPassword = bcrypt.hashSync('123456', 10);
|
||||
const superEmail = 'default@cooper.com';
|
||||
const adminEmail = 'defaultAdmin@cooper.com';
|
||||
|
||||
4
dist/modules/models/dto/setModel.dto.js
vendored
4
dist/modules/models/dto/setModel.dto.js
vendored
@@ -81,4 +81,8 @@ __decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: true, description: '是否设置为绘画Key', required: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], SetModelDto.prototype, "isDraw", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: true, description: '是否使用token计费', required: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], SetModelDto.prototype, "isTokenBased", void 0);
|
||||
exports.SetModelDto = SetModelDto;
|
||||
|
||||
6
dist/modules/models/models.entity.js
vendored
6
dist/modules/models/models.entity.js
vendored
@@ -75,7 +75,7 @@ __decorate([
|
||||
__metadata("design:type", Number)
|
||||
], ModelsEntity.prototype, "timeout", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '单词调用扣除的次数', default: 1 }),
|
||||
(0, typeorm_1.Column)({ comment: '单次调用扣除的次数', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], ModelsEntity.prototype, "deduct", void 0);
|
||||
__decorate([
|
||||
@@ -94,6 +94,10 @@ __decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否是绘画key: 0:不是 1:是', default: 0 }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ModelsEntity.prototype, "isDraw", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否使用token计费: 0:不是 1:是', default: 0 }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ModelsEntity.prototype, "isTokenBased", void 0);
|
||||
ModelsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'models' })
|
||||
], ModelsEntity);
|
||||
|
||||
Reference in New Issue
Block a user