This commit is contained in:
vastxie
2024-07-07 13:09:08 +08:00
parent 086e5aed3c
commit 4fef3663e4
1131 changed files with 11143 additions and 10769 deletions

View File

@@ -1,153 +0,0 @@
"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 ApiDataService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiDataService = void 0;
const common_1 = require("@nestjs/common");
const axios_1 = require("axios");
const uuid = require("uuid");
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
const upload_service_1 = require("../upload/upload.service");
let ApiDataService = ApiDataService_1 = class ApiDataService {
constructor(uploadService, globalConfigService) {
this.uploadService = uploadService;
this.globalConfigService = globalConfigService;
this.logger = new common_1.Logger(ApiDataService_1.name);
}
async chatFree(prompt, systemMessage, messagesHistory) {
const { openaiBaseUrl = '', openaiBaseKey = '', openaiBaseModel, } = await this.globalConfigService.getConfigs([
'openaiBaseKey',
'openaiBaseUrl',
'openaiBaseModel',
]);
const key = openaiBaseKey;
const proxyUrl = openaiBaseUrl;
let requestData = [];
if (systemMessage) {
requestData.push({
"role": "system",
"content": systemMessage
});
}
if (messagesHistory && messagesHistory.length > 0) {
requestData = requestData.concat(messagesHistory);
}
else {
requestData.push({
"role": "user",
"content": prompt
});
}
const options = {
method: 'POST',
url: `${proxyUrl}/v1/chat/completions`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${key}`,
},
data: {
model: openaiBaseModel || 'gpt-3.5-turbo-0125',
messages: requestData,
},
};
try {
const response = await (0, axios_1.default)(options);
common_1.Logger.log(`全局模型调用成功, 返回结果: ${response === null || response === void 0 ? void 0 : response.data.choices[0].message.content}`);
return response === null || response === void 0 ? void 0 : response.data.choices[0].message.content;
}
catch (error) {
console.log('error: ', error);
}
}
async dalleDraw(inputs, messagesHistory) {
var _a, _b, _c, _d;
common_1.Logger.log('开始提交 Dalle 绘图任务 ', 'DrawService');
const { apiKey, model, proxyUrl, prompt, extraParam, timeout, onSuccess, onFailure } = inputs;
const size = (extraParam === null || extraParam === void 0 ? void 0 : extraParam.size) || '1024x1024';
let result = { answer: '', fileInfo: '', status: 2 };
try {
const options = {
method: 'POST',
url: `${proxyUrl}/v1/images/generations`,
timeout: timeout,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
data: {
model: model,
prompt: prompt,
size,
},
};
const response = await (0, axios_1.default)(options);
common_1.Logger.debug(`请求成功${JSON.stringify(response.data.data[0])}`);
common_1.Logger.debug(`请求状态${JSON.stringify(response.status)}`);
const url = response.data.data[0].url;
try {
const filename = `${Date.now()}-${uuid.v4().slice(0, 4)}.png`;
common_1.Logger.debug(`------> 开始上传图片!!!`, 'DrawService');
result.fileInfo = await this.uploadService.uploadFileFromUrl({ filename, url: url });
common_1.Logger.debug(`图片上传成功URL: ${result.fileInfo}`, 'DrawService');
}
catch (error) {
common_1.Logger.error(`上传图片过程中出现错误: ${error}`, 'DrawService');
}
let revised_prompt_cn;
try {
revised_prompt_cn = await this.chatFree(`根据提示词{${response.data.data[0].revised_prompt}}, 模拟AI绘画机器人的语气用中文回复告诉用户已经画好了`);
}
catch (error) {
revised_prompt_cn = `${prompt} 绘制成功`;
common_1.Logger.error("翻译失败: ", error);
}
result.answer = revised_prompt_cn;
result.status = 3;
onSuccess(result);
return;
}
catch (error) {
result.status = 5;
onFailure(result);
const status = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
console.log('draw error: ', JSON.stringify(error), status);
const message = (_d = (_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message;
if (status === 429) {
result.text = '当前请求已过载、请稍等会儿再试试吧!';
return result;
}
if (status === 400 && message.includes('This request has been blocked by our content filters')) {
result.text = '您的请求已被系统拒绝。您的提示可能存在一些非法的文本。';
return result;
}
if (status === 400 && message.includes('Billing hard limit has been reached')) {
result.text = '当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧';
return result;
}
if (status === 500) {
result.text = '绘制图片失败,请检查你的提示词是否有非法描述!';
return result;
}
if (status === 401) {
result.text = '绘制图片失败,此次绘画被拒绝了!';
return result;
}
result.text = '绘制图片失败,请稍后试试吧!';
return result;
}
}
};
ApiDataService = ApiDataService_1 = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [upload_service_1.UploadService,
globalConfig_service_1.GlobalConfigService])
], ApiDataService);
exports.ApiDataService = ApiDataService;

View File

@@ -18,8 +18,6 @@ const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
const chat_service_1 = require("./chat.service");
const common_1 = require("@nestjs/common");
const chatProcess_dto_1 = require("./dto/chatProcess.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) {
@@ -32,56 +30,14 @@ let ChatController = class ChatController {
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) {
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: 'PromptOptimization' }), req);
}
async chatmind(body, req, res) {
return this.chatService.chatProcess(Object.assign(Object.assign({}, body), { specialModel: 'MindMap' }), req, res);
}
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();
ttsProcess(body, req, res) {
return this.chatService.ttsProcess(body, req, res);
}
};
__decorate([
@@ -107,18 +63,6 @@ __decorate([
__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描述词绘画翻译' }),
@@ -143,142 +87,21 @@ __decorate([
__metadata("design:returntype", Promise)
], ChatController.prototype, "chatmind", null);
__decorate([
(0, common_1.Post)('setChatBoxType'),
(0, swagger_1.ApiOperation)({ summary: '添加修改分类类型' }),
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
(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.Req)()),
__param(1, (0, common_1.Body)()),
__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", [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);
__metadata("design:paramtypes", [Object, Object, Object]),
__metadata("design:returntype", void 0)
], ChatController.prototype, "ttsProcess", null);
ChatController = __decorate([
(0, swagger_1.ApiTags)('chatgpt'),
(0, common_1.Controller)('chatgpt'),
__metadata("design:paramtypes", [chat_service_1.ChatService, globalConfig_service_1.GlobalConfigService])
__metadata("design:paramtypes", [chat_service_1.ChatService,
globalConfig_service_1.GlobalConfigService])
], ChatController);
exports.ChatController = ChatController;

View File

@@ -9,6 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatModule = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const lumaVideo_service_1 = require("../ai/lumaVideo.service");
const midjourneyDraw_service_1 = require("../ai/midjourneyDraw.service");
const openaiChat_service_1 = require("../ai/openaiChat.service");
const openaiDraw_service_1 = require("../ai/openaiDraw.service");
const stableDiffusion_service_1 = require("../ai/stableDiffusion.service");
const suno_service_1 = require("../ai/suno.service");
const app_entity_1 = require("../app/app.entity");
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
@@ -17,6 +23,7 @@ const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
const config_entity_1 = require("../globalConfig/config.entity");
const mailer_service_1 = require("../mailer/mailer.service");
const midjourney_entity_1 = require("../midjourney/midjourney.entity");
const plugin_entity_1 = require("../plugin/plugin.entity");
const redisCache_service_1 = require("../redisCache/redisCache.service");
const salesUsers_entity_1 = require("../sales/salesUsers.entity");
const user_entity_1 = require("../user/user.entity");
@@ -28,14 +35,8 @@ const userBalance_entity_1 = require("../userBalance/userBalance.entity");
const userBalance_service_1 = require("../userBalance/userBalance.service");
const verification_service_1 = require("../verification/verification.service");
const verifycation_entity_1 = require("../verification/verifycation.entity");
const apiDataService_service_1 = require("./apiDataService.service");
const chat_controller_1 = require("./chat.controller");
const chat_service_1 = require("./chat.service");
const chatBox_entity_1 = require("./chatBox.entity");
const chatBoxType_entity_1 = require("./chatBoxType.entity");
const chatPre_entity_1 = require("./chatPre.entity");
const chatPreType_entity_1 = require("./chatPreType.entity");
const whiteList_entity_1 = require("./whiteList.entity");
let ChatModule = class ChatModule {
};
ChatModule = __decorate([
@@ -45,11 +46,11 @@ ChatModule = __decorate([
typeorm_1.TypeOrmModule.forFeature([
balance_entity_1.BalanceEntity,
user_entity_1.UserEntity,
plugin_entity_1.PluginEntity,
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,
@@ -58,15 +59,25 @@ ChatModule = __decorate([
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, apiDataService_service_1.ApiDataService, mailer_service_1.MailerService],
exports: [chat_service_1.ChatService]
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,
mailer_service_1.MailerService,
suno_service_1.SunoService,
openaiChat_service_1.OpenAIChatService,
stableDiffusion_service_1.StableDiffusionService,
midjourneyDraw_service_1.MidjourneyService,
openaiDraw_service_1.OpenAIDrawService,
lumaVideo_service_1.LumaVideoService,
],
exports: [chat_service_1.ChatService],
})
], ChatModule);
exports.ChatModule = ChatModule;

File diff suppressed because it is too large Load Diff

View File

@@ -1,48 +0,0 @@
"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;

View File

@@ -1,36 +0,0 @@
"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;

View File

@@ -1,40 +0,0 @@
"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;

View File

@@ -1,36 +0,0 @@
"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;

View File

@@ -1,137 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NineStore = void 0;
const tiktoken_1 = require("@dqbd/tiktoken");
const uuid_1 = require("uuid");
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) {
console.log('Adding system message:', systemMessage);
messages.push({ role: 'system', content: systemMessage });
}
if (groupId) {
console.log('Querying chat history for groupId:', groupId, 'with maxRounds:', maxRounds);
const history = await chatLogService.chatHistory(groupId, maxRounds);
console.log('Received history records:', history.length);
let tempUserMessage = null;
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;
}
if (record.role === 'user') {
tempUserMessage = { role: record.role, content };
}
else if (record.role === 'assistant' && tempUserMessage && content.trim() !== '') {
messages.push(tempUserMessage);
messages.push({ role: record.role, content });
tempUserMessage = null;
}
});
}
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) {
if (messages.length === 2 && messages[0].role === 'system' && messages[1].role === 'user') {
break;
}
let foundPairToDelete = false;
for (let i = 0; i < messages.length; i++) {
if (messages[i].role !== 'system' && messages[i + 1] && messages[i + 1].role === 'assistant') {
messages.splice(i, 2);
foundPairToDelete = true;
break;
}
}
if (!foundPairToDelete) {
for (let i = 0; i < messages.length; i++) {
if (messages[i].role === 'user') {
messages.splice(i, 1);
break;
}
}
}
totalTokens = await this._getTokenCount(messages);
if (messages.length <= 2) {
break;
}
}
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;

View File

@@ -1,36 +0,0 @@
"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;