mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-14 20:53:42 +08:00
v-3.0.0
This commit is contained in:
309
dist/modules/chat/chat.controller.js
vendored
Normal file
309
dist/modules/chat/chat.controller.js
vendored
Normal file
@@ -0,0 +1,309 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatController = void 0;
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const chat_service_1 = require("./chat.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chatProcess_dto_1 = require("./dto/chatProcess.dto");
|
||||
const chatDraw_dto_1 = require("./dto/chatDraw.dto");
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let ChatController = class ChatController {
|
||||
constructor(chatService, globalConfigService) {
|
||||
this.chatService = chatService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
chatProcess(body, req, res) {
|
||||
return this.chatService.chatProcess(body, req, res);
|
||||
}
|
||||
chatProcessSync(body, req) {
|
||||
return this.chatService.chatProcess(Object.assign({}, body), req);
|
||||
}
|
||||
ttsProcess(body, req, res) {
|
||||
return this.chatService.ttsProcess(body, req, res);
|
||||
}
|
||||
async mjFanyi(body, req) {
|
||||
const mjTranslatePrompt = await this.globalConfigService.getConfigs(['mjTranslatePrompt']);
|
||||
body.model = 'translation-';
|
||||
body.systemMessage =
|
||||
mjTranslatePrompt ||
|
||||
`接下来我会给你一些内容、我希望你帮我翻译成英文、不管我给你任何语言、你都回复我英文、如果给你了英文、依然回复我更加优化的英文、并且期望你不需要做任何多余的解释、给我英文即可、不要加任何东西、我只需要英文!`;
|
||||
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: true }), req);
|
||||
}
|
||||
async chatmind(body, req, res) {
|
||||
const mindCustomPrompt = await this.globalConfigService.getConfigs(['mindCustomPrompt']);
|
||||
body.model = 'mindmap-';
|
||||
body.systemMessage =
|
||||
mindCustomPrompt ||
|
||||
`我希望你使用markdown格式回答我得问题、我的需求是得到一份markdown格式的大纲、尽量做的精细、层级多一点、不管我问你什么、都需要您回复我一个大纲出来、我想使用大纲做思维导图、除了大纲之外、不要无关内容和总结。`;
|
||||
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: true }), req, res);
|
||||
}
|
||||
async draw(body, req) {
|
||||
return await this.chatService.draw(body, req);
|
||||
}
|
||||
async setChatBoxType(req, body) {
|
||||
return await this.chatService.setChatBoxType(req, body);
|
||||
}
|
||||
async delChatBoxType(req, body) {
|
||||
return await this.chatService.delChatBoxType(req, body);
|
||||
}
|
||||
async queryChatBoxType() {
|
||||
return await this.chatService.queryChatBoxType();
|
||||
}
|
||||
async setChatBox(req, body) {
|
||||
return await this.chatService.setChatBox(req, body);
|
||||
}
|
||||
async delChatBox(req, body) {
|
||||
return await this.chatService.delChatBox(req, body);
|
||||
}
|
||||
async queryChatBox() {
|
||||
return await this.chatService.queryChatBox();
|
||||
}
|
||||
async queryChatBoxFrontend() {
|
||||
return await this.chatService.queryChatBoxFrontend();
|
||||
}
|
||||
async setChatPreType(req, body) {
|
||||
return await this.chatService.setChatPreType(req, body);
|
||||
}
|
||||
async delChatPreType(req, body) {
|
||||
return await this.chatService.delChatPreType(req, body);
|
||||
}
|
||||
async queryChatPreType() {
|
||||
return await this.chatService.queryChatPreType();
|
||||
}
|
||||
async setChatPre(req, body) {
|
||||
return await this.chatService.setChatPre(req, body);
|
||||
}
|
||||
async delChatPre(req, body) {
|
||||
return await this.chatService.delChatPre(req, body);
|
||||
}
|
||||
async queryChatPre() {
|
||||
return await this.chatService.queryChatPre();
|
||||
}
|
||||
async queryChatPreList() {
|
||||
return await this.chatService.queryChatPreList();
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-process'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt聊天对话' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "chatProcess", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-sync'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt聊天对话' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "chatProcessSync", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('tts-process'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'tts语音播报' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], ChatController.prototype, "ttsProcess", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('mj-fy'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt描述词绘画翻译' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "mjFanyi", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-mind'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'mind思维导图提示' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatProcess_dto_1.ChatProcessDto, Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "chatmind", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('chat-draw'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'gpt绘画' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [chatDraw_dto_1.ChatDrawDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "draw", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('setChatBoxType'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改分类类型' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "setChatBoxType", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delChatBoxType'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatBoxType' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "delChatBoxType", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatBoxTypes'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatBoxType' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatBoxType", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('setChatBox'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatBox' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "setChatBox", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delChatBox'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatBox提示词' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "delChatBox", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatBoxs'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatBox列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatBox", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatBoxFrontend'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatBox分类加详细' }),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatBoxFrontend", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('setChatPreType'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改预设分类类型' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "setChatPreType", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delChatPretype'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatPretype' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "delChatPreType", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatPretypes'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatPretype' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatPreType", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('setChatPre'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatPre' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "setChatPre", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delChatPre'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加修改ChatPre提示词' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "delChatPre", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatPres'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatPre列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatPre", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryChatPreList'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询ChatPre列表' }),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ChatController.prototype, "queryChatPreList", null);
|
||||
ChatController = __decorate([
|
||||
(0, swagger_1.ApiTags)('chatgpt'),
|
||||
(0, common_1.Controller)('chatgpt'),
|
||||
__metadata("design:paramtypes", [chat_service_1.ChatService, globalConfig_service_1.GlobalConfigService])
|
||||
], ChatController);
|
||||
exports.ChatController = ChatController;
|
||||
70
dist/modules/chat/chat.module.js
vendored
Normal file
70
dist/modules/chat/chat.module.js
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chat_controller_1 = require("./chat.controller");
|
||||
const chat_service_1 = require("./chat.service");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const user_service_1 = require("../user/user.service");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const verification_service_1 = require("../verification/verification.service");
|
||||
const verifycation_entity_1 = require("../verification/verifycation.entity");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const whiteList_entity_1 = require("./whiteList.entity");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const app_entity_1 = require("../app/app.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const salesUsers_entity_1 = require("../sales/salesUsers.entity");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const midjourney_entity_1 = require("../midjourney/midjourney.entity");
|
||||
const chatBoxType_entity_1 = require("./chatBoxType.entity");
|
||||
const chatBox_entity_1 = require("./chatBox.entity");
|
||||
const chatPreType_entity_1 = require("./chatPreType.entity");
|
||||
const chatPre_entity_1 = require("./chatPre.entity");
|
||||
let ChatModule = class ChatModule {
|
||||
};
|
||||
ChatModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
balance_entity_1.BalanceEntity,
|
||||
user_entity_1.UserEntity,
|
||||
verifycation_entity_1.VerifycationEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
whiteList_entity_1.WhiteListEntity,
|
||||
user_entity_1.UserEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
app_entity_1.AppEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
salesUsers_entity_1.SalesUsersEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
midjourney_entity_1.MidjourneyEntity,
|
||||
chatBoxType_entity_1.ChatBoxTypeEntity,
|
||||
chatBox_entity_1.ChatBoxEntity,
|
||||
chatPreType_entity_1.ChatPreTypeEntity,
|
||||
chatPre_entity_1.ChatPreEntity
|
||||
]),
|
||||
],
|
||||
controllers: [chat_controller_1.ChatController],
|
||||
providers: [chat_service_1.ChatService, userBalance_service_1.UserBalanceService, user_service_1.UserService, verification_service_1.VerificationService, chatLog_service_1.ChatLogService, redisCache_service_1.RedisCacheService],
|
||||
exports: [chat_service_1.ChatService]
|
||||
})
|
||||
], ChatModule);
|
||||
exports.ChatModule = ChatModule;
|
||||
1156
dist/modules/chat/chat.service.js
vendored
Normal file
1156
dist/modules/chat/chat.service.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
48
dist/modules/chat/chatBox.entity.js
vendored
Normal file
48
dist/modules/chat/chatBox.entity.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatBoxEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let ChatBoxEntity = class ChatBoxEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分类ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatBoxEntity.prototype, "typeId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用ID', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatBoxEntity.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '快速描述词', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatBoxEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '标题名称' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatBoxEntity.prototype, "title", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '排序ID', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatBoxEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '开启状态', default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatBoxEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '跳转地址' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatBoxEntity.prototype, "url", void 0);
|
||||
ChatBoxEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chat_box' })
|
||||
], ChatBoxEntity);
|
||||
exports.ChatBoxEntity = ChatBoxEntity;
|
||||
36
dist/modules/chat/chatBoxType.entity.js
vendored
Normal file
36
dist/modules/chat/chatBoxType.entity.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatBoxTypeEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let ChatBoxTypeEntity = class ChatBoxTypeEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分类名称' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatBoxTypeEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'icon图标' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatBoxTypeEntity.prototype, "icon", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '排序ID', default: 10 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatBoxTypeEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否打开', default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatBoxTypeEntity.prototype, "status", void 0);
|
||||
ChatBoxTypeEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chat_box_type' })
|
||||
], ChatBoxTypeEntity);
|
||||
exports.ChatBoxTypeEntity = ChatBoxTypeEntity;
|
||||
40
dist/modules/chat/chatPre.entity.js
vendored
Normal file
40
dist/modules/chat/chatPre.entity.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatPreEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let ChatPreEntity = class ChatPreEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分类ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatPreEntity.prototype, "typeId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '预设问题描述词', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatPreEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '标题名称' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatPreEntity.prototype, "title", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '排序ID', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatPreEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '开启状态', default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatPreEntity.prototype, "status", void 0);
|
||||
ChatPreEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chat_pre' })
|
||||
], ChatPreEntity);
|
||||
exports.ChatPreEntity = ChatPreEntity;
|
||||
36
dist/modules/chat/chatPreType.entity.js
vendored
Normal file
36
dist/modules/chat/chatPreType.entity.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatPreTypeEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let ChatPreTypeEntity = class ChatPreTypeEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '分类名称' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatPreTypeEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'icon图标', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatPreTypeEntity.prototype, "icon", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '排序ID', default: 10 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatPreTypeEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否打开', default: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatPreTypeEntity.prototype, "status", void 0);
|
||||
ChatPreTypeEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chat_pre_type' })
|
||||
], ChatPreTypeEntity);
|
||||
exports.ChatPreTypeEntity = ChatPreTypeEntity;
|
||||
78
dist/modules/chat/dto/chatDraw.dto.js
vendored
Normal file
78
dist/modules/chat/dto/chatDraw.dto.js
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatDrawDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class ChatDrawDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'Draw a cute little dog', description: '绘画描述信息' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '绘画张数', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "n", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '1024x1024', description: '图片尺寸', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'standard', description: '图片质量', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "quality", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 'close-up polaroid photo, of a little joyful cute panda, in the forest, sun rays coming, photographic, sharp focus, depth of field, soft lighting, heigh quality, 24mm, Nikon Z FX',
|
||||
description: '绘画提示词!',
|
||||
required: true,
|
||||
}),
|
||||
(0, swagger_1.ApiProperty)({ example: '--ar 16:9 --c 0', description: '除了prompt的额外参数' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "extraParam", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xsdasdasd.com', description: '垫图图片地址' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "imgUrl", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'IMAGINE', description: '任务类型,可用值:IMAGINE,UPSCALE,VARIATION,ZOOM,PAN,DESCRIBE,BLEND,SHORTEN,SWAP_FACE' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "action", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '变体或者放大的序号' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "orderId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '绘画的DBID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "drawId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'customId' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "customId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'base64' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatDrawDto.prototype, "base64", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '任务ID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatDrawDto.prototype, "taskId", void 0);
|
||||
exports.ChatDrawDto = ChatDrawDto;
|
||||
57
dist/modules/chat/dto/chatProcess.dto.js
vendored
Normal file
57
dist/modules/chat/dto/chatProcess.dto.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChatProcessDto = exports.Options = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_transformer_1 = require("class-transformer");
|
||||
class Options {
|
||||
}
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], Options.prototype, "parentMessageId", void 0);
|
||||
exports.Options = Options;
|
||||
class ChatProcessDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'hello, Who are you', description: '对话信息' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '提问信息不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://aiweb.com', description: '对话附带的链接', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "url", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '{ parentMessageId: 0 }', description: '上次对话信息', required: false }),
|
||||
(0, class_transformer_1.Type)(() => Options),
|
||||
__metadata("design:type", Options)
|
||||
], ChatProcessDto.prototype, "options", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
|
||||
description: '系统预设信息',
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "systemMessage", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '应用id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], ChatProcessDto.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: "gpt-3.5-turbo", description: '使用模型', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], ChatProcessDto.prototype, "model", void 0);
|
||||
exports.ChatProcessDto = ChatProcessDto;
|
||||
46
dist/modules/chat/helper.js
vendored
Normal file
46
dist/modules/chat/helper.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.addOneIfOdd = exports.unifiedFormattingResponse = void 0;
|
||||
function unifiedFormattingResponse(keyType, response, others) {
|
||||
let formatRes = {
|
||||
keyType,
|
||||
parentMessageId: '',
|
||||
text: '',
|
||||
usage: {
|
||||
prompt_tokens: 0,
|
||||
completion_tokens: 0,
|
||||
total_tokens: 0,
|
||||
}
|
||||
};
|
||||
const { parentMessageId } = response === null || response === void 0 ? void 0 : response.detail;
|
||||
let { usage } = response === null || response === void 0 ? void 0 : response.detail;
|
||||
if (!usage) {
|
||||
usage = {
|
||||
prompt_tokens: 0,
|
||||
completion_tokens: 0,
|
||||
total_tokens: 0
|
||||
};
|
||||
}
|
||||
const { prompt_tokens, completion_tokens, total_tokens } = usage;
|
||||
formatRes = {
|
||||
keyType,
|
||||
parentMessageId,
|
||||
text: response.text,
|
||||
usage: {
|
||||
prompt_tokens,
|
||||
completion_tokens,
|
||||
total_tokens
|
||||
}
|
||||
};
|
||||
return formatRes;
|
||||
}
|
||||
exports.unifiedFormattingResponse = unifiedFormattingResponse;
|
||||
function addOneIfOdd(num) {
|
||||
if (num % 2 !== 0) {
|
||||
return num + 1;
|
||||
}
|
||||
else {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
exports.addOneIfOdd = addOneIfOdd;
|
||||
115
dist/modules/chat/store.js
vendored
Normal file
115
dist/modules/chat/store.js
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NineStore = void 0;
|
||||
const uuid_1 = require("uuid");
|
||||
const tiktoken_1 = require("@dqbd/tiktoken");
|
||||
const tokenizer = (0, tiktoken_1.get_encoding)('cl100k_base');
|
||||
class NineStore {
|
||||
constructor(options) {
|
||||
const { store, namespace, expires } = this.formatOptions(options);
|
||||
this.store = store;
|
||||
this.namespace = namespace;
|
||||
this.expires = expires;
|
||||
}
|
||||
formatOptions(options) {
|
||||
const { store, expires = 1000 * 60 * 60 * 24 * 3, namespace = 'chat' } = options;
|
||||
return { store, namespace, expires };
|
||||
}
|
||||
generateKey(key) {
|
||||
return this.namespace ? `${this.namespace}-${key}` : key;
|
||||
}
|
||||
async getData(id) {
|
||||
const res = await this.store.get(id);
|
||||
return res;
|
||||
}
|
||||
async setData(message, expires = this.expires) {
|
||||
await this.store.set(message.id, message, expires);
|
||||
}
|
||||
async buildMessageFromParentMessageId(text, options, chatLogService) {
|
||||
let { systemMessage = '', fileInfo, model, groupId, maxRounds = 5, maxModelTokens = 4000, isFileUpload = 0 } = options;
|
||||
let messages = [];
|
||||
if (systemMessage) {
|
||||
messages.push({ role: 'system', content: systemMessage });
|
||||
}
|
||||
if (groupId) {
|
||||
const history = await chatLogService.chatHistory(groupId, maxRounds);
|
||||
history.forEach((record) => {
|
||||
let content;
|
||||
if (isFileUpload === 2 && record.fileInfo) {
|
||||
content = [
|
||||
{ type: "text", text: record.text },
|
||||
{ type: "image_url", image_url: { url: record.fileInfo } }
|
||||
];
|
||||
}
|
||||
else if (isFileUpload === 1 && record.fileInfo) {
|
||||
content = record.fileInfo + "\n" + record.text;
|
||||
}
|
||||
else {
|
||||
content = record.text;
|
||||
}
|
||||
messages.push({ role: record.role, content });
|
||||
});
|
||||
}
|
||||
let currentMessageContent;
|
||||
if (isFileUpload === 2 && fileInfo) {
|
||||
currentMessageContent = [
|
||||
{ type: "text", text },
|
||||
{ type: "image_url", image_url: { url: fileInfo } }
|
||||
];
|
||||
}
|
||||
else if (isFileUpload === 1 && fileInfo) {
|
||||
currentMessageContent = fileInfo + "\n" + text;
|
||||
}
|
||||
else {
|
||||
currentMessageContent = text;
|
||||
}
|
||||
messages.push({ role: 'user', content: currentMessageContent });
|
||||
let totalTokens = await this._getTokenCount(messages);
|
||||
while (totalTokens > maxModelTokens / 2) {
|
||||
let foundNonSystemMessage = false;
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
if (messages[i].role !== 'system') {
|
||||
messages.splice(i, 2);
|
||||
foundNonSystemMessage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundNonSystemMessage) {
|
||||
break;
|
||||
}
|
||||
totalTokens = await this._getTokenCount(messages);
|
||||
}
|
||||
return {
|
||||
messagesHistory: messages,
|
||||
round: messages.length
|
||||
};
|
||||
}
|
||||
_getTokenCount(messages) {
|
||||
let text = messages.reduce((pre, cur) => {
|
||||
if (Array.isArray(cur.content)) {
|
||||
const contentText = cur.content
|
||||
.filter((item) => item.type === 'text')
|
||||
.map((item) => item.text)
|
||||
.join(' ');
|
||||
return pre + contentText;
|
||||
}
|
||||
else {
|
||||
return pre + (cur.content || '');
|
||||
}
|
||||
}, '');
|
||||
text = text.replace(/<\|endoftext\|>/g, '');
|
||||
return tokenizer.encode(text).length;
|
||||
}
|
||||
_recursivePruning(messages, maxNumTokens, systemMessage) {
|
||||
const currentTokens = this._getTokenCount(messages);
|
||||
if (currentTokens <= maxNumTokens) {
|
||||
return messages;
|
||||
}
|
||||
messages.splice(systemMessage ? 1 : 0, 1);
|
||||
return this._recursivePruning(messages, maxNumTokens, systemMessage);
|
||||
}
|
||||
getUuid() {
|
||||
return (0, uuid_1.v4)();
|
||||
}
|
||||
}
|
||||
exports.NineStore = NineStore;
|
||||
36
dist/modules/chat/whiteList.entity.js
vendored
Normal file
36
dist/modules/chat/whiteList.entity.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WhiteListEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let WhiteListEntity = class WhiteListEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: '用户ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], WhiteListEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '使用次数限制', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], WhiteListEntity.prototype, "count", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '当前用户状态', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], WhiteListEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '已经使用的次数', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], WhiteListEntity.prototype, "useCount", void 0);
|
||||
WhiteListEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'white_list' })
|
||||
], WhiteListEntity);
|
||||
exports.WhiteListEntity = WhiteListEntity;
|
||||
Reference in New Issue
Block a user