This commit is contained in:
vastxie
2024-03-15 17:40:19 +08:00
parent 4de54d8fec
commit 19254a8176
305 changed files with 8751 additions and 9416 deletions

View File

@@ -22,17 +22,13 @@ __decorate([
__metadata("design:type", Number)
], SetModelDto.prototype, "keyType", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: '文心一言普通模型', description: '模型中文名称', required: true }),
(0, swagger_1.ApiProperty)({ example: '默认', description: '模型中文名称', required: true }),
__metadata("design:type", String)
], SetModelDto.prototype, "modelName", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 'dsadgadaorjoqm', description: '模型key', required: true }),
(0, swagger_1.ApiProperty)({ example: 'sk-', description: '模型key', required: false }),
__metadata("design:type", Object)
], SetModelDto.prototype, "key", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 'dasdasdk2n31323k', description: '模型秘钥', required: false }),
__metadata("design:type", String)
], SetModelDto.prototype, "secret", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '是否开启当前key对应的模型', required: true }),
__metadata("design:type", Boolean)
@@ -50,19 +46,19 @@ __decorate([
__metadata("design:type", Number)
], SetModelDto.prototype, "modelOrder", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 4096, description: '模型支持的最大TOken数量', required: true }),
(0, swagger_1.ApiProperty)({ example: 'https://***.png', required: false }),
__metadata("design:type", String)
], SetModelDto.prototype, "modelAvatar", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 4096, description: '模型支持的最大TOken数量', required: false }),
__metadata("design:type", Number)
], SetModelDto.prototype, "maxModelTokens", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 1000, description: '模型支持的最大回复TOken数量', required: true }),
__metadata("design:type", Number)
], SetModelDto.prototype, "maxResponseTokens", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '模型的代理地址', required: false }),
__metadata("design:type", String)
], SetModelDto.prototype, "proxyUrl", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '模型超时时间', required: false }),
(0, swagger_1.ApiProperty)({ example: 300, description: '模型超时时间', required: false }),
__metadata("design:type", Number)
], SetModelDto.prototype, "timeout", void 0);
__decorate([
@@ -85,6 +81,10 @@ __decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '是否设置为绘画Key', required: false }),
__metadata("design:type", Boolean)
], SetModelDto.prototype, "isDraw", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '是否支持文件上传', required: false }),
__metadata("design:type", Number)
], SetModelDto.prototype, "isFileUpload", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '是否使用token计费', required: false }),
__metadata("design:type", Boolean)

View File

