mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-15 05:03:45 +08:00
v-3.0.0
This commit is contained in:
126
dist/modules/chatLog/chatLog.entity.js
vendored
126
dist/modules/chatLog/chatLog.entity.js
vendored
@@ -19,97 +19,101 @@ __decorate([
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '使用类型', nullable: true }),
|
||||
(0, typeorm_1.Column)({ comment: '使用的模型', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "model", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '使用类型1: 普通对话 2: 绘图 3: 拓展性对话', nullable: true, default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "type", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '自定义的模型名称', nullable: true, default: 'AI' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "modelName", 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: '询问的问题', type: 'text', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '附加参数', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "extraParam", 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 }),
|
||||
(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 }),
|
||||
(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 }),
|
||||
(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 }),
|
||||
(0, typeorm_1.Column)({ comment: '当前绘制任务的进度', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "progress", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '当前绘制任务的耗时', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "durationSpent", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '当前绘制任务的状态', nullable: true, default: 3 }),
|
||||
__metadata("design:type", Number)
|
||||
], ChatLogEntity.prototype, "status", 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: '对图片操作的按钮ID', type: 'text', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "customId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '绘画的ID每条不一样', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "drawId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '图片比例', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "drawRatio", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '对话或绘图附带的链接', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "fileInfo", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '对话转语音的链接', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], ChatLogEntity.prototype, "ttsUrl", 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: '分组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);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否删除', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], ChatLogEntity.prototype, "isDelete", void 0);
|
||||
ChatLogEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'chatlog' })
|
||||
], ChatLogEntity);
|
||||
|
||||
63
dist/modules/chatLog/chatLog.service.js
vendored
63
dist/modules/chatLog/chatLog.service.js
vendored
@@ -29,12 +29,19 @@ let ChatLogService = class ChatLogService {
|
||||
this.chatGroupEntity = chatGroupEntity;
|
||||
}
|
||||
async saveChatLog(logInfo) {
|
||||
return await this.chatLogEntity.save(logInfo);
|
||||
const savedLog = await this.chatLogEntity.save(logInfo);
|
||||
return savedLog;
|
||||
}
|
||||
async updateChatLog(id, logInfo) {
|
||||
return await this.chatLogEntity.update({ id }, logInfo);
|
||||
}
|
||||
async findOneChatLog(id) {
|
||||
return await this.chatLogEntity.findOne({ where: { id } });
|
||||
}
|
||||
async querDrawLog(req, query) {
|
||||
const { id } = req.user;
|
||||
const { model } = query;
|
||||
const where = { userId: id, type: balance_constant_1.DeductionKey.PAINT_TYPE };
|
||||
const where = { userId: id, type: balance_constant_1.ChatType.PAINT };
|
||||
if (model) {
|
||||
where.model = model;
|
||||
if (model === 'DALL-E2') {
|
||||
@@ -44,7 +51,7 @@ let ChatLogService = class ChatLogService {
|
||||
const data = await this.chatLogEntity.find({
|
||||
where,
|
||||
order: { id: 'DESC' },
|
||||
select: ['id', 'answer', 'prompt', 'message_id', 'group', 'model', 'extend', 'type', 'fileInfo'],
|
||||
select: ['id', 'answer', 'prompt', 'model', 'type', 'fileInfo'],
|
||||
});
|
||||
data.forEach((r) => {
|
||||
if (r.type === 'paintCount') {
|
||||
@@ -64,7 +71,7 @@ let ChatLogService = class ChatLogService {
|
||||
}
|
||||
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)('') };
|
||||
const where = { type: balance_constant_1.ChatType.PAINT, prompt: (0, typeorm_2.Not)(''), answer: (0, typeorm_2.Not)('') };
|
||||
rec && Object.assign(where, { rec });
|
||||
userId && Object.assign(where, { userId });
|
||||
if (model) {
|
||||
@@ -104,9 +111,14 @@ let ChatLogService = class ChatLogService {
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async findOneDrawLog(params) {
|
||||
const { id } = params;
|
||||
const record = await this.chatLogEntity.findOne({ where: { id } });
|
||||
return record;
|
||||
}
|
||||
async recDrawImg(body) {
|
||||
const { id } = body;
|
||||
const l = await this.chatLogEntity.findOne({ where: { id, type: balance_constant_1.DeductionKey.PAINT_TYPE } });
|
||||
const l = await this.chatLogEntity.findOne({ where: { id, type: balance_constant_1.ChatType.PAINT } });
|
||||
if (!l) {
|
||||
throw new common_1.HttpException('你推荐的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -118,7 +130,7 @@ let ChatLogService = class ChatLogService {
|
||||
throw new common_1.HttpException('你操作的图片不存在、请检查!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async exportExcel(body, res) {
|
||||
const where = { type: balance_constant_1.DeductionKey.CHAT_TYPE };
|
||||
const where = { type: balance_constant_1.ChatType.NORMAL_CHAT };
|
||||
const { page = 1, size = 30, prompt, email } = body;
|
||||
prompt && Object.assign(where, { prompt: (0, typeorm_2.Like)(`%${prompt}%`) });
|
||||
if (email) {
|
||||
@@ -160,7 +172,7 @@ let ChatLogService = class ChatLogService {
|
||||
}
|
||||
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)('') };
|
||||
const where = { type: balance_constant_1.ChatType.NORMAL_CHAT, 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({
|
||||
@@ -195,25 +207,40 @@ let ChatLogService = class ChatLogService {
|
||||
}
|
||||
const list = await this.chatLogEntity.find({ where });
|
||||
return list.map((item) => {
|
||||
const { prompt, role, answer, createdAt, model, conversationOptions, requestOptions, id, fileInfo } = item;
|
||||
let parseConversationOptions = null;
|
||||
let parseRequestOptions = null;
|
||||
try {
|
||||
parseConversationOptions = JSON.parse(conversationOptions);
|
||||
parseRequestOptions = JSON.parse(requestOptions);
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
const { prompt, role, answer, createdAt, model, modelName, type, status, action, drawId, id, fileInfo, ttsUrl, customId } = item;
|
||||
return {
|
||||
chatId: id,
|
||||
dateTime: (0, utils_1.formatDate)(createdAt),
|
||||
text: role === 'user' ? prompt : answer,
|
||||
modelType: type,
|
||||
status: status,
|
||||
action: action,
|
||||
drawId: drawId,
|
||||
customId: customId,
|
||||
inversion: role === 'user',
|
||||
error: false,
|
||||
conversationOptions: parseConversationOptions,
|
||||
requestOptions: parseRequestOptions,
|
||||
fileInfo: fileInfo,
|
||||
ttsUrl: ttsUrl,
|
||||
model: model,
|
||||
modelName: modelName,
|
||||
};
|
||||
});
|
||||
}
|
||||
async chatHistory(groupId, rounds) {
|
||||
const where = { isDelete: false, groupId: groupId };
|
||||
const list = await this.chatLogEntity.find({
|
||||
where,
|
||||
order: {
|
||||
createdAt: 'ASC'
|
||||
},
|
||||
take: rounds * 2
|
||||
});
|
||||
return list.map((item) => {
|
||||
const { role, prompt, answer, fileInfo } = item;
|
||||
return {
|
||||
role: role,
|
||||
text: role === 'user' ? prompt : answer,
|
||||
fileInfo: fileInfo,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user