This commit is contained in:
vastxie
2024-04-20 22:15:08 +08:00
parent 133b89076e
commit 1c9e023c08
221 changed files with 6107 additions and 6478 deletions

View File

@@ -14,11 +14,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatGroupService = void 0;
const common_1 = require("@nestjs/common");
const chatGroup_entity_1 = require("./chatGroup.entity");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const app_entity_1 = require("../app/app.entity");
const models_service_1 = require("../models/models.service");
const chatGroup_entity_1 = require("./chatGroup.entity");
let ChatGroupService = class ChatGroupService {
constructor(chatGroupEntity, appEntity, modelsService) {
this.chatGroupEntity = chatGroupEntity;
@@ -28,32 +28,39 @@ let ChatGroupService = class ChatGroupService {
async create(body, req) {
const { id } = req.user;
const { appId, modelConfig: bodyModelConfig } = body;
let modelConfig = bodyModelConfig;
let modelConfig = bodyModelConfig || await this.modelsService.getBaseConfig(appId);
if (!modelConfig) {
modelConfig = await this.modelsService.getBaseConfig(appId);
if (!modelConfig) {
throw new common_1.HttpException('管理员未配置任何AI模型、请先联系管理员开通聊天模型配置', common_1.HttpStatus.BAD_REQUEST);
}
throw new common_1.HttpException('管理员未配置任何AI模型、请先联系管理员开通聊天模型配置', common_1.HttpStatus.BAD_REQUEST);
}
const params = { title: '新对话', userId: id };
modelConfig = JSON.parse(JSON.stringify(modelConfig));
const params = { title: '新对话', userId: id, appId };
if (appId) {
const appInfo = await this.appEntity.findOne({ where: { id: appId } });
if (!appInfo) {
throw new common_1.HttpException('非法操作、您在使用一个不存在的应用!', common_1.HttpStatus.BAD_REQUEST);
}
const { status, name } = appInfo;
const existingGroupCount = await this.chatGroupEntity.count({ where: { userId: id, appId, isDelete: false } });
if (existingGroupCount > 0) {
throw new common_1.HttpException('当前应用已经开启了一个对话无需新建了!', common_1.HttpStatus.BAD_REQUEST);
const { status, name, isFixedModel, isGPTs, appModel, coverImg } = appInfo;
Object.assign(modelConfig.modelInfo, {
isGPTs,
isFixedModel,
modelAvatar: coverImg,
modelName: name
});
if (isGPTs === 1 || isFixedModel === 1) {
const appModelKey = await this.modelsService.getCurrentModelKeyInfo(isFixedModel === 1 ? appModel : 'gpts');
Object.assign(modelConfig.modelInfo, {
deductType: appModelKey.deductType,
deduct: appModelKey.deduct,
model: appModel,
isFileUpload: appModelKey.isFileUpload
});
}
if (![1, 3, 4, 5].includes(status)) {
throw new common_1.HttpException('非法操作、您在使用一个未启用的应用!', common_1.HttpStatus.BAD_REQUEST);
}
if (name) {
params['title'] = name;
params.title = name;
}
params['appId'] = appId;
modelConfig.appId = appId;
}
const newGroup = await this.chatGroupEntity.save(Object.assign(Object.assign({}, params), { config: JSON.stringify(modelConfig) }));
return newGroup;
@@ -62,7 +69,8 @@ let ChatGroupService = class ChatGroupService {
try {
const { id } = req.user;
const params = { userId: id, isDelete: false };
const res = await this.chatGroupEntity.find({ where: params, order: { isSticky: 'DESC', id: 'DESC' } });
const res = await this.chatGroupEntity.find({ where: params, order: { isSticky: 'DESC', updatedAt: 'DESC' } });
return res;
const appIds = res.filter(t => t.appId).map(t => t.appId);
const appInfos = await this.appEntity.find({ where: { id: (0, typeorm_2.In)(appIds) } });
return res.map((item) => {
@@ -105,6 +113,11 @@ let ChatGroupService = class ChatGroupService {
throw new common_1.HttpException('更新对话失败!', common_1.HttpStatus.BAD_REQUEST);
}
}
async updateTime(groupId) {
await this.chatGroupEntity.update(groupId, {
updatedAt: new Date()
});
}
async del(body, req) {
const { groupId } = body;
const { id } = req.user;