@@ -22,7 +22,7 @@ __decorate([
__metadata("design:type", Number)
], SetModelTypeDto.prototype, "keyType", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: '文心一言普通模型', description: '模型中文名称', required: true }),
(0, swagger_1.ApiProperty)({ example: '普通模型', description: '模型中文名称', required: true }),
__metadata("design:type", String)
], SetModelTypeDto.prototype, "modelName", void 0);
__decorate([
@@ -34,13 +34,17 @@ __decorate([
__metadata("design:type", String)
], SetModelTypeDto.prototype, "model", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: 1, description: '温度' }),
(0, swagger_1.ApiProperty)({ example: 300, description: '模型超时时间', required: false }),
__metadata("design:type", Number)
], SetModelTypeDto.prototype, "temperature", void 0);
], SetModelTypeDto.prototype, "timeout", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '扣费类型 1 普通 2 高级余额', required: false }),
__metadata("design:type", Number)
], SetModelTypeDto.prototype, "deductType", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '文件上传类型 0 : 不使用 1: ALL类型 2: 4V类型', required: false }),
__metadata("design:type", Number)
], SetModelTypeDto.prototype, "isFileUpload", void 0);
__decorate([
(0, swagger_1.ApiProperty)({ example: true, description: '单次扣除金额', required: false }),
__metadata("design:type", Number)

View File

@@ -38,6 +38,9 @@ let ModelsController = class ModelsController {
modelsList() {
return this.modelsService.modelsList();
}
getMjInfo() {
return this.modelsService.getMjInfo();
}
baseConfig() {
return this.modelsService.getBaseConfig();
}
@@ -89,6 +92,13 @@ __decorate([
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ModelsController.prototype, "modelsList", null);
__decorate([
(0, common_1.Get)('mjInfo'),
(0, swagger_1.ApiOperation)({ summary: '客户端查询当前所有可以使用的模型' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ModelsController.prototype, "getMjInfo", null);
__decorate([
(0, common_1.Get)('baseConfig'),
(0, swagger_1.ApiOperation)({ summary: '客户端查询当前已经配置模型的基础配置' }),

View File

@@ -15,7 +15,7 @@ const baseEntity_1 = require("../../common/entity/baseEntity");
let ModelsEntity = class ModelsEntity extends baseEntity_1.BaseEntity {
};
__decorate([
(0, typeorm_1.Column)({ comment: 'key模型类型 1: openai 2: 文心一言 3:清华智谱' }),
(0, typeorm_1.Column)({ comment: '模型类型 1: 普通对话 2: 绘画 3:高级对话' }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "keyType", void 0);
__decorate([
@@ -23,37 +23,69 @@ __decorate([
__metadata("design:type", String)
], ModelsEntity.prototype, "modelName", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型的key' }),
(0, typeorm_1.Column)({ comment: '绑定的模型是?' }),
__metadata("design:type", String)
], ModelsEntity.prototype, "model", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型头像', nullable: true }),
__metadata("design:type", String)
], ModelsEntity.prototype, "modelAvatar", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型排序', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "modelOrder", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型上下文支持的最大Token', default: 2000, nullable: true }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "maxModelTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型上下文最大条数', nullable: true }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "maxRounds", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型上下文最大条数', nullable: true }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "timeout", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型单次调用扣除的次数', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "deduct", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型扣除余额类型 1: 普通模型 2: 高级模型', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "deductType", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否使用token计费: 0:不是 1: 是', default: 0 }),
__metadata("design:type", Boolean)
], ModelsEntity.prototype, "isTokenBased", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否支持文件上传: 0:不是 1: 附件链接格式 2: 4V格式', default: 0 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "isFileUpload", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'token计费比例', default: 0 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "tokenFeeRatio", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型附加信息', nullable: true }),
__metadata("design:type", String)
], ModelsEntity.prototype, "remark", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型的key', nullable: true }),
__metadata("design:type", String)
], ModelsEntity.prototype, "key", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型的secret', default: null }),
__metadata("design:type", String)
], ModelsEntity.prototype, "secret", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '部分模型的调用token', default: null }),
__metadata("design:type", String)
], ModelsEntity.prototype, "accessToken", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '使用的状态: 0:禁用 1启用', default: 1 }),
__metadata("design:type", Boolean)
], ModelsEntity.prototype, "status", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '绑定的模型是?' }),
__metadata("design:type", String)
], ModelsEntity.prototype, "model", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'key的状态: 1:有效 -1:被封号 -2: 错误的秘钥 -3: 余额使用完了', default: 1 }),
(0, typeorm_1.Column)({ comment: 'key的状态: 1:有效 -1:被封号 -2: 错误的秘钥 -3: 余额使用完了', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "keyStatus", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'key权重', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "keyWeight", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'key权重', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "modelOrder", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'key的使用次数', default: 0 }),
__metadata("design:type", Number)
@@ -62,50 +94,10 @@ __decorate([
(0, typeorm_1.Column)({ comment: 'key的已经使用的token数量', default: 0 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "useToken", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型支持的最大Token', default: 1000 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "maxModelTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '模型设置的最大回复Token', default: 4096 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "maxResponseTokens", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '当前模型的代理地址', nullable: true }),
__metadata("design:type", String)
], ModelsEntity.prototype, "proxyUrl", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '当前模型的超时时间单位s', default: 200 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "timeout", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '单次调用扣除的次数', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "deduct", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '扣除余额类型 1 普通模型 2高级模型', default: 1 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "deductType", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '备注信息', nullable: true }),
__metadata("design:type", String)
], ModelsEntity.prototype, "remark", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '限制用户上下文最大次数', nullable: true }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "maxRounds", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否是绘画key: 0:不是 1是', default: 0 }),
__metadata("design:type", Boolean)
], ModelsEntity.prototype, "isDraw", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: '是否使用token计费: 0:不是 1是', default: 0 }),
__metadata("design:type", Boolean)
], ModelsEntity.prototype, "isTokenBased", void 0);
__decorate([
(0, typeorm_1.Column)({ comment: 'token计费比例', default: 0 }),
__metadata("design:type", Number)
], ModelsEntity.prototype, "tokenFeeRatio", void 0);
ModelsEntity = __decorate([
(0, typeorm_1.Entity)({ name: 'models' })
], ModelsEntity);

View File

