NineAI 2.4.2

This commit is contained in:
vastxie
2024-01-17 09:22:28 +08:00
commit bdc48207fc
636 changed files with 41864 additions and 0 deletions

View File

@@ -0,0 +1,162 @@
"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.ChatLogController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
const chatLog_service_1 = require("./chatLog.service");
const queryAllDrawLog_dto_1 = require("./dto/queryAllDrawLog.dto");
const queryAllChatLog_dto_1 = require("./dto/queryAllChatLog.dto");
const recDrawImg_dto_1 = require("./dto/recDrawImg.dto");
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
const queryMyChatLog_dto_1 = require("./dto/queryMyChatLog.dto");
const exportExcelChatlog_dto_1 = require("./dto/exportExcelChatlog.dto");
const chatList_dto_1 = require("./dto/chatList.dto");
const del_dto_1 = require("./dto/del.dto");
const delByGroup_dto_1 = require("./dto/delByGroup.dto");
const queryByAppId_dto_1 = require("./dto/queryByAppId.dto");
let ChatLogController = class ChatLogController {
constructor(chatLogService) {
this.chatLogService = chatLogService;
}
querDrawLog(query, req) {
return this.chatLogService.querDrawLog(req, query);
}
recDrawImg(body) {
return this.chatLogService.recDrawImg(body);
}
querAllDrawLog(params) {
return this.chatLogService.querAllDrawLog(params);
}
queryAllChatLog(params, req) {
return this.chatLogService.querAllChatLog(params, req);
}
exportExcel(body, res) {
return this.chatLogService.exportExcel(body, res);
}
chatList(req, params) {
return this.chatLogService.chatList(req, params);
}
del(req, body) {
return this.chatLogService.deleteChatLog(req, body);
}
delByGroupId(req, body) {
return this.chatLogService.delByGroupId(req, body);
}
byAppId(req, params) {
return this.chatLogService.byAppId(req, params);
}
};
__decorate([
(0, common_1.Get)('draw'),
(0, swagger_1.ApiOperation)({ summary: '查询我的绘制记录' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
__param(0, (0, common_1.Query)()),
__param(1, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [queryMyChatLog_dto_1.QuerMyChatLogDto, Object]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "querDrawLog", null);
__decorate([
(0, common_1.Post)('recDrawImg'),
(0, swagger_1.ApiOperation)({ summary: '推荐此图片对外展示' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
__param(0, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [recDrawImg_dto_1.recDrawImgDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "recDrawImg", null);
__decorate([
(0, common_1.Get)('drawAll'),
(0, swagger_1.ApiOperation)({ summary: '查询所有的绘制记录' }),
__param(0, (0, common_1.Query)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [queryAllDrawLog_dto_1.QuerAllDrawLogDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "querAllDrawLog", null);
__decorate([
(0, common_1.Get)('chatAll'),
(0, swagger_1.ApiOperation)({ summary: '查询所有的问答记录' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
__param(0, (0, common_1.Query)()),
__param(1, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [queryAllChatLog_dto_1.QuerAllChatLogDto, Object]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "queryAllChatLog", null);
__decorate([
(0, common_1.Post)('exportExcel'),
(0, swagger_1.ApiOperation)({ summary: '导出问答记录' }),
(0, swagger_1.ApiBearerAuth)(),
__param(0, (0, common_1.Body)()),
__param(1, (0, common_1.Res)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [exportExcelChatlog_dto_1.ExportExcelChatlogDto, Object]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "exportExcel", null);
__decorate([
(0, common_1.Get)('chatList'),
(0, swagger_1.ApiOperation)({ summary: '查询我的问答记录' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Query)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, chatList_dto_1.ChatListDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "chatList", null);
__decorate([
(0, common_1.Post)('del'),
(0, swagger_1.ApiOperation)({ summary: '删除我的问答记录' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, del_dto_1.DelDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "del", null);
__decorate([
(0, common_1.Post)('delByGroupId'),
(0, swagger_1.ApiOperation)({ summary: '清空一组对话' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, delByGroup_dto_1.DelByGroupDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "delByGroupId", null);
__decorate([
(0, common_1.Get)('byAppId'),
(0, swagger_1.ApiOperation)({ summary: '查询某个应用的问答记录' }),
(0, swagger_1.ApiBearerAuth)(),
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Query)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, queryByAppId_dto_1.QueryByAppIdDto]),
__metadata("design:returntype", void 0)
], ChatLogController.prototype, "byAppId", null);
ChatLogController = __decorate([
(0, common_1.Controller)('chatLog'),
(0, swagger_1.ApiTags)('ChatLog'),
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService])
], ChatLogController);
exports.ChatLogController = ChatLogController;

116
dist/modules/chatLog/chatLog.entity.js vendored Normal file
View File

@@ -0,0 +1,116 @@
"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.ChatLogEntity = void 0;
const typeorm_1 = require("typeorm");
const baseEntity_1 = require("../../common/entity/baseEntity");
let ChatLogEntity = class ChatLogEntity extends baseEntity_1.BaseEntity {
};
__decorate([
(0, typeorm_1.Column)({ comment: '用户ID' }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "userId", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '使用类型', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "type", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '询问的问题', type: 'text', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "prompt", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '回答的答案', type: 'text', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "answer", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '本次问题的token', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "promptTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '本次回答的token', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "completionTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '本次总花费的token', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "totalTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '本次使用的模型', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "model", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '本次访问的Ip地址', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "curIp", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否推荐0: 默认 1: 推荐', nullable: true, default: 0 }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "rec", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '扩展参数', nullable: true, type: 'text' }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "extend", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'mj绘画列表携带的一级id用于图片变换或者放大', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "message_id", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '一组图片的第几张、放大或者变换的时候需要使用', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "orderId", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'mj绘画的动作、放大或者变换、或者全部重新绘制', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "action", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否是组图,这种图才可以指定放大', default: 0 }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "group", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '放大图片的Id记录', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "upscaleId", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '变换图片的Id记录', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "variationId", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '图片信息的string', nullable: true, type: 'text' }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "fileInfo", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'role system user assistant', nullable: true }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "role", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '对话分组ID', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "groupId", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '序列化的本次会话参数', nullable: true, type: 'text' }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "conversationOptions", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '序列化的本次提交参数', nullable: true, type: 'text' }),
__metadata("design:type", String)
], ChatLogEntity.prototype, "requestOptions", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否删除', default: false }),
__metadata("design:type", Boolean)
], ChatLogEntity.prototype, "isDelete", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '使用的应用id', nullable: true }),
__metadata("design:type", Number)
], ChatLogEntity.prototype, "appId", void 0);
ChatLogEntity = __decorate([
(0, typeorm_1.Entity)({ name: 'chatlog' })
], ChatLogEntity);
exports.ChatLogEntity = ChatLogEntity;

29
dist/modules/chatLog/chatLog.module.js vendored Normal file
View File

@@ -0,0 +1,29 @@
"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.ChatLogModule = void 0;
const common_1 = require("@nestjs/common");
const chatLog_service_1 = require("./chatLog.service");
const typeorm_1 = require("@nestjs/typeorm");
const chatLog_entity_1 = require("./chatLog.entity");
const chatLog_controller_1 = require("./chatLog.controller");
const user_entity_1 = require("../user/user.entity");
const badwords_entity_1 = require("../badwords/badwords.entity");
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
let ChatLogModule = class ChatLogModule {
};
ChatLogModule = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({
imports: [typeorm_1.TypeOrmModule.forFeature([chatLog_entity_1.ChatLogEntity, user_entity_1.UserEntity, badwords_entity_1.BadWordsEntity, chatGroup_entity_1.ChatGroupEntity])],
controllers: [chatLog_controller_1.ChatLogController],
providers: [chatLog_service_1.ChatLogService],
exports: [chatLog_service_1.ChatLogService],
})
], ChatLogModule);
exports.ChatLogModule = ChatLogModule;

269
dist/modules/chatLog/chatLog.service.js vendored Normal file
View File

@@ -0,0 +1,269 @@
"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.ChatLogService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const chatLog_entity_1 = require("./chatLog.entity");
const typeorm_2 = require("typeorm");
const balance_constant_1 = require("../../common/constants/balance.constant");
const user_entity_1 = require("../user/user.entity");
const utils_1 = require("../../common/utils");
const exceljs_1 = require("exceljs");
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
let ChatLogService = class ChatLogService {
constructor(chatLogEntity, userEntity, chatGroupEntity) {
this.chatLogEntity = chatLogEntity;
this.userEntity = userEntity;
this.chatGroupEntity = chatGroupEntity;
}
async saveChatLog(logInfo) {
return await this.chatLogEntity.save(logInfo);
}
async querDrawLog(req, query) {
const { id } = req.user;
const { model } = query;
const where = { userId: id, type: balance_constant_1.DeductionKey.PAINT_TYPE };
if (model) {
where.model = model;
if (model === 'DALL-E2') {
where.model = (0, typeorm_2.In)(['DALL-E2', 'dall-e-3']);
}
}
const data = await this.chatLogEntity.find({
where,
order: { id: 'DESC' },
select: ['id', 'answer', 'prompt', 'message_id', 'group', 'model', 'extend', 'type', 'fileInfo'],
});
data.forEach((r) => {
if (r.type === 'paintCount') {
const w = r.model === 'mj' ? 310 : 160;
const imgType = r.answer.includes('cos') ? 'tencent' : 'ali';
const compress = imgType === 'tencent' ? `?imageView2/1/w/${w}/q/55` : `?x-oss-process=image/resize,w_${w}`;
r.thumbImg = r.answer + compress;
try {
r.fileInfo = r.fileInfo ? JSON.parse(r.fileInfo) : null;
}
catch (error) {
r.fileInfo = {};
}
}
});
return data;
}
async querAllDrawLog(params) {
const { page = 1, size = 20, rec, userId, model } = params;
const where = { type: balance_constant_1.DeductionKey.PAINT_TYPE, prompt: (0, typeorm_2.Not)(''), answer: (0, typeorm_2.Not)('') };
rec && Object.assign(where, { rec });
userId && Object.assign(where, { userId });
if (model) {
where.model = model;
if (model === 'DALL-E2') {
where.model = (0, typeorm_2.In)(['DALL-E2', 'dall-e-3']);
}
}
const [rows, count] = await this.chatLogEntity.findAndCount({
order: { id: 'DESC' },
skip: (page - 1) * size,
take: size,
where,
});
rows.forEach((r) => {
var _a;
if (r.type === 'paintCount') {
const w = r.model === 'mj' ? 310 : 160;
const imgType = r.answer.includes('cos') ? 'tencent' : 'ali';
const compress = imgType === 'tencent' ? `?imageView2/1/w/${w}/q/55` : `?x-oss-process=image/resize,w_${w}`;
r.thumbImg = r.answer + compress;
try {
const detailInfo = r.extend ? JSON.parse(r.extend) : null;
if (detailInfo) {
if (detailInfo) {
r.isGroup = ((_a = detailInfo === null || detailInfo === void 0 ? void 0 : detailInfo.components[0]) === null || _a === void 0 ? void 0 : _a.components.length) === 5;
}
else {
r.isGroup = false;
}
}
}
catch (error) {
console.log('querAllDrawLog Json parse error', error);
}
}
});
return { rows, count };
}
async recDrawImg(body) {
const { id } = body;
const l = await this.chatLogEntity.findOne({ where: { id, type: balance_constant_1.DeductionKey.PAINT_TYPE } });
if (!l) {
throw new common_1.HttpException('你推荐的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
const rec = l.rec === 1 ? 0 : 1;
const res = await this.chatLogEntity.update({ id }, { rec });
if (res.affected > 0) {
return `${rec ? '推荐' : '取消推荐'}图片成功!`;
}
throw new common_1.HttpException('你操作的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
async exportExcel(body, res) {
const where = { type: balance_constant_1.DeductionKey.CHAT_TYPE };
const { page = 1, size = 30, prompt, email } = body;
prompt && Object.assign(where, { prompt: (0, typeorm_2.Like)(`%${prompt}%`) });
if (email) {
const user = await this.userEntity.findOne({ where: { email } });
(user === null || user === void 0 ? void 0 : user.id) && Object.assign(where, { userId: user.id });
}
const [rows, count] = await this.chatLogEntity.findAndCount({
order: { id: 'DESC' },
skip: (page - 1) * size,
take: size,
where,
});
const userIds = rows.map((r) => r.userId);
const userInfos = await this.userEntity.find({ where: { id: (0, typeorm_2.In)(userIds) } });
const data = rows.map((r) => {
const userInfo = userInfos.find((u) => u.id === r.userId);
return {
username: userInfo ? userInfo.username : '',
email: userInfo ? userInfo.email : '',
prompt: r.prompt,
answer: r.answer,
createdAt: (0, utils_1.formatDate)(r.createdAt),
};
});
const workbook = new exceljs_1.default.Workbook();
const worksheet = workbook.addWorksheet('chatlog');
worksheet.columns = [
{ header: '用户名', key: 'username', width: 20 },
{ header: '用户邮箱', key: 'email', width: 20 },
{ header: '提问时间', key: 'createdAt', width: 20 },
{ header: '提问问题', key: 'prompt', width: 80 },
{ header: '回答答案', key: 'answer', width: 150 },
];
data.forEach((row) => worksheet.addRow(row));
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader('Content-Disposition', 'attachment; filename=' + 'chat.xlsx');
await workbook.xlsx.write(res);
res.end();
}
async querAllChatLog(params, req) {
const { page = 1, size = 20, userId, prompt } = params;
const where = { type: balance_constant_1.DeductionKey.CHAT_TYPE, prompt: (0, typeorm_2.Not)('') };
userId && Object.assign(where, { userId });
prompt && Object.assign(where, { prompt: (0, typeorm_2.Like)(`%${prompt}%`) });
const [rows, count] = await this.chatLogEntity.findAndCount({
order: { id: 'DESC' },
skip: (page - 1) * size,
take: size,
where,
});
const userIds = rows.map((item) => item.userId);
const userInfo = await this.userEntity.find({ where: { id: (0, typeorm_2.In)(userIds) }, select: ['id', 'username', 'email'] });
rows.forEach((item) => {
const { username, email } = userInfo.find((u) => u.id === item.userId) || {};
item.username = username;
item.email = email;
});
req.user.role !== 'super' && rows.forEach((t) => (t.email = (0, utils_1.maskEmail)(t.email)));
rows.forEach((item) => {
!item.email && (item.email = `${item === null || item === void 0 ? void 0 : item.userId}@nine.com`);
!item.username && (item.username = `游客${item === null || item === void 0 ? void 0 : item.userId}`);
});
return { rows, count };
}
async chatList(req, params) {
const { id } = req.user;
const { groupId } = params;
const where = { userId: id, isDelete: false };
groupId && Object.assign(where, { groupId });
if (groupId) {
const count = await this.chatGroupEntity.count({ where: { isDelete: false } });
if (count === 0)
return [];
}
const list = await this.chatLogEntity.find({ where });
return list.map((item) => {
const { prompt, role, answer, createdAt, model, conversationOptions, requestOptions, id } = item;
let parseConversationOptions = null;
let parseRequestOptions = null;
try {
parseConversationOptions = JSON.parse(conversationOptions);
parseRequestOptions = JSON.parse(requestOptions);
}
catch (error) {
}
return {
chatId: id,
dateTime: (0, utils_1.formatDate)(createdAt),
text: role === 'user' ? prompt : answer,
inversion: role === 'user',
error: false,
conversationOptions: parseConversationOptions,
requestOptions: parseRequestOptions,
};
});
}
async deleteChatLog(req, body) {
const { id: userId } = req.user;
const { id } = body;
const c = await this.chatLogEntity.findOne({ where: { id, userId } });
if (!c) {
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
const r = await this.chatLogEntity.update({ id }, { isDelete: true });
if (r.affected > 0) {
return '删除对话记录成功!';
}
else {
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
}
async delByGroupId(req, body) {
const { groupId } = body;
const { id } = req.user;
const g = await this.chatGroupEntity.findOne({ where: { id: groupId, userId: id } });
if (!g) {
throw new common_1.HttpException('你删除的对话记录不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
}
const r = await this.chatLogEntity.update({ groupId }, { isDelete: true });
if (r.affected > 0) {
return '删除对话记录成功!';
}
if (r.affected === 0) {
throw new common_1.HttpException('当前页面已经没有东西可以删除了!', common_1.HttpStatus.BAD_REQUEST);
}
}
async byAppId(req, body) {
const { id } = req.user;
const { appId, page = 1, size = 10 } = body;
const [rows, count] = await this.chatLogEntity.findAndCount({
where: { userId: id, appId, role: 'assistant' },
order: { id: 'DESC' },
take: size,
skip: (page - 1) * size,
});
return { rows, count };
}
};
ChatLogService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(chatLog_entity_1.ChatLogEntity)),
__param(1, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
__param(2, (0, typeorm_1.InjectRepository)(chatGroup_entity_1.ChatGroupEntity)),
__metadata("design:paramtypes", [typeorm_2.Repository,
typeorm_2.Repository,
typeorm_2.Repository])
], ChatLogService);
exports.ChatLogService = ChatLogService;

View File

@@ -0,0 +1,22 @@
"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.ChatListDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class ChatListDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '对话分组ID', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], ChatListDto.prototype, "groupId", void 0);
exports.ChatListDto = ChatListDto;

20
dist/modules/chatLog/dto/del.dto.js vendored Normal file
View File

@@ -0,0 +1,20 @@
"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.DelDto = void 0;
const swagger_1 = require("@nestjs/swagger");
class DelDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '对话Id', required: true }),
__metadata("design:type", Number)
], DelDto.prototype, "id", void 0);
exports.DelDto = DelDto;

View File

@@ -0,0 +1,20 @@
"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.DelByGroupDto = void 0;
const swagger_1 = require("@nestjs/swagger");
class DelByGroupDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '对话组Id', required: true }),
__metadata("design:type", Number)
], DelByGroupDto.prototype, "groupId", void 0);
exports.DelByGroupDto = DelByGroupDto;

View File

@@ -0,0 +1,37 @@
"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.ExportExcelChatlogDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class ExportExcelChatlogDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], ExportExcelChatlogDto.prototype, "page", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], ExportExcelChatlogDto.prototype, "size", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: '您好', description: '用户询问的问题', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], ExportExcelChatlogDto.prototype, "prompt", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 'J_longyan@163.com', description: '用户邮箱', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], ExportExcelChatlogDto.prototype, "email", void 0);
exports.ExportExcelChatlogDto = ExportExcelChatlogDto;

View File

@@ -0,0 +1,41 @@
"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.QuerAllChatLogDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class QuerAllChatLogDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllChatLogDto.prototype, "page", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllChatLogDto.prototype, "size", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 99, description: '对话的用户id', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllChatLogDto.prototype, "userId", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: '您好', description: '用户询问的问题', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], QuerAllChatLogDto.prototype, "prompt", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 'user', description: '身份', required: false }),
__metadata("design:type", String)
], QuerAllChatLogDto.prototype, "role", void 0);
exports.QuerAllChatLogDto = QuerAllChatLogDto;

View File

@@ -0,0 +1,42 @@
"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.QuerAllDrawLogDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class QuerAllDrawLogDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllDrawLogDto.prototype, "page", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllDrawLogDto.prototype, "size", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '是否推荐0: 默认 1: 推荐', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllDrawLogDto.prototype, "rec", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 99, description: '生成图片的用户id', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QuerAllDrawLogDto.prototype, "userId", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 'DALL-E2', description: '生成图片使用的模型', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], QuerAllDrawLogDto.prototype, "model", void 0);
exports.QuerAllDrawLogDto = QuerAllDrawLogDto;

View File

@@ -0,0 +1,32 @@
"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.QueryByAppIdDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class QueryByAppIdDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '应用Id', required: true }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QueryByAppIdDto.prototype, "appId", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QueryByAppIdDto.prototype, "page", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], QueryByAppIdDto.prototype, "size", void 0);
exports.QueryByAppIdDto = QueryByAppIdDto;

View File

@@ -0,0 +1,22 @@
"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.QuerMyChatLogDto = void 0;
const class_validator_1 = require("class-validator");
const swagger_1 = require("@nestjs/swagger");
class QuerMyChatLogDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 'mj', description: '使用的模型', required: false }),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], QuerMyChatLogDto.prototype, "model", void 0);
exports.QuerMyChatLogDto = QuerMyChatLogDto;

View File

@@ -0,0 +1,20 @@
"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.recDrawImgDto = void 0;
const swagger_1 = require("@nestjs/swagger");
class recDrawImgDto {
}
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '推荐图片的id' }),
__metadata("design:type", Number)
], recDrawImgDto.prototype, "id", void 0);
exports.recDrawImgDto = recDrawImgDto;