YiAi/YiAiQuickDeploy/dist/modules/models/models.service.js
2024-02-06 13:43:30 +08:00

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 _0x4326b4=_0x20a2;(function(_0x842c84,_0x5ef51c){const _0x201cc6=_0x20a2,_0x99e8d=_0x842c84();while(!![]){try{const _0x142cec=parseInt(_0x201cc6(0x1e3))/0x1*(-parseInt(_0x201cc6(0x1f7))/0x2)+-parseInt(_0x201cc6(0x1de))/0x3*(-parseInt(_0x201cc6(0x1d3))/0x4)+-parseInt(_0x201cc6(0x1fa))/0x5+parseInt(_0x201cc6(0x1a5))/0x6+parseInt(_0x201cc6(0x1b8))/0x7*(parseInt(_0x201cc6(0x1d6))/0x8)+-parseInt(_0x201cc6(0x1df))/0x9*(-parseInt(_0x201cc6(0x1e5))/0xa)+-parseInt(_0x201cc6(0x1d8))/0xb*(parseInt(_0x201cc6(0x1cd))/0xc);if(_0x142cec===_0x5ef51c)break;else _0x99e8d['push'](_0x99e8d['shift']());}catch(_0x410d40){_0x99e8d['push'](_0x99e8d['shift']());}}}(_0x37a2,0xf1260));function _0x20a2(_0x1eca6e,_0x3bc100){const _0x37a234=_0x37a2();return _0x20a2=function(_0x20a25c,_0x23095c){_0x20a25c=_0x20a25c-0x19e;let _0x5104ce=_0x37a234[_0x20a25c];return _0x5104ce;},_0x20a2(_0x1eca6e,_0x3bc100);}var __decorate=this&&this['__decorate']||function(_0x1c5f17,_0x3cef65,_0x567654,_0x2cbf7d){const _0x2f4975=_0x20a2;var _0x1d6cc9=arguments[_0x2f4975(0x1f9)],_0x4edd36=_0x1d6cc9<0x3?_0x3cef65:_0x2cbf7d===null?_0x2cbf7d=Object[_0x2f4975(0x1a6)](_0x3cef65,_0x567654):_0x2cbf7d,_0x15ae9f;if(typeof Reflect===_0x2f4975(0x1fb)&&typeof Reflect[_0x2f4975(0x1bc)]===_0x2f4975(0x1a8))_0x4edd36=Reflect[_0x2f4975(0x1bc)](_0x1c5f17,_0x3cef65,_0x567654,_0x2cbf7d);else{for(var _0x1ead90=_0x1c5f17['length']-0x1;_0x1ead90>=0x0;_0x1ead90--)if(_0x15ae9f=_0x1c5f17[_0x1ead90])_0x4edd36=(_0x1d6cc9<0x3?_0x15ae9f(_0x4edd36):_0x1d6cc9>0x3?_0x15ae9f(_0x3cef65,_0x567654,_0x4edd36):_0x15ae9f(_0x3cef65,_0x567654))||_0x4edd36;}return _0x1d6cc9>0x3&&_0x4edd36&&Object['defineProperty'](_0x3cef65,_0x567654,_0x4edd36),_0x4edd36;},__metadata=this&&this[_0x4326b4(0x1da)]||function(_0x158566,_0xe1739){const _0x26ac84=_0x4326b4;if(typeof Reflect===_0x26ac84(0x1fb)&&typeof Reflect[_0x26ac84(0x1e0)]===_0x26ac84(0x1a8))return Reflect[_0x26ac84(0x1e0)](_0x158566,_0xe1739);},__param=this&&this['__param']||function(_0x2b8c13,_0x1e7df5){return function(_0xa714e3,_0x25e2dc){_0x1e7df5(_0xa714e3,_0x25e2dc,_0x2b8c13);};};Object[_0x4326b4(0x1db)](exports,'__esModule',{'value':!![]}),exports['ModelsService']=void 0x0;const common_1=require(_0x4326b4(0x1b1)),typeorm_1=require(_0x4326b4(0x1b6)),typeorm_2=require(_0x4326b4(0x1f2)),models_entity_1=require(_0x4326b4(0x1a1)),status_constant_1=require(_0x4326b4(0x1ac)),utils_1=require(_0x4326b4(0x1be)),modelType_entity_1=require(_0x4326b4(0x1e4));function _0x37a2(){const _0x3cc305=['push','reduce','@nestjs/common','useToken\x20+\x20','update','HttpStatus','useCount\x20+\x201','@nestjs/typeorm','error','28KHANWp','Injectable','getRandomItemFromArray','ModelsTypeEntity','decorate','keyList','../../common/utils','keys','map','queryModels','values','hideString','modelTypes','key','findAndCount','execute','缺失必要参数!','status','lockKey','Repository','HttpException','216DmpXbu','secret','delModelType','getAllKey','\x20欠费或被官方封禁导致不可用已被系统自动锁定','stringify','12ddAZBh','parse','sort','1736776VxwOSq','createQueryBuilder','844646cMLDGm','modelName','__metadata','defineProperty','ModelsMapCn','delModel','874374vshYQT','117xxrbDV','metadata','set','find','4hZYnsc','./modelType.entity','1121870zwxMAH','save','getCurrentModelKeyInfo','findOne','keyPoolMap','design:paramtypes','modelsList','当前账号不存在!','onModuleInit','forEach','modelsEntity','modelMaps','ModelsEntity','typeorm','modelOrder','getRandomDrawKey','val','saveUseLog','872276HNHlPn','parse\x20error:\x20','length','4069315CDiCQV','object','Like','id\x20=\x20:id','keyStatus','当前调用模型已经被移除、请重新选择模型!','key:\x20','getBaseConfig','./models.entity','keyType','model','log','10362684bbBKVe','getOwnPropertyDescriptor','delete','function','InjectRepository','initCalcKey','BAD_REQUEST','../../common/constants/status.constant','setModel','keyPoolIndexMap'];_0x37a2=function(){return _0x3cc305;};return _0x37a2();}let ModelsService=class ModelsService{constructor(_0x532453,_0x1bf1a6){const _0x5e9ad4=_0x4326b4;this[_0x5e9ad4(0x1ef)]=_0x532453,this['modelsTypeEntity']=_0x1bf1a6,this[_0x5e9ad4(0x1c4)]=[],this[_0x5e9ad4(0x1f0)]={},this['keyList']={},this[_0x5e9ad4(0x1e9)]={},this[_0x5e9ad4(0x1ae)]={};}async[_0x4326b4(0x1ed)](){await this['initCalcKey']();}async[_0x4326b4(0x1aa)](){const _0x556b58=_0x4326b4;this[_0x556b58(0x1e9)]={},this[_0x556b58(0x1ae)]={},this[_0x556b58(0x1bd)]={},this[_0x556b58(0x1f0)]={},this[_0x556b58(0x1c4)]=[];const _0x4fee2f=await this[_0x556b58(0x1ef)][_0x556b58(0x1e2)]({'where':{'status':!![]}}),_0xd7afaa=_0x4fee2f[_0x556b58(0x1b0)]((_0x375a11,_0x899d6d)=>{const _0x4ec0ee=_0x556b58;return!_0x375a11[_0x899d6d[_0x4ec0ee(0x1a2)]]?_0x375a11[_0x899d6d[_0x4ec0ee(0x1a2)]]=[_0x899d6d]:_0x375a11[_0x899d6d['keyType']][_0x4ec0ee(0x1af)](_0x899d6d),_0x375a11;},{});this[_0x556b58(0x1c4)]=Object[_0x556b58(0x1bf)](_0xd7afaa)[_0x556b58(0x1c0)](_0x1a8e67=>{const _0x246343=_0x556b58;return{'label':status_constant_1[_0x246343(0x1dc)][_0x1a8e67],'val':_0x1a8e67};}),this[_0x556b58(0x1f0)]=_0xd7afaa,this[_0x556b58(0x1bd)]={},_0x4fee2f[_0x556b58(0x1ee)](_0x5a1bd5=>{const _0x17b7d2=_0x556b58,{keyType:_0x82dc3d,model:_0x1b99c7,keyWeight:_0x55fe78}=_0x5a1bd5;if(!this[_0x17b7d2(0x1e9)][_0x1b99c7])this['keyPoolMap'][_0x1b99c7]=[];for(let _0x28b5cd=0x0;_0x28b5cd<_0x55fe78;_0x28b5cd++){this[_0x17b7d2(0x1e9)][_0x1b99c7][_0x17b7d2(0x1af)](_0x5a1bd5);}if(!this[_0x17b7d2(0x1ae)][_0x1b99c7])this['keyPoolIndexMap'][_0x1b99c7]=0x0;if(!this[_0x17b7d2(0x1bd)][_0x82dc3d])this[_0x17b7d2(0x1bd)][_0x82dc3d]={};if(!this[_0x17b7d2(0x1bd)][_0x82dc3d][_0x1b99c7])this['keyList'][_0x82dc3d][_0x1b99c7]=[];this[_0x17b7d2(0x1bd)][_0x82dc3d][_0x1b99c7]['push'](_0x5a1bd5);});}async[_0x4326b4(0x1ca)](_0x176943,_0x1f8c5d,_0x100b1e=-0x1){const _0x4dc675=_0x4326b4,_0x20f814=await this[_0x4dc675(0x1ef)]['update']({'id':_0x176943},{'status':![],'keyStatus':_0x100b1e,'remark':_0x1f8c5d});common_1['Logger'][_0x4dc675(0x1b7)](_0x4dc675(0x19f)+_0x176943+_0x4dc675(0x1d1)),this[_0x4dc675(0x1aa)]();}async[_0x4326b4(0x1e7)](_0x443087){const _0x216deb=_0x4326b4;if(!this['keyPoolMap'][_0x443087])throw new common_1['HttpException'](_0x216deb(0x19e),common_1[_0x216deb(0x1b4)][_0x216deb(0x1ab)]);this['keyPoolIndexMap'][_0x443087]++;const _0x5f3d57=this[_0x216deb(0x1ae)][_0x443087];if(_0x5f3d57>=this[_0x216deb(0x1e9)][_0x443087]['length'])this[_0x216deb(0x1ae)][_0x443087]=0x0;const _0x1a2d0e=this[_0x216deb(0x1e9)][_0x443087][this[_0x216deb(0x1ae)][_0x443087]];return _0x1a2d0e;}async[_0x4326b4(0x1a0)](_0x16b30b){const _0x8e8689=_0x4326b4;if(!this['modelTypes'][_0x8e8689(0x1f9)]||!Object[_0x8e8689(0x1bf)](this[_0x8e8689(0x1f0)])[_0x8e8689(0x1f9)])return;const _0x54a559=_0x16b30b?this[_0x8e8689(0x1c4)][_0x8e8689(0x1e2)](_0x39f81d=>Number(_0x39f81d[_0x8e8689(0x1f5)])===0x1):this[_0x8e8689(0x1c4)][0x0];if(!_0x54a559)return;const {keyType:_0x5a7ae7,modelName:_0xf42dd2,model:_0x1c40ef,maxModelTokens:_0x9e3afa,maxResponseTokens:_0x260204,deductType:_0x1eb25a,deduct:_0x56e9c8,maxRounds:_0x3673ea}=this[_0x8e8689(0x1f0)][_0x54a559[_0x8e8689(0x1f5)]][0x0];return{'modelTypeInfo':_0x54a559,'modelInfo':{'keyType':_0x5a7ae7,'modelName':_0xf42dd2,'model':_0x1c40ef,'maxModelTokens':_0x9e3afa,'maxResponseTokens':_0x260204,'topN':0.8,'systemMessage':'','deductType':_0x1eb25a,'deduct':_0x56e9c8,'maxRounds':_0x3673ea,'rounds':0x8}};}async[_0x4326b4(0x1ad)](_0x283510){const _0x5db7d7=_0x4326b4;try{const {id:_0x5d7095}=_0x283510;_0x283510[_0x5db7d7(0x1c9)]&&(_0x283510[_0x5db7d7(0x1fe)]=0x1);if(_0x5d7095){const _0x339165=await this['modelsEntity'][_0x5db7d7(0x1b3)]({'id':_0x5d7095},_0x283510);return await this[_0x5db7d7(0x1aa)](),_0x339165['affected']>0x0;}else{const {keyType:_0x5f0f08,key:_0x41b257}=_0x283510;if(Number(_0x5f0f08!==0x1)){const _0x3084bc=await this[_0x5db7d7(0x1ef)]['save'](_0x283510);return await this[_0x5db7d7(0x1aa)](),_0x3084bc;}else{const _0x1fe96f=_0x41b257[_0x5db7d7(0x1c0)](_0x29cc74=>{const _0x5e2b4d=_0x5db7d7;try{const _0x25708d=JSON[_0x5e2b4d(0x1d4)](JSON[_0x5e2b4d(0x1d2)](_0x283510));return _0x25708d[_0x5e2b4d(0x1c5)]=_0x29cc74,_0x25708d;}catch(_0x2b6987){console[_0x5e2b4d(0x1a4)](_0x5e2b4d(0x1f8),_0x2b6987);}}),_0x102f44=await this[_0x5db7d7(0x1ef)][_0x5db7d7(0x1e6)](_0x1fe96f);return await this[_0x5db7d7(0x1aa)](),_0x102f44;}}}catch(_0x50bf03){console['log']('error:\x20',_0x50bf03);}}async[_0x4326b4(0x1dd)]({id:_0x49e73c}){const _0x491db1=_0x4326b4;if(!_0x49e73c)throw new common_1[(_0x491db1(0x1cc))](_0x491db1(0x1c8),common_1[_0x491db1(0x1b4)][_0x491db1(0x1ab)]);const _0x1fc7b8=await this[_0x491db1(0x1ef)][_0x491db1(0x1e8)]({'where':{'id':_0x49e73c}});if(!_0x1fc7b8)throw new common_1[(_0x491db1(0x1cc))](_0x491db1(0x1ec),common_1[_0x491db1(0x1b4)][_0x491db1(0x1ab)]);const _0x2ec4a7=await this[_0x491db1(0x1ef)][_0x491db1(0x1a7)]({'id':_0x49e73c});return await this['initCalcKey'](),_0x2ec4a7;}async[_0x4326b4(0x1c1)](_0xdc1150,_0x2239bc){const _0x298ef8=_0x4326b4,{role:_0x33cbb0}=_0xdc1150['user'],{keyType:_0x254f07,key:_0x273744,status:_0x54f5d2,model:_0x1f23c8,page:page=0x1,size:size=0xa}=_0x2239bc;let _0x375164={};_0x254f07&&(_0x375164['keyType']=_0x254f07),_0x1f23c8&&(_0x375164[_0x298ef8(0x1a3)]=_0x1f23c8),_0x54f5d2&&(_0x375164['status']=Number(_0x54f5d2)===0x1?!![]:![]),_0x273744&&(_0x375164['key']=(0x0,typeorm_2[_0x298ef8(0x1fc)])('%'+_0x273744+'%'));const [_0x96eeb6,_0x2d2e79]=await this[_0x298ef8(0x1ef)][_0x298ef8(0x1c6)]({'where':_0x375164,'order':{'modelOrder':'ASC'},'skip':(page-0x1)*size,'take':size});return _0x33cbb0!=='super'&&_0x96eeb6['forEach'](_0x50dc25=>{const _0x5beedc=_0x298ef8;_0x50dc25[_0x5beedc(0x1c5)]&&(_0x50dc25['key']=(0x0,utils_1[_0x5beedc(0x1c3)])(_0x50dc25[_0x5beedc(0x1c5)])),_0x50dc25[_0x5beedc(0x1ce)]&&(_0x50dc25[_0x5beedc(0x1ce)]=(0x0,utils_1[_0x5beedc(0x1c3)])(_0x50dc25[_0x5beedc(0x1ce)]));}),{'rows':_0x96eeb6,'count':_0x2d2e79};}async[_0x4326b4(0x1eb)](){const _0x5d5b28=_0x4326b4,_0x26b0a3=JSON['parse'](JSON[_0x5d5b28(0x1d2)](this[_0x5d5b28(0x1f0)]));return Object['keys'](_0x26b0a3)[_0x5d5b28(0x1ee)](_0x4b6c07=>{const _0x5dae47=_0x5d5b28;_0x26b0a3[_0x4b6c07]=_0x26b0a3[_0x4b6c07][_0x5dae47(0x1d5)]((_0x2779c9,_0x3f9398)=>_0x2779c9[_0x5dae47(0x1f3)]-_0x3f9398[_0x5dae47(0x1f3)]),_0x26b0a3[_0x4b6c07]=Array['from'](_0x26b0a3[_0x4b6c07][_0x5dae47(0x1c0)](_0x3593e6=>{const {modelName:_0x226b22,model:_0x323dbd,deduct:_0x23cb38,deductType:_0x58f45f,maxRounds:_0x271505}=_0x3593e6;return{'modelName':_0x226b22,'model':_0x323dbd,'deduct':_0x23cb38,'deductType':_0x58f45f,'maxRounds':_0x271505};})[_0x5dae47(0x1b0)]((_0x4037be,_0x116ce2)=>_0x4037be['set'](_0x116ce2[_0x5dae47(0x1d9)],_0x116ce2),new Map())[_0x5dae47(0x1c2)]());}),{'modelTypeList':this[_0x5d5b28(0x1c4)],'modelMaps':_0x26b0a3};}async[_0x4326b4(0x1f6)](_0x4a7e6f,_0xdf1ac8){const _0x352a55=_0x4326b4;await this[_0x352a55(0x1ef)][_0x352a55(0x1d7)]()['update'](models_entity_1[_0x352a55(0x1f1)])[_0x352a55(0x1e1)]({'useCount':()=>_0x352a55(0x1b5),'useToken':()=>_0x352a55(0x1b2)+_0xdf1ac8})['where'](_0x352a55(0x1fd),{'id':_0x4a7e6f})[_0x352a55(0x1c7)]();}async[_0x4326b4(0x1f4)](){const _0x2fc327=_0x4326b4,_0x3ed664=await this[_0x2fc327(0x1ef)][_0x2fc327(0x1e2)]({'where':{'isDraw':!![],'status':!![]}});if(!_0x3ed664[_0x2fc327(0x1f9)])throw new common_1[(_0x2fc327(0x1cc))]('当前未指定特殊模型KEY、前往后台模型池设置吧',common_1[_0x2fc327(0x1b4)][_0x2fc327(0x1ab)]);return(0x0,utils_1[_0x2fc327(0x1ba)])(_0x3ed664);}async[_0x4326b4(0x1d0)](){const _0x386b8f=_0x4326b4;return await this[_0x386b8f(0x1ef)][_0x386b8f(0x1e2)]();}async['queryModelType'](_0x12abd0){return 0x1;}async['setModelType'](_0x4c1b39){return 0x1;}async[_0x4326b4(0x1cf)](_0x510218){return 0x1;}};ModelsService=__decorate([(0x0,common_1[_0x4326b4(0x1b9)])(),__param(0x0,(0x0,typeorm_1['InjectRepository'])(models_entity_1[_0x4326b4(0x1f1)])),__param(0x1,(0x0,typeorm_1[_0x4326b4(0x1a9)])(modelType_entity_1[_0x4326b4(0x1bb)])),__metadata(_0x4326b4(0x1ea),[typeorm_2[_0x4326b4(0x1cb)],typeorm_2[_0x4326b4(0x1cb)]])],ModelsService),exports['ModelsService']=ModelsService;