@@ -76,30 +76,41 @@ let ModelsService = class ModelsService {
this.initCalcKey();
}
async getCurrentModelKeyInfo(model) {
if (!this.keyPoolMap[model]) {
throw new common_1.HttpException('当前调用模型已经被移除、请重新选择模型!', common_1.HttpStatus.BAD_REQUEST);
const modelKeyInfo = await this.modelsEntity.findOne({ where: { model: model } });
if (!modelKeyInfo) {
throw new common_1.HttpException('当前调用模型的key未找到请重新选择模型', common_1.HttpStatus.BAD_REQUEST);
}
this.keyPoolIndexMap[model]++;
const index = this.keyPoolIndexMap[model];
if (index >= this.keyPoolMap[model].length)
this.keyPoolIndexMap[model] = 0;
const key = this.keyPoolMap[model][this.keyPoolIndexMap[model]];
return key;
return modelKeyInfo;
}
async getSpecialModelKeyInfo(modelPrefix) {
const matchingModels = await this.modelsEntity.find({
where: { model: (0, typeorm_2.Like)(`${modelPrefix}%`) }
});
if (matchingModels.length === 0) {
throw new common_1.HttpException('未找到匹配的模型,请重新选择模型!', common_1.HttpStatus.BAD_REQUEST);
}
const firstMatchModel = matchingModels[0];
const modifiedModelName = firstMatchModel.model.replace(modelPrefix, '');
const modifiedModel = Object.assign(Object.assign({}, firstMatchModel), { model: modifiedModelName });
return modifiedModel;
}
async getBaseConfig(appId) {
if (!this.modelTypes.length || !Object.keys(this.modelMaps).length)
return;
const modelTypeInfo = appId ? this.modelTypes.find(item => Number(item.val) === 1) : this.modelTypes[0];
const modelTypeInfo = this.modelTypes[0];
if (!modelTypeInfo)
return;
const { keyType, modelName, model, maxModelTokens, maxResponseTokens, deductType, deduct, maxRounds } = this.modelMaps[modelTypeInfo.val][0];
const { keyType, modelName, model, deductType, deduct, isFileUpload } = this.modelMaps[modelTypeInfo.val][0];
return {
modelTypeInfo,
modelInfo: { keyType, modelName, model, maxModelTokens, maxResponseTokens, topN: 0.8, systemMessage: '', deductType, deduct, maxRounds, rounds: 8 }
modelInfo: { keyType, modelName, model, deductType, deduct, isFileUpload }
};
}
async setModel(params) {
try {
if (isNaN(params.timeout)) {
params.timeout = null;
}
const { id } = params;
params.status && (params.keyStatus = 1);
if (id) {
@@ -119,6 +130,9 @@ let ModelsService = class ModelsService {
try {
const data = JSON.parse(JSON.stringify(params));
data.key = k;
if (isNaN(data.timeout)) {
data.timeout = null;
}
return data;
}
catch (error) {
@@ -166,7 +180,6 @@ let ModelsService = class ModelsService {
if (role !== 'super') {
rows.forEach(item => {
item.key && (item.key = (0, utils_1.hideString)(item.key));
item.secret && (item.secret = (0, utils_1.hideString)(item.secret));
});
}
return { rows, count };
@@ -177,8 +190,8 @@ let ModelsService = class ModelsService {
cloneModelMaps[key] = cloneModelMaps[key].sort((a, b) => a.modelOrder - b.modelOrder);
cloneModelMaps[key] = Array.from(cloneModelMaps[key]
.map(t => {
const { modelName, model, deduct, deductType, maxRounds } = t;
return { modelName, model, deduct, deductType, maxRounds };
const { modelName, keyType, model, deduct, deductType, maxRounds, modelAvatar, isFileUpload } = t;
return { modelName, keyType, model, deduct, deductType, maxRounds, modelAvatar, isFileUpload };
})
.reduce((map, obj) => map.set(obj.modelName, obj), new Map()).values());
});
@@ -187,6 +200,20 @@ let ModelsService = class ModelsService {
modelMaps: cloneModelMaps
};
}
async getMjInfo() {
const modelInfo = await this.modelsEntity.findOne({ where: { model: "midjourney" } });
if (modelInfo) {
return {
modelName: modelInfo.modelName,
model: modelInfo.model,
deduct: modelInfo.deduct,
deductType: modelInfo.deductType,
};
}
else {
return null;
}
}
async saveUseLog(id, useToken) {
await this.modelsEntity
.createQueryBuilder()
@@ -195,13 +222,6 @@ let ModelsService = class ModelsService {
.where('id = :id', { id })
.execute();
}
async getRandomDrawKey() {
const drawkeys = await this.modelsEntity.find({ where: { isDraw: true, status: true } });
if (!drawkeys.length) {
throw new common_1.HttpException('当前未指定特殊模型KEY、前往后台模型池设置吧', common_1.HttpStatus.BAD_REQUEST);
}
return (0, utils_1.getRandomItemFromArray)(drawkeys);
}
async getAllKey() {
return await this.modelsEntity.find();
}