mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-14 12:43:43 +08:00
v3.7.0
This commit is contained in:
16
dist/modules/autoreply/autoreply.controller.js
vendored
16
dist/modules/autoreply/autoreply.controller.js
vendored
@@ -13,15 +13,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoreplyController = void 0;
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const queryAutoReply_dto_1 = require("./dto/queryAutoReply.dto");
|
||||
const addAutoReply_dto_1 = require("./dto/addAutoReply.dto");
|
||||
const updateAutoReply_dto_1 = require("./dto/updateAutoReply.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
const addAutoReply_dto_1 = require("./dto/addAutoReply.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const queryAutoReply_dto_1 = require("./dto/queryAutoReply.dto");
|
||||
const updateAutoReply_dto_1 = require("./dto/updateAutoReply.dto");
|
||||
let AutoreplyController = class AutoreplyController {
|
||||
constructor(autoreplyService) {
|
||||
this.autoreplyService = autoreplyService;
|
||||
@@ -66,7 +66,7 @@ __decorate([
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateAutoReply_dto_1.UpdateAutpReplyDto]),
|
||||
__metadata("design:paramtypes", [updateAutoReply_dto_1.UpdateAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "updateAutoreply", null);
|
||||
__decorate([
|
||||
|
||||
@@ -10,8 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoReplyEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AutoReplyEntity = class AutoReplyEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
@@ -22,6 +22,10 @@ __decorate([
|
||||
(0, typeorm_1.Column)({ comment: '定义的答案', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AutoReplyEntity.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '是否开启AI回复,0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], AutoReplyEntity.prototype, "isAIReplyEnabled", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '启用当前自动回复状态, 0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
8
dist/modules/autoreply/autoreply.module.js
vendored
8
dist/modules/autoreply/autoreply.module.js
vendored
@@ -8,16 +8,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoreplyModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const autoreply_controller_1 = require("./autoreply.controller");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const autoreplay_entity_1 = require("./autoreplay.entity");
|
||||
const autoreply_controller_1 = require("./autoreply.controller");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
let AutoreplyModule = class AutoreplyModule {
|
||||
};
|
||||
AutoreplyModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([autoreplay_entity_1.AutoReplyEntity])],
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([autoreply_entity_1.AutoReplyEntity])],
|
||||
controllers: [autoreply_controller_1.AutoreplyController],
|
||||
providers: [autoreply_service_1.AutoreplyService],
|
||||
exports: [autoreply_service_1.AutoreplyService],
|
||||
|
||||
60
dist/modules/autoreply/autoreply.service.js
vendored
60
dist/modules/autoreply/autoreply.service.js
vendored
@@ -16,7 +16,7 @@ exports.AutoreplyService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const autoreplay_entity_1 = require("./autoreplay.entity");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
let AutoreplyService = class AutoreplyService {
|
||||
constructor(autoReplyEntity) {
|
||||
this.autoReplyEntity = autoReplyEntity;
|
||||
@@ -25,20 +25,57 @@ let AutoreplyService = class AutoreplyService {
|
||||
this.autoReplyFuzzyMatch = true;
|
||||
}
|
||||
async onModuleInit() {
|
||||
this.loadAutoReplyList();
|
||||
await this.loadAutoReplyList();
|
||||
}
|
||||
async loadAutoReplyList() {
|
||||
const res = await this.autoReplyEntity.find({ where: { status: 1 }, select: ['prompt', 'answer'] });
|
||||
const res = await this.autoReplyEntity.find({
|
||||
where: { status: 1 },
|
||||
select: ['prompt', 'answer', 'isAIReplyEnabled'],
|
||||
});
|
||||
this.autoReplyMap = {};
|
||||
res.forEach((t) => (this.autoReplyMap[t.prompt] = t.answer));
|
||||
this.autoReplyKes = Object.keys(this.autoReplyMap);
|
||||
this.autoReplyKes = [];
|
||||
res.forEach((t) => {
|
||||
this.autoReplyMap[t.prompt] = {
|
||||
answer: t.answer,
|
||||
isAIReplyEnabled: t.isAIReplyEnabled,
|
||||
};
|
||||
const keywords = t.prompt.split(' ').map((k) => k.trim());
|
||||
this.autoReplyKes.push({ prompt: t.prompt, keywords });
|
||||
});
|
||||
}
|
||||
async checkAutoReply(prompt) {
|
||||
let question = prompt;
|
||||
let answers = [];
|
||||
let isAIReplyEnabled = 0;
|
||||
const seenGroups = new Set();
|
||||
if (this.autoReplyFuzzyMatch) {
|
||||
question = this.autoReplyKes.find((item) => item.includes(prompt));
|
||||
for (const item of this.autoReplyKes) {
|
||||
if (item.keywords.some((keyword) => prompt.includes(keyword))) {
|
||||
if (!seenGroups.has(item.prompt)) {
|
||||
answers.push(this.autoReplyMap[item.prompt].answer);
|
||||
seenGroups.add(item.prompt);
|
||||
if (this.autoReplyMap[item.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return question ? this.autoReplyMap[question] : '';
|
||||
else {
|
||||
const matches = this.autoReplyKes.filter((item) => item.prompt === prompt);
|
||||
for (const match of matches) {
|
||||
if (!seenGroups.has(match.prompt)) {
|
||||
answers.push(this.autoReplyMap[match.prompt].answer);
|
||||
seenGroups.add(match.prompt);
|
||||
if (this.autoReplyMap[match.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
answer: answers.join('\n'),
|
||||
isAIReplyEnabled,
|
||||
};
|
||||
}
|
||||
async queryAutoreply(query) {
|
||||
const { page = 1, size = 10, prompt, status } = query;
|
||||
@@ -54,11 +91,6 @@ let AutoreplyService = class AutoreplyService {
|
||||
return { rows, count };
|
||||
}
|
||||
async addAutoreply(body) {
|
||||
const { prompt } = body;
|
||||
const a = await this.autoReplyEntity.findOne({ where: { prompt } });
|
||||
if (a) {
|
||||
throw new common_1.HttpException('该问题已存在,请检查您的提交信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.autoReplyEntity.save(body);
|
||||
await this.loadAutoReplyList();
|
||||
return '添加问题成功!';
|
||||
@@ -88,7 +120,7 @@ let AutoreplyService = class AutoreplyService {
|
||||
};
|
||||
AutoreplyService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(autoreplay_entity_1.AutoReplyEntity)),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(autoreply_entity_1.AutoReplyEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository])
|
||||
], AutoreplyService);
|
||||
exports.AutoreplyService = AutoreplyService;
|
||||
|
||||
@@ -9,29 +9,33 @@ 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.UpdateAutpReplyDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
exports.UpdateAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdateAutpReplyDto {
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdateAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '自动回复id', required: true }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutpReplyDto.prototype, "id", void 0);
|
||||
], UpdateAutoReplyDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你可以干嘛', description: '问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutpReplyDto.prototype, "prompt", void 0);
|
||||
], UpdateAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '我可以干很多事情.......', description: '答案', required: false }),
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我可以干很多事情.......',
|
||||
description: '答案',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutpReplyDto.prototype, "answer", void 0);
|
||||
], UpdateAutoReplyDto.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 0, description: '状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutpReplyDto.prototype, "status", void 0);
|
||||
exports.UpdateAutpReplyDto = UpdateAutpReplyDto;
|
||||
], UpdateAutoReplyDto.prototype, "status", void 0);
|
||||
exports.UpdateAutoReplyDto = UpdateAutoReplyDto;
|
||||
|
||||
Reference in New Issue
Block a user