YiAi/YiAiQuickDeploy/dist/modules/models/models.service.js

1 line
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';const _0x104e29=_0x5a93;(function(_0x4cac91,_0x12122e){const _0x32fcaa=_0x5a93,_0x2cc332=_0x4cac91();while(!![]){try{const _0x4bd457=parseInt(_0x32fcaa(0x23a))/0x1*(parseInt(_0x32fcaa(0x21c))/0x2)+parseInt(_0x32fcaa(0x1e9))/0x3+-parseInt(_0x32fcaa(0x1e2))/0x4*(-parseInt(_0x32fcaa(0x204))/0x5)+parseInt(_0x32fcaa(0x229))/0x6+parseInt(_0x32fcaa(0x237))/0x7*(-parseInt(_0x32fcaa(0x1f4))/0x8)+parseInt(_0x32fcaa(0x231))/0x9*(-parseInt(_0x32fcaa(0x1ef))/0xa)+-parseInt(_0x32fcaa(0x1ee))/0xb*(parseInt(_0x32fcaa(0x213))/0xc);if(_0x4bd457===_0x12122e)break;else _0x2cc332['push'](_0x2cc332['shift']());}catch(_0x4a0a0c){_0x2cc332['push'](_0x2cc332['shift']());}}}(_0x3aad,0xe6200));var __decorate=this&&this[_0x104e29(0x23b)]||function(_0x61f98b,_0x1a0972,_0x3f5d0b,_0x32fc54){const _0x22984b=_0x104e29;var _0x3b2010=arguments[_0x22984b(0x1e0)],_0x5d34c9=_0x3b2010<0x3?_0x1a0972:_0x32fc54===null?_0x32fc54=Object[_0x22984b(0x211)](_0x1a0972,_0x3f5d0b):_0x32fc54,_0x4ffae9;if(typeof Reflect===_0x22984b(0x1de)&&typeof Reflect['decorate']===_0x22984b(0x1e5))_0x5d34c9=Reflect[_0x22984b(0x1e8)](_0x61f98b,_0x1a0972,_0x3f5d0b,_0x32fc54);else{for(var _0x56d395=_0x61f98b[_0x22984b(0x1e0)]-0x1;_0x56d395>=0x0;_0x56d395--)if(_0x4ffae9=_0x61f98b[_0x56d395])_0x5d34c9=(_0x3b2010<0x3?_0x4ffae9(_0x5d34c9):_0x3b2010>0x3?_0x4ffae9(_0x1a0972,_0x3f5d0b,_0x5d34c9):_0x4ffae9(_0x1a0972,_0x3f5d0b))||_0x5d34c9;}return _0x3b2010>0x3&&_0x5d34c9&&Object[_0x22984b(0x1f6)](_0x1a0972,_0x3f5d0b,_0x5d34c9),_0x5d34c9;},__metadata=this&&this[_0x104e29(0x205)]||function(_0x55cc66,_0x10e5ed){const _0x3e2dd2=_0x104e29;if(typeof Reflect==='object'&&typeof Reflect['metadata']===_0x3e2dd2(0x1e5))return Reflect['metadata'](_0x55cc66,_0x10e5ed);},__param=this&&this[_0x104e29(0x20d)]||function(_0x1f419,_0x38ac9f){return function(_0x730ff2,_0x4b4729){_0x38ac9f(_0x730ff2,_0x4b4729,_0x1f419);};};function _0x5a93(_0x58a5bf,_0x595ddd){const _0x3aad61=_0x3aad();return _0x5a93=function(_0x5a93b0,_0x9ee87d){_0x5a93b0=_0x5a93b0-0x1da;let _0x1dd3fa=_0x3aad61[_0x5a93b0];return _0x1dd3fa;},_0x5a93(_0x58a5bf,_0x595ddd);}function _0x3aad(){const _0x4889bf=['./models.entity','initCalcKey','9398514YBfpXE','BAD_REQUEST','hideString','delModel','modelName','val','当前调用模型已经被移除、请重新选择模型!','delModelType','99xBqpfK','modelTypes','getBaseConfig','onModuleInit','secret','Repository','1523046lUEgET','createQueryBuilder','reduce','278yaXGHW','__decorate','queryModels','../../common/constants/status.constant','\x20欠费或被官方封禁导致不可用已被系统自动锁定','execute','__esModule','ModelsTypeEntity','keyStatus','object','modelMaps','length','findOne','156EsQKEv','Logger','setModelType','function','update','modelsTypeEntity','decorate','899064MfRhLk','error','parse','getAllKey','useCount\x20+\x201','17197741OyRRkG','133670OEFIvU','HttpException','keyPoolMap','stringify','user','16VmmyId','../../common/utils','defineProperty','InjectRepository','key','Like','super','keyList','queryModelType','map','save','model','modelsEntity','keyPoolIndexMap','keyType','find','110775VJxoou','__metadata','sort','Injectable','./modelType.entity','typeorm','parse\x20error:\x20','useToken\x20+\x20','design:paramtypes','__param','delete','modelsList','getRandomItemFromArray','getOwnPropertyDescriptor','findAndCount','12qicbrW','log','HttpStatus','status','当前账号不存在!','key:\x20','lockKey','keys','getRandomDrawKey','2576yauotX','values','forEach','setModel','modelOrder','where','error:\x20','push','set','ModelsService','缺失必要参数!'];_0x3aad=function(){return _0x4889bf;};return _0x3aad();}Object[_0x104e29(0x1f6)](exports,_0x104e29(0x1db),{'value':!![]}),exports[_0x104e29(0x225)]=void 0x0;const common_1=require('@nestjs/common'),typeorm_1=require('@nestjs/typeorm'),typeorm_2=require(_0x104e29(0x209)),models_entity_1=require(_0x104e29(0x227)),status_constant_1=require(_0x104e29(0x23d)),utils_1=require(_0x104e29(0x1f5)),modelType_entity_1=require(_0x104e29(0x208));let ModelsService=class ModelsService{constructor(_0x3f9fee,_0x569a10){const _0x28b447=_0x104e29;this[_0x28b447(0x200)]=_0x3f9fee,this[_0x28b447(0x1e7)]=_0x569a10,this[_0x28b447(0x232)]=[],this['modelMaps']={},this[_0x28b447(0x1fb)]={},this[_0x28b447(0x1f1)]={},this[_0x28b447(0x201)]={};}async[_0x104e29(0x234)](){const _0x46de65=_0x104e29;await this[_0x46de65(0x228)]();}async['initCalcKey'](){const _0x1c7674=_0x104e29;this[_0x1c7674(0x1f1)]={},this[_0x1c7674(0x201)]={},this['keyList']={},this[_0x1c7674(0x1df)]={},this[_0x1c7674(0x232)]=[];const _0xcb5492=await this[_0x1c7674(0x200)][_0x1c7674(0x203)]({'where':{'status':!![]}}),_0x2bb6de=_0xcb5492['reduce']((_0x4499c1,_0xad996b)=>{const _0x22ac1c=_0x1c7674;return!_0x4499c1[_0xad996b[_0x22ac1c(0x202)]]?_0x4499c1[_0xad996b[_0x22ac1c(0x202)]]=[_0xad996b]:_0x4499c1[_0xad996b[_0x22ac1c(0x202)]][_0x22ac1c(0x223)](_0xad996b),_0x4499c1;},{});this['modelTypes']=Object['keys'](_0x2bb6de)[_0x1c7674(0x1fd)](_0x1382f0=>{return{'label':status_constant_1['ModelsMapCn'][_0x1382f0],'val':_0x1382f0};}),this[_0x1c7674(0x1df)]=_0x2bb6de,this[_0x1c7674(0x1fb)]={},_0xcb5492[_0x1c7674(0x21e)](_0x2b7f0c=>{const _0x5739ac=_0x1c7674,{keyType:_0x50e711,model:_0x3e2ef8,keyWeight:_0x28bcc7}=_0x2b7f0c;if(!this[_0x5739ac(0x1f1)][_0x3e2ef8])this[_0x5739ac(0x1f1)][_0x3e2ef8]=[];for(let _0x9e14ed=0x0;_0x9e14ed<_0x28bcc7;_0x9e14ed++){this['keyPoolMap'][_0x3e2ef8][_0x5739ac(0x223)](_0x2b7f0c);}if(!this[_0x5739ac(0x201)][_0x3e2ef8])this[_0x5739ac(0x201)][_0x3e2ef8]=0x0;if(!this[_0x5739ac(0x1fb)][_0x50e711])this[_0x5739ac(0x1fb)][_0x50e711]={};if(!this[_0x5739ac(0x1fb)][_0x50e711][_0x3e2ef8])this[_0x5739ac(0x1fb)][_0x50e711][_0x3e2ef8]=[];this[_0x5739ac(0x1fb)][_0x50e711][_0x3e2ef8]['push'](_0x2b7f0c);});}async[_0x104e29(0x219)](_0x3343e0,_0x224bc5,_0x3786d0=-0x1){const _0x18cc28=_0x104e29,_0x1be9a0=await this[_0x18cc28(0x200)][_0x18cc28(0x1e6)]({'id':_0x3343e0},{'status':![],'keyStatus':_0x3786d0,'remark':_0x224bc5});common_1[_0x18cc28(0x1e3)][_0x18cc28(0x1ea)](_0x18cc28(0x218)+_0x3343e0+_0x18cc28(0x23e)),this[_0x18cc28(0x228)]();}async['getCurrentModelKeyInfo'](_0xeb33f0){const _0x4300c4=_0x104e29;if(!this[_0x4300c4(0x1f1)][_0xeb33f0])throw new common_1[(_0x4300c4(0x1f0))](_0x4300c4(0x22f),common_1[_0x4300c4(0x215)][_0x4300c4(0x22a)]);this[_0x4300c4(0x201)][_0xeb33f0]++;const _0x571500=this[_0x4300c4(0x201)][_0xeb33f0];if(_0x571500>=this[_0x4300c4(0x1f1)][_0xeb33f0][_0x4300c4(0x1e0)])this[_0x4300c4(0x201)][_0xeb33f0]=0x0;const _0x3b8749=this['keyPoolMap'][_0xeb33f0][this[_0x4300c4(0x201)][_0xeb33f0]];return _0x3b8749;}async[_0x104e29(0x233)](_0xeba4ad){const _0x5ae277=_0x104e29;if(!this[_0x5ae277(0x232)][_0x5ae277(0x1e0)]||!Object['keys'](this[_0x5ae277(0x1df)])['length'])return;const _0x1c73a5=_0xeba4ad?this['modelTypes']['find'](_0x1cb4dc=>Number(_0x1cb4dc[_0x5ae277(0x22e)])===0x1):this[_0x5ae277(0x232)][0x0];if(!_0x1c73a5)return;const {keyType:_0x368051,modelName:_0x20434f,model:_0x542788,maxModelTokens:_0x1dfb94,maxResponseTokens:_0xed1e5d,deductType:_0xf28b79,deduct:_0x38277e,maxRounds:_0x518b24}=this[_0x5ae277(0x1df)][_0x1c73a5['val']][0x0];return{'modelTypeInfo':_0x1c73a5,'modelInfo':{'keyType':_0x368051,'modelName':_0x20434f,'model':_0x542788,'maxModelTokens':_0x1dfb94,'maxResponseTokens':_0xed1e5d,'topN':0.8,'systemMessage':'','deductType':_0xf28b79,'deduct':_0x38277e,'maxRounds':_0x518b24,'rounds':0x8}};}async[_0x104e29(0x21f)](_0x35a28c){const _0x3a30ff=_0x104e29;try{const {id:_0x22ecc3}=_0x35a28c;_0x35a28c[_0x3a30ff(0x216)]&&(_0x35a28c[_0x3a30ff(0x1dd)]=0x1);if(_0x22ecc3){const _0x5af9a5=await this[_0x3a30ff(0x200)]['update']({'id':_0x22ecc3},_0x35a28c);return await this[_0x3a30ff(0x228)](),_0x5af9a5['affected']>0x0;}else{const {keyType:_0x1e0aeb,key:_0x1b6f9b}=_0x35a28c;if(Number(_0x1e0aeb!==0x1)){const _0x4ddf0a=await this[_0x3a30ff(0x200)][_0x3a30ff(0x1fe)](_0x35a28c);return await this[_0x3a30ff(0x228)](),_0x4ddf0a;}else{const _0x33663b=_0x1b6f9b[_0x3a30ff(0x1fd)](_0x6d4336=>{const _0x25d7d0=_0x3a30ff;try{const _0x3f58b1=JSON[_0x25d7d0(0x1eb)](JSON['stringify'](_0x35a28c));return _0x3f58b1[_0x25d7d0(0x1f8)]=_0x6d4336,_0x3f58b1;}catch(_0x4bee91){console[_0x25d7d0(0x214)](_0x25d7d0(0x20a),_0x4bee91);}}),_0x54ada5=await this[_0x3a30ff(0x200)][_0x3a30ff(0x1fe)](_0x33663b);return await this[_0x3a30ff(0x228)](),_0x54ada5;}}}catch(_0x60c0c4){console['log'](_0x3a30ff(0x222),_0x60c0c4);}}async[_0x104e29(0x22c)]({id:_0x23bee2}){const _0x4ae677=_0x104e29;if(!_0x23bee2)throw new common_1[(_0x4ae677(0x1f0))](_0x4ae677(0x226),common_1['HttpStatus']['BAD_REQUEST']);const _0x25e6e1=await this[_0x4ae677(0x200)][_0x4ae677(0x1e1)]({'where':{'id':_0x23bee2}});if(!_0x25e6e1)throw new common_1[(_0x4ae677(0x1f0))](_0x4ae677(0x217),common_1[_0x4ae677(0x215)]['BAD_REQUEST']);const _0x48b5f6=await this[_0x4ae677(0x200)][_0x4ae677(0x20e)]({'id':_0x23bee2});return await this[_0x4ae677(0x228)](),_0x48b5f6;}async[_0x104e29(0x23c)](_0x168710,_0x3b4fe3){const _0x5afba2=_0x104e29,{role:_0x29c47d}=_0x168710[_0x5afba2(0x1f3)],{keyType:_0xc9c3a8,key:_0x2a2ce4,status:_0x21e4b4,model:_0x37bd88,page:page=0x1,size:size=0xa}=_0x3b4fe3;let _0x1ed61f={};_0xc9c3a8&&(_0x1ed61f[_0x5afba2(0x202)]=_0xc9c3a8),_0x37bd88&&(_0x1ed61f[_0x5afba2(0x1ff)]=_0x37bd88),_0x21e4b4&&(_0x1ed61f['status']=Number(_0x21e4b4)===0x1?!![]:![]),_0x2a2ce4&&(_0x1ed61f[_0x5afba2(0x1f8)]=(0x0,typeorm_2[_0x5afba2(0x1f9)])('%'+_0x2a2ce4+'%'));const [_0x49604f,_0x59a1f3]=await this[_0x5afba2(0x200)][_0x5afba2(0x212)]({'where':_0x1ed61f,'order':{'modelOrder':'ASC'},'skip':(page-0x1)*size,'take':size});return _0x29c47d!==_0x5afba2(0x1fa)&&_0x49604f[_0x5afba2(0x21e)](_0x3850d6=>{const _0x2b10a0=_0x5afba2;_0x3850d6[_0x2b10a0(0x1f8)]&&(_0x3850d6['key']=(0x0,utils_1[_0x2b10a0(0x22b)])(_0x3850d6[_0x2b10a0(0x1f8)])),_0x3850d6['secret']&&(_0x3850d6['secret']=(0x0,utils_1['hideString'])(_0x3850d6[_0x2b10a0(0x235)]));}),{'rows':_0x49604f,'count':_0x59a1f3};}async[_0x104e29(0x20f)](){const _0x367032=_0x104e29,_0x255d2b=JSON[_0x367032(0x1eb)](JSON[_0x367032(0x1f2)](this[_0x367032(0x1df)]));return Object[_0x367032(0x21a)](_0x255d2b)[_0x367032(0x21e)](_0xf8cf7b=>{const _0x2eda41=_0x367032;_0x255d2b[_0xf8cf7b]=_0x255d2b[_0xf8cf7b][_0x2eda41(0x206)]((_0x47b128,_0x3a0f35)=>_0x47b128[_0x2eda41(0x220)]-_0x3a0f35[_0x2eda41(0x220)]),_0x255d2b[_0xf8cf7b]=Array['from'](_0x255d2b[_0xf8cf7b][_0x2eda41(0x1fd)](_0x2fe8c7=>{const {modelName:_0x24960a,model:_0x1aba04,deduct:_0x51d526,deductType:_0x5670fa,maxRounds:_0x212b7f}=_0x2fe8c7;return{'modelName':_0x24960a,'model':_0x1aba04,'deduct':_0x51d526,'deductType':_0x5670fa,'maxRounds':_0x212b7f};})[_0x2eda41(0x239)]((_0x3ffbee,_0x580f73)=>_0x3ffbee[_0x2eda41(0x224)](_0x580f73[_0x2eda41(0x22d)],_0x580f73),new Map())[_0x2eda41(0x21d)]());}),{'modelTypeList':this[_0x367032(0x232)],'modelMaps':_0x255d2b};}async['saveUseLog'](_0x4f9bde,_0x1dd686){const _0x13c8b8=_0x104e29;await this[_0x13c8b8(0x200)][_0x13c8b8(0x238)]()[_0x13c8b8(0x1e6)](models_entity_1['ModelsEntity'])['set']({'useCount':()=>_0x13c8b8(0x1ed),'useToken':()=>_0x13c8b8(0x20b)+_0x1dd686})[_0x13c8b8(0x221)]('id\x20=\x20:id',{'id':_0x4f9bde})[_0x13c8b8(0x1da)]();}async[_0x104e29(0x21b)](){const _0x1a8184=_0x104e29,_0xd5dde8=await this['modelsEntity']['find']({'where':{'isDraw':!![],'status':!![]}});if(!_0xd5dde8[_0x1a8184(0x1e0)])throw new common_1[(_0x1a8184(0x1f0))]('当前未指定特殊模型KEY、前往后台模型池设置吧',common_1['HttpStatus'][_0x1a8184(0x22a)]);return(0x0,utils_1[_0x1a8184(0x210)])(_0xd5dde8);}async[_0x104e29(0x1ec)](){const _0xafa098=_0x104e29;return await this['modelsEntity'][_0xafa098(0x203)]();}async[_0x104e29(0x1fc)](_0x1dee09){return 0x1;}async[_0x104e29(0x1e4)](_0xbf452){return 0x1;}async[_0x104e29(0x230)](_0x3bd547){return 0x1;}};ModelsService=__decorate([(0x0,common_1[_0x104e29(0x207)])(),__param(0x0,(0x0,typeorm_1['InjectRepository'])(models_entity_1['ModelsEntity'])),__param(0x1,(0x0,typeorm_1[_0x104e29(0x1f7)])(modelType_entity_1[_0x104e29(0x1dc)])),__metadata(_0x104e29(0x20c),[typeorm_2['Repository'],typeorm_2[_0x104e29(0x236)]])],ModelsService),exports[_0x104e29(0x225)]=ModelsService;