mirror of
https://github.com/xiaoyiweb/YiAi.git
synced 2026-04-25 20:44:30 +08:00
1 line
44 KiB
JavaScript
1 line
44 KiB
JavaScript
'use strict';function _0x4073(){const _0x6450ce=['globalConfigService','delChatPre','chatPreTypeEntity','addOneIfOdd','close','./chatPre.entity','InjectRepository','lockKey','getClientIp','statusCode','ModelsService','assistant','saveChatLog','dall-e-3','systemPreMessage','uuid','systemMessage','queryUserBalance','chatSyncFree','badwordsService','@nestjs/common','Billing\x20hard\x20limit\x20has\x20been\x20reached','billing','status','response','28iVPNMM','keyv','/v1/images/generations','map','quality','childList','OpenAiErrorCodeMessage','configEntity','1420JDHLYT','500727PTgnCh','gpt-3','UserService','defineProperty','../chatLog/chatLog.service','29788QyHpDS','getAllKeyList','Injectable','1106','@keyv/redis','chatPreEntity','queryChatBox','当前Key余额已不足、请重新再试一次吧!','error','dall','缺失必要参数!','chatBoxTypeEntity','keyPool','This\x20is\x20not\x20a\x20chat\x20model\x20and\x20thus\x20not\x20supported','includes','openaiTimeoutMs','32k','chat','getCurrentModelKeyInfo','toISOString','Too\x20Many\x20Requests','text','nineStore','delChatBox','maxResponseTokens','__decorate','result','split','delete','777368ZeejvL','BadwordsService','detail','autoreplyService','conversationId','16k','gpt-4-vision-preview',',\x20消耗token:\x20','checkUserStatus','userBanance','gpt-4','chat-error\x20<----------------------------------------->','queryChatPreList','../../common/utils','message','./baidu','openaiModel3MaxTokensRes','env','__param','REDIS_USER','uploadService','UploadService','imageUrl','getRandomDrawKey','绘制图片失败,请检查你的提示词是否有非法描述!','提供了错误的模型秘钥','queryChatBoxFrontend','GptKeysEntity','key','compileNetwork','appInfo','getUploadType','mjDraw','当前模型不是聊天模型','redis://','BAD_REQUEST','gpt-4-1106','Repository','userService','error:\x20','formatModelToken','HttpException','queryChatPre','config','getTokenCount','code:\x20','ChatPreEntity','save','../app/app.entity','saveUseLog','buildMessageFromParentMessageId','modelsService','setChatPre','application/octet-stream;\x20charset=utf-8','openaiBaseUrl','\x0a\x20Current\x20date:\x20','ChatPreTypeEntity','用户ID:\x20','fanyiService','setChatBoxType','./../user/user.service','../autoreply/autoreply.service','statusText','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!','服务异常、请重新试试吧!!!','getModelProxyUrl','base64','toLowerCase','Content-type','chatBoxEntity','draw\x20paompt\x20info\x20<==**==>\x20','../globalConfig/config.entity','typeId','../../common/constants/balance.constant','dall-e\x20draw\x20params:\x20','Bearer\x20','checkBadWords','size','importDynamic','typeInfo','update','3983wMZycM','stringify','sendMessageFromOpenAi','weight','setData','ChatLogService','AutoreplyService',',\x20key\x20===>\x20','HttpStatus','appId','./zhipu','decorate','https://api.openai.com','DrawService','4buQoaN','count','当前流程所需要的模型已被管理员下架、请联系管理员上架专属模型!','Catch\x20Error\x20','getConfigs','openaiModel4MaxTokens32kRes','all','proxyUrl','chat-error-detail\x20\x20<----------------------------------------->','nineai-chatlog','当前分类下有未处理数据不可移除!','log','PAYMENT_REQUIRED','standard','FanyiService','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters','abortController','sendMessageFromBaidu','delChatPreType','model3','assign','b64_json','当前模型不是聊天模型、已冻结当前调用Key、请重新尝试对话!','65PXtOES','当前模型调用过于频繁、请重新试试吧!','preset','userBalanceService','checkAutoReply','coverImg','91812avJGXL','chatGroupService','REDIS_HOST','modelInfo','chatProcess','model4','find','metadata','DESC','openaiModel3MaxTokens16kRes','end','length','floor','validateBalance','ceil','64615xxmtJU','ConfigEntity','design:paramtypes','appEntity','abort','chatgpt-ai-web','setChatPreType','../userBalance/userBalance.service','非法操作!','DeductionKey','model','../chatGroup/chatGroup.service','../globalConfig/globalConfig.service','getRequestParams','default','GlobalConfigService','getGroupInfoFromId','queryChatBoxType','draw','forEach','from','object','unifiedFormattingResponse','openaiModel3MaxTokens16k','openaiModel3MaxTokens','chatLogService','maxModelTokens','__esModule','write','9ydKdms','UserBalanceService','prompt','./helper','707474MOBoSd','The\x20OpenAI\x20account\x20associated\x20with\x20this\x20API\x20key\x20has\x20been\x20deactivated.','Incorrect\x20API\x20key\x20provided','REDIS_PORT','getBaseConfig','usage','parse','.png','./chatBox.entity','user','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','data','debug','whiteListUser','ConfigService','绘制图片失败,此次绘画被拒绝了!','ChatgptService','../models/models.service','push','4362lUzUuu','openaiModel4MaxTokens32k','getUuid','openai-draw\x20error:\x20','filter','../badwords/badwords.service','CHAT_TYPE','openaiProxyUrl','当前模型key已被封禁','queryChatPreType','onModuleInit','getMaxTokenFromModelWithOpenAi','__metadata','REDIS_PASSWORD'];_0x4073=function(){return _0x6450ce;};return _0x4073();}const _0x5c5e18=_0x3e3d;function _0x3e3d(_0x41b580,_0x5c93f6){const _0x4073fe=_0x4073();return _0x3e3d=function(_0x3e3dd5,_0x5b919e){_0x3e3dd5=_0x3e3dd5-0x68;let _0x137ed1=_0x4073fe[_0x3e3dd5];return _0x137ed1;},_0x3e3d(_0x41b580,_0x5c93f6);}(function(_0xc41825,_0x10c524){const _0x455729=_0x3e3d,_0x1b051a=_0xc41825();while(!![]){try{const _0x4efc70=parseInt(_0x455729(0xda))/0x1+-parseInt(_0x455729(0x8d))/0x2*(parseInt(_0x455729(0x11d))/0x3)+parseInt(_0x455729(0x114))/0x4*(parseInt(_0x455729(0xb9))/0x5)+parseInt(_0x455729(0xed))/0x6*(-parseInt(_0x455729(0x7f))/0x7)+parseInt(_0x455729(0x13f))/0x8*(-parseInt(_0x455729(0xd6))/0x9)+-parseInt(_0x455729(0x11c))/0xa*(-parseInt(_0x455729(0x122))/0xb)+-parseInt(_0x455729(0xaa))/0xc*(-parseInt(_0x455729(0xa4))/0xd);if(_0x4efc70===_0x10c524)break;else _0x1b051a['push'](_0x1b051a['shift']());}catch(_0x4ac12b){_0x1b051a['push'](_0x1b051a['shift']());}}}(_0x4073,0x5bd0a));var __decorate=this&&this[_0x5c5e18(0x13b)]||function(_0x28a80e,_0x2c5616,_0x29ce18,_0x12c4ff){const _0x4dbcb4=_0x5c5e18;var _0x34165f=arguments[_0x4dbcb4(0xb5)],_0x418938=_0x34165f<0x3?_0x2c5616:_0x12c4ff===null?_0x12c4ff=Object['getOwnPropertyDescriptor'](_0x2c5616,_0x29ce18):_0x12c4ff,_0x2eedfc;if(typeof Reflect===_0x4dbcb4(0xce)&&typeof Reflect[_0x4dbcb4(0x8a)]==='function')_0x418938=Reflect[_0x4dbcb4(0x8a)](_0x28a80e,_0x2c5616,_0x29ce18,_0x12c4ff);else{for(var _0x4bd987=_0x28a80e['length']-0x1;_0x4bd987>=0x0;_0x4bd987--)if(_0x2eedfc=_0x28a80e[_0x4bd987])_0x418938=(_0x34165f<0x3?_0x2eedfc(_0x418938):_0x34165f>0x3?_0x2eedfc(_0x2c5616,_0x29ce18,_0x418938):_0x2eedfc(_0x2c5616,_0x29ce18))||_0x418938;}return _0x34165f>0x3&&_0x418938&&Object[_0x4dbcb4(0x120)](_0x2c5616,_0x29ce18,_0x418938),_0x418938;},__metadata=this&&this[_0x5c5e18(0xf9)]||function(_0x46ccbb,_0x2424c6){const _0x5248e9=_0x5c5e18;if(typeof Reflect===_0x5248e9(0xce)&&typeof Reflect[_0x5248e9(0xb1)]==='function')return Reflect[_0x5248e9(0xb1)](_0x46ccbb,_0x2424c6);},__param=this&&this[_0x5c5e18(0x151)]||function(_0x5c84dd,_0x5e1695){return function(_0xc7b20,_0x4ddf02){_0x5e1695(_0xc7b20,_0x4ddf02,_0x5c84dd);};};Object[_0x5c5e18(0x120)](exports,_0x5c5e18(0xd4),{'value':!![]}),exports['ChatgptService']=void 0x0;const upload_service_1=require('./../upload/upload.service'),user_service_1=require(_0x5c5e18(0x6a)),nestjs_config_1=require('nestjs-config'),common_1=require(_0x5c5e18(0x10f)),errorMessage_constant_1=require('../../common/constants/errorMessage.constant'),utils_1=require(_0x5c5e18(0x14c)),axios_1=require('axios'),userBalance_service_1=require(_0x5c5e18(0xc0)),balance_constant_1=require(_0x5c5e18(0x77)),chatLog_service_1=require(_0x5c5e18(0x121)),uuid=require(_0x5c5e18(0x10a)),config_entity_1=require(_0x5c5e18(0x75)),typeorm_1=require('typeorm'),typeorm_2=require('@nestjs/typeorm'),badwords_service_1=require(_0x5c5e18(0xf2)),autoreply_service_1=require(_0x5c5e18(0x6b)),gptkeys_entity_1=require('./gptkeys.entity'),globalConfig_service_1=require(_0x5c5e18(0xc5)),fanyi_service_1=require('../fanyi/fanyi.service'),app_entity_1=require(_0x5c5e18(0x16f)),chatGroup_service_1=require(_0x5c5e18(0xc4)),models_service_1=require(_0x5c5e18(0xeb)),baidu_1=require(_0x5c5e18(0x14e)),helper_1=require(_0x5c5e18(0xd9)),store_1=require('./store'),zhipu_1=require(_0x5c5e18(0x89)),openai_1=require('./openai'),chatBoxType_entity_1=require('./chatBoxType.entity'),chatBox_entity_1=require(_0x5c5e18(0xe2)),chatPre_entity_1=require(_0x5c5e18(0x100)),chatPreType_entity_1=require('./chatPreType.entity');let ChatgptService=class ChatgptService{constructor(_0x58db48,_0x367e03,_0x1c7078,_0x337866,_0x4e46c9,_0x2c9471,_0x777a8e,_0xb9ef81,_0x3ab862,_0x45869c,_0x3a3c3d,_0x483593,_0x2029e0,_0x2975a3,_0xd8baf7,_0x178aa2,_0x8f5c61,_0x27179a){const _0x23fbd0=_0x5c5e18;this['gptKeysEntity']=_0x58db48,this[_0x23fbd0(0x11b)]=_0x367e03,this[_0x23fbd0(0x12d)]=_0x1c7078,this[_0x23fbd0(0x73)]=_0x337866,this['appEntity']=_0x4e46c9,this['chatPreTypeEntity']=_0x2c9471,this[_0x23fbd0(0x127)]=_0x777a8e,this['configService']=_0xb9ef81,this[_0x23fbd0(0xa7)]=_0x3ab862,this[_0x23fbd0(0xd2)]=_0x45869c,this[_0x23fbd0(0x165)]=_0x3a3c3d,this[_0x23fbd0(0x153)]=_0x483593,this[_0x23fbd0(0x10e)]=_0x2029e0,this['autoreplyService']=_0x2975a3,this['globalConfigService']=_0xd8baf7,this[_0x23fbd0(0x68)]=_0x178aa2,this[_0x23fbd0(0xab)]=_0x8f5c61,this[_0x23fbd0(0x172)]=_0x27179a,this['nineStore']=null,this[_0x23fbd0(0xe7)]=[],this[_0x23fbd0(0x12e)]={'list3':[],'list4':[]};}async[_0x5c5e18(0xf7)](){const _0xd127fc=_0x5c5e18;let _0x5e958a=await(0x0,utils_1[_0xd127fc(0x7c)])(_0xd127fc(0xbe)),_0x300b7d=await(0x0,utils_1['importDynamic'])(_0xd127fc(0x126)),_0x41742e=await(0x0,utils_1[_0xd127fc(0x7c)])(_0xd127fc(0x115));_0x5e958a=(_0x5e958a===null||_0x5e958a===void 0x0?void 0x0:_0x5e958a[_0xd127fc(0xc7)])?_0x5e958a['default']:_0x5e958a,_0x300b7d=(_0x300b7d===null||_0x300b7d===void 0x0?void 0x0:_0x300b7d[_0xd127fc(0xc7)])?_0x300b7d[_0xd127fc(0xc7)]:_0x300b7d,_0x41742e=(_0x41742e===null||_0x41742e===void 0x0?void 0x0:_0x41742e[_0xd127fc(0xc7)])?_0x41742e[_0xd127fc(0xc7)]:_0x41742e;const {ChatGPTAPI:_0xeb0c9,ChatGPTError:_0x44e10b,ChatGPTUnofficialProxyAPI:_0x100d81}=_0x5e958a,_0x481118=+process['env'][_0xd127fc(0xdd)],_0x42597c=process['env'][_0xd127fc(0xac)],_0x128db9=process[_0xd127fc(0x150)][_0xd127fc(0xfa)],_0x5267e6=process['env'][_0xd127fc(0x152)],_0x2f993d=_0xd127fc(0x161)+(_0x5267e6||'')+':'+(_0x128db9||'')+'@'+_0x42597c+':'+_0x481118,_0x4852fd=new _0x300b7d(_0x2f993d),_0x49c9c8=new _0x41742e({'store':_0x4852fd,'namespace':_0xd127fc(0x96)});this[_0xd127fc(0x138)]=new store_1['NineStore']({'store':_0x49c9c8,'namespace':_0xd127fc(0x133)});}async[_0x5c5e18(0xc6)](_0x23247a,_0x5649b8,_0x12a263,_0x8a7017=null){const _0x306f3b=_0x5c5e18;var _0xd0940a;!_0x8a7017&&(_0x8a7017=(_0xd0940a=await this[_0x306f3b(0x172)][_0x306f3b(0xde)]())===null||_0xd0940a===void 0x0?void 0x0:_0xd0940a[_0x306f3b(0xad)]);const {timeout:timeout=0x3c}=_0x12a263,{topN:_0x37fefd,model:_0x67a6d}=_0x8a7017,{parentMessageId:parentMessageId=0x0}=_0x23247a,_0x3e7f8e=await this[_0x306f3b(0xfb)]['getConfigs']([_0x306f3b(0x131)]),_0x4f5cc8=timeout*0x3e8||_0x3e7f8e||0x64*0x3e8,_0x2867c4={'parentMessageId':parentMessageId,'timeoutMs':+_0x4f5cc8,'completionParams':{'model':_0x67a6d,'temperature':_0x37fefd}};return _0x5649b8&&(_0x2867c4[_0x306f3b(0x10b)]=_0x5649b8),_0x2867c4;}async[_0x5c5e18(0x10d)](_0x19ca1f){const _0x14e2be=_0x5c5e18,_0xaac72f=await this[_0x14e2be(0x172)]['getRandomDrawKey'](),_0x95ac7f=await this[_0x14e2be(0xfb)][_0x14e2be(0x91)]([_0x14e2be(0x109)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x5980ca,model:_0x1a03ec}=_0xaac72f,_0x44df41=await this[_0x14e2be(0x6f)](_0xaac72f),{context:_0x5b87d6}=await this[_0x14e2be(0x138)][_0x14e2be(0x171)](_0x19ca1f,{'parentMessageId':'','systemMessage':_0x95ac7f});try{const _0x1dc110=await(0x0,openai_1[_0x14e2be(0x81)])(_0x5b87d6,{'apiKey':(0x0,utils_1['removeSpecialCharacters'])(_0x5980ca),'model':_0x1a03ec,'proxyUrl':_0x44df41,'onProgress':null});return _0x1dc110===null||_0x1dc110===void 0x0?void 0x0:_0x1dc110[_0x14e2be(0x137)];}catch(_0x111df2){console['log'](_0x14e2be(0x166),_0x111df2);}}async[_0x5c5e18(0xae)](_0x43e76b,_0x322b54,_0x6d0c4a){const _0x3ad283=_0x5c5e18;var _0x1a3dec,_0x8bc1c5,_0x3a65f8,_0x8ebf70;const _0x5da4d7=_0x322b54[_0x3ad283(0x9d)],{options:options={},appId:_0x101b29,cusromPrompt:_0xbcd066,systemMessage:systemMessage=''}=_0x43e76b;let _0x3e174c=systemMessage;const {parentMessageId:_0x441a18}=options,{prompt:_0x438bb2,imageUrl:_0x5c6292,model:_0x2c7a1f}=_0x43e76b,{groupId:_0x11d8c4,usingNetwork:_0x58e834}=options,_0x37497b=await this[_0x3ad283(0xab)][_0x3ad283(0xc9)](_0x11d8c4),_0x57448f=(_0x37497b===null||_0x37497b===void 0x0?void 0x0:_0x37497b[_0x3ad283(0x16a)])?JSON[_0x3ad283(0xe0)](_0x37497b['config']):await this[_0x3ad283(0x172)]['getBaseConfig'](),{keyType:_0x154fe3,model:_0x4cd71c,topN:_0x3eb115,systemMessage:_0x10470d,rounds:_0x126db0}=_0x57448f[_0x3ad283(0xad)];let _0x90c2c6=null;!_0xbcd066?_0x90c2c6=await this['modelsService'][_0x3ad283(0x134)](_0x4cd71c):_0x90c2c6=await this[_0x3ad283(0x172)][_0x3ad283(0x156)]();if(!_0x90c2c6)throw new common_1[(_0x3ad283(0x168))](_0x3ad283(0x8f),common_1[_0x3ad283(0x87)][_0x3ad283(0x162)]);const {deduct:_0x12cb7e,isTokenBased:_0x3cf32c,tokenFeeRatio:_0x45d3b0,deductType:_0x1f4f8f,key:_0x1cb1e0,secret:_0x137190,modelName:_0xfca1a6,id:_0x35f42c,accessToken:_0x5c7ceb}=_0x90c2c6;await this[_0x3ad283(0x165)]['checkUserStatus'](_0x322b54[_0x3ad283(0xe3)]),await this['userBalanceService'][_0x3ad283(0xb7)](_0x322b54,_0x1f4f8f===0x1?_0x3ad283(0xa0):_0x3ad283(0xaf),_0x12cb7e),_0x6d0c4a&&_0x6d0c4a['setHeader'](_0x3ad283(0x72),_0x3ad283(0x174)),await this[_0x3ad283(0x10e)][_0x3ad283(0x7a)](_0x438bb2,_0x322b54[_0x3ad283(0xe3)]['id']);const _0x23fda2=await this[_0x3ad283(0x142)][_0x3ad283(0xa8)](_0x438bb2);if(_0x23fda2&&_0x6d0c4a){const _0x4cd16c={'message':_0x23fda2,'code':0x1f4};return _0x6d0c4a[_0x3ad283(0xd5)](JSON['stringify'](_0x4cd16c)),_0x6d0c4a[_0x3ad283(0xb4)]();}if(_0x101b29){const _0x596d80=await this['appEntity']['findOne']({'where':{'id':_0x101b29,'status':(0x0,typeorm_1['In'])([0x1,0x3,0x4,0x5])}});if(!_0x596d80)throw new common_1[(_0x3ad283(0x168))]('你当前使用的应用已被下架、请删除当前对话开启新的对话吧!',common_1[_0x3ad283(0x87)][_0x3ad283(0x162)]);_0x596d80[_0x3ad283(0xa6)]&&(_0x3e174c=_0x596d80['preset']);}else{if(_0xbcd066)_0x3e174c=systemMessage;else{if(_0x10470d)_0x3e174c=_0x10470d;else{const _0x29c6ba=new Date()[_0x3ad283(0x135)]()[_0x3ad283(0x13d)]('T')[0x0],_0x48aa8d=await this[_0x3ad283(0xfb)][_0x3ad283(0x91)]([_0x3ad283(0x109)]);_0x3e174c=_0x48aa8d+(_0x3ad283(0x176)+_0x29c6ba);}}}let _0x1eca01='';if(_0x58e834){_0x1eca01=await(0x0,utils_1[_0x3ad283(0x15c)])(_0x438bb2);const _0x5346d9=new Date()[_0x3ad283(0x135)]()[_0x3ad283(0x13d)]('T')[0x0],_0x5be870=await this[_0x3ad283(0xfb)][_0x3ad283(0x91)](['systemPreMessage']);_0x3e174c=_0x5be870+(_0x3ad283(0x176)+_0x5346d9);}const _0xe6c16d=await this['getRequestParams'](options,_0x3e174c,_0x90c2c6,_0x57448f[_0x3ad283(0xad)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x3ee041}=_0x90c2c6;_0x6d0c4a&&_0x6d0c4a[_0x3ad283(0x112)](0xc8);let _0x54e631=null,_0x1e1196=null;try{if(_0x6d0c4a){let _0x2e6006=null,_0x5e0a37=![];_0x6d0c4a['on'](_0x3ad283(0xff),async()=>{const _0x331590=_0x3ad283;if(_0x5e0a37)return;_0x5da4d7[_0x331590(0xbd)]();const _0xe50196=await(0x0,openai_1[_0x331590(0x16b)])(_0x438bb2)||0x0,_0x3166f9=await(0x0,openai_1[_0x331590(0x16b)])(_0x2e6006===null||_0x2e6006===void 0x0?void 0x0:_0x2e6006[_0x331590(0x137)])||0x0,_0x3b6291=_0xe50196+_0x3166f9,_0x11f6e3=(0x0,utils_1[_0x331590(0x103)])(_0x322b54);await this[_0x331590(0xd2)][_0x331590(0x107)]({'appId':_0x101b29,'curIp':_0x11f6e3,'userId':_0x322b54[_0x331590(0xe3)]['id'],'type':balance_constant_1[_0x331590(0xc2)]['CHAT_TYPE'],'prompt':_0x438bb2,'imageUrl':_0x5c6292,'activeModel':_0x2c7a1f,'answer':'','promptTokens':_0xe50196,'completionTokens':0x0,'totalTokens':_0xe50196,'model':_0x4cd71c,'role':_0x331590(0xe3),'groupId':_0x11d8c4,'requestOptions':JSON[_0x331590(0x80)]({'options':null,'prompt':_0x438bb2})}),await this['chatLogService'][_0x331590(0x107)]({'appId':_0x101b29,'curIp':_0x11f6e3,'userId':_0x322b54['user']['id'],'type':balance_constant_1[_0x331590(0xc2)]['CHAT_TYPE'],'prompt':_0x438bb2,'answer':_0x2e6006===null||_0x2e6006===void 0x0?void 0x0:_0x2e6006[_0x331590(0x137)],'promptTokens':_0xe50196,'completionTokens':_0x3166f9,'totalTokens':_0x3b6291,'model':_0x4cd71c,'role':'assistant','groupId':_0x11d8c4,'requestOptions':JSON['stringify']({'options':{'model':_0x4cd71c,'temperature':_0x3eb115},'prompt':_0x438bb2}),'conversationOptions':JSON[_0x331590(0x80)]({'conversationId':_0x2e6006===null||_0x2e6006===void 0x0?void 0x0:_0x2e6006[_0x331590(0x143)],'model':_0x4cd71c,'parentMessageId':_0x2e6006===null||_0x2e6006===void 0x0?void 0x0:_0x2e6006['id'],'temperature':_0x3eb115})});let _0x2eafc0=_0x12cb7e;_0x3cf32c===!![]&&(_0x2eafc0=Math[_0x331590(0xb8)](_0x12cb7e*_0x3b6291/_0x45d3b0)),await this[_0x331590(0xa7)]['deductFromBalance'](_0x322b54[_0x331590(0xe3)]['id'],'model'+(_0x1f4f8f===0x1?0x3:0x4),_0x2eafc0,_0x3b6291);});if(Number(_0x154fe3)===0x1){const {key:_0x184862,maxToken:_0x3b7080,maxTokenRes:_0x4b2618,proxyResUrl:_0x19a42a}=await this[_0x3ad283(0x167)](_0x90c2c6),{parentMessageId:_0x432611,completionParams:_0x47eac0,systemMessage:_0x1a92a6}=_0xe6c16d,{model:_0x4867a8,temperature:_0x4380e1}=_0x47eac0,{context:_0x3fdb6c}=await this[_0x3ad283(0x138)]['buildMessageFromParentMessageId'](_0x58e834?_0x1eca01:_0x438bb2,{'parentMessageId':_0x432611,'systemMessage':_0x1a92a6,'maxModelToken':_0x3b7080,'maxResponseTokens':_0x4b2618,'maxRounds':(0x0,helper_1[_0x3ad283(0xfe)])(_0x126db0),'imageUrl':_0x5c6292,'activeModel':_0x2c7a1f});let _0x573d1f=!![];_0x54e631=await(0x0,openai_1[_0x3ad283(0x81)])(_0x3fdb6c,{'maxToken':_0x3b7080,'maxTokenRes':_0x4b2618,'apiKey':_0x1cb1e0,'model':_0x4867a8,'prompt':_0x438bb2,'activeModel':_0x2c7a1f,'imageUrl':_0x5c6292,'temperature':_0x4380e1,'proxyUrl':_0x19a42a,'onProgress':_0x350f17=>{const _0x2b9205=_0x3ad283;_0x6d0c4a[_0x2b9205(0xd5)](_0x573d1f?JSON['stringify'](_0x350f17):'\x0a'+JSON['stringify'](_0x350f17)),_0x2e6006=_0x350f17,_0x573d1f=![];}},this[_0x3ad283(0x153)]),_0x5e0a37=!![];}if(Number(_0x154fe3)===0x2){let _0xfa9d54=!![];const {context:_0x389dc9}=await this[_0x3ad283(0x138)][_0x3ad283(0x171)](_0x58e834?_0x1eca01:_0x438bb2,{'parentMessageId':_0x441a18,'maxRounds':(0x0,helper_1[_0x3ad283(0xfe)])(_0x126db0)});_0x54e631=await(0x0,baidu_1[_0x3ad283(0x9e)])(_0x58e834?_0x1eca01:_0x389dc9,{'temperature':_0x3eb115,'accessToken':_0x5c7ceb,'model':_0x4cd71c,'onProgress':_0xa449b2=>{const _0x590fc1=_0x3ad283;_0x6d0c4a[_0x590fc1(0xd5)](_0xfa9d54?JSON[_0x590fc1(0x80)](_0xa449b2):'\x0a'+JSON[_0x590fc1(0x80)](_0xa449b2)),_0xfa9d54=![],_0x2e6006=_0xa449b2;}}),_0x5e0a37=!![];}if(Number(_0x154fe3)===0x3){let _0x5daae2=!![];const {context:_0x4d2ddd}=await this[_0x3ad283(0x138)][_0x3ad283(0x171)](_0x58e834?_0x1eca01:_0x438bb2,{'parentMessageId':_0x441a18,'maxRounds':(0x0,helper_1[_0x3ad283(0xfe)])(_0x126db0)});_0x54e631=await(0x0,zhipu_1['sendMessageFromZhipu'])(_0x58e834?_0x1eca01:_0x4d2ddd,{'temperature':_0x3eb115,'key':_0x3ee041,'model':_0x4cd71c,'onProgress':_0x53cc92=>{const _0x3284c3=_0x3ad283;_0x6d0c4a[_0x3284c3(0xd5)](_0x5daae2?JSON[_0x3284c3(0x80)](_0x53cc92):'\x0a'+JSON[_0x3284c3(0x80)](_0x53cc92)),_0x5daae2=![],_0x2e6006=_0x53cc92;}}),_0x5e0a37=!![];}const _0x3c2c2a={'id':this[_0x3ad283(0x138)][_0x3ad283(0xef)](),'text':_0x438bb2,'role':'user','name':undefined,'usage':null,'imageUrl':_0x5c6292,'activeModel':_0x2c7a1f,'parentMessageId':_0x441a18,'conversationId':_0x54e631===null||_0x54e631===void 0x0?void 0x0:_0x54e631[_0x3ad283(0x143)]};_0x1e1196={'model':_0x4cd71c,'parentMessageId':_0x441a18},await this[_0x3ad283(0x138)][_0x3ad283(0x83)](_0x3c2c2a);const _0x122fb1={'id':_0x54e631['id'],'text':_0x54e631['text'],'role':_0x3ad283(0x106),'name':undefined,'usage':_0x54e631===null||_0x54e631===void 0x0?void 0x0:_0x54e631[_0x3ad283(0xdf)],'imageUrl':_0x5c6292,'parentMessageId':_0x3c2c2a['id'],'conversationId':_0x54e631===null||_0x54e631===void 0x0?void 0x0:_0x54e631[_0x3ad283(0x143)]};await this['nineStore'][_0x3ad283(0x83)](_0x122fb1),_0x1e1196={'model':_0x4cd71c,'parentMessageId':_0x3c2c2a['id']};}else{const {key:_0xb95070,maxToken:_0x17dd33,maxTokenRes:_0x8ea8a3,proxyResUrl:_0x3b168c}=await this['formatModelToken'](_0x90c2c6),{parentMessageId:_0x5b4bc9,completionParams:_0x5e7621,systemMessage:_0x220b5a}=_0xe6c16d,{model:_0x3e031e,temperature:_0x1ecd6}=_0x5e7621,{context:_0x29932f}=await this[_0x3ad283(0x138)][_0x3ad283(0x171)](_0x58e834?_0x1eca01:_0x438bb2,{'parentMessageId':_0x5b4bc9,'systemMessage':_0x220b5a,'maxRounds':(0x0,helper_1[_0x3ad283(0xfe)])(_0x126db0)});_0x54e631=await(0x0,openai_1['sendMessageFromOpenAi'])(_0x29932f,{'apiKey':_0x1cb1e0,'model':_0x3e031e,'temperature':_0x1ecd6,'proxyUrl':_0x3b168c,'onProgress':null,'prompt':_0x438bb2});}let _0x3897cb=null,_0x1fdb05=null;_0x4cd71c[_0x3ad283(0x130)]('dall')?_0x3897cb=((_0x1a3dec=_0x54e631[_0x3ad283(0x141)])===null||_0x1a3dec===void 0x0?void 0x0:_0x1a3dec[_0x3ad283(0xdf)])||{'prompt_tokens':0x1,'completion_tokens':0x1,'total_tokens':0x2}:_0x1fdb05=await(0x0,helper_1[_0x3ad283(0xcf)])(_0x154fe3,_0x54e631,_0x1e1196);const {prompt_tokens:_0x1c3ab1,completion_tokens:_0x248fda,total_tokens:_0x54cada}=_0x4cd71c[_0x3ad283(0x130)](_0x3ad283(0x12b))?_0x3897cb:_0x1fdb05[_0x3ad283(0xdf)];let _0x23cf04=_0x12cb7e;_0x3cf32c===!![]&&(_0x23cf04=Math[_0x3ad283(0xb8)](_0x12cb7e*_0x54cada/_0x45d3b0));await this[_0x3ad283(0xa7)]['deductFromBalance'](_0x322b54[_0x3ad283(0xe3)]['id'],_0x3ad283(0xc3)+(_0x1f4f8f===0x1?0x3:0x4),_0x23cf04,_0x54cada),await this['modelsService'][_0x3ad283(0x170)](_0x35f42c,_0x54cada);const _0x32249f=(0x0,utils_1['getClientIp'])(_0x322b54);await this['chatLogService'][_0x3ad283(0x107)]({'appId':_0x101b29,'curIp':_0x32249f,'userId':_0x322b54['user']['id'],'type':balance_constant_1[_0x3ad283(0xc2)][_0x3ad283(0xf3)],'prompt':_0x438bb2,'imageUrl':_0x5c6292,'activeModel':_0x2c7a1f,'answer':'','promptTokens':_0x1c3ab1,'completionTokens':0x0,'totalTokens':_0x54cada,'model':_0x4cd71c,'role':'user','groupId':_0x11d8c4,'requestOptions':JSON[_0x3ad283(0x80)]({'options':null,'prompt':_0x438bb2})}),await this[_0x3ad283(0xd2)][_0x3ad283(0x107)]({'appId':_0x101b29,'curIp':_0x32249f,'userId':_0x322b54['user']['id'],'type':balance_constant_1['DeductionKey'][_0x3ad283(0xf3)],'prompt':_0x438bb2,'imageUrl':_0x54e631===null||_0x54e631===void 0x0?void 0x0:_0x54e631[_0x3ad283(0x155)],'answer':_0x54e631['text'],'promptTokens':_0x1c3ab1,'completionTokens':_0x248fda,'totalTokens':_0x54cada,'model':_0x4cd71c,'role':_0x3ad283(0x106),'groupId':_0x11d8c4,'requestOptions':JSON[_0x3ad283(0x80)]({'options':{'model':_0x4cd71c,'temperature':_0x3eb115},'prompt':_0x438bb2}),'conversationOptions':JSON['stringify']({'conversationId':_0x54e631[_0x3ad283(0x143)],'model':_0x4cd71c,'parentMessageId':_0x54e631['id'],'temperature':_0x3eb115})}),common_1['Logger'][_0x3ad283(0xe6)](_0x3ad283(0x178)+_0x322b54['user']['id']+'\x20模型名称:\x20'+_0xfca1a6+'-'+_0x2c7a1f+_0x3ad283(0x146)+_0x54cada+',\x20消耗积分:\x20'+_0x23cf04,_0x3ad283(0xea));const _0x295a40=await this[_0x3ad283(0xa7)][_0x3ad283(0x10c)](_0x322b54['user']['id']);return _0x54e631[_0x3ad283(0x148)]=Object[_0x3ad283(0xa1)]({},_0x295a40),_0x54e631['result']&&(_0x54e631[_0x3ad283(0x13c)]=''),_0x54e631['is_end']=!![],_0x6d0c4a?_0x6d0c4a[_0x3ad283(0xd5)]('\x0a'+JSON[_0x3ad283(0x80)](_0x54e631)):_0x54e631[_0x3ad283(0x137)];}catch(_0x576f84){console[_0x3ad283(0x98)](_0x3ad283(0x14a),_0x1cb1e0,_0x576f84);const _0x6f9ae1=(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x104)])||0x190,_0xf11fe3=((_0x8bc1c5=_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x113)])===null||_0x8bc1c5===void 0x0?void 0x0:_0x8bc1c5[_0x3ad283(0x112)])||(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84['statusCode'])||0x190;console[_0x3ad283(0x98)](_0x3ad283(0x95),_0x3ad283(0x16c),_0x6f9ae1,'message',_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x14d)],'statusText:',(_0x3a65f8=_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x113)])===null||_0x3a65f8===void 0x0?void 0x0:_0x3a65f8[_0x3ad283(0x6c)],_0x3ad283(0x112),(_0x8ebf70=_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x113)])===null||_0x8ebf70===void 0x0?void 0x0:_0x8ebf70['status']);if(_0x576f84[_0x3ad283(0x112)]&&_0x576f84['status']===0x192){const _0x49ee3a={'message':_0x3ad283(0x90)+_0x576f84[_0x3ad283(0x14d)],'code':0x192};if(_0x6d0c4a)return _0x6d0c4a[_0x3ad283(0xd5)](JSON['stringify'](_0x49ee3a));else throw new common_1[(_0x3ad283(0x168))](_0x576f84[_0x3ad283(0x14d)],common_1[_0x3ad283(0x87)][_0x3ad283(0x99)]);}if(!_0xf11fe3){if(_0x6d0c4a)return _0x6d0c4a[_0x3ad283(0xd5)](JSON[_0x3ad283(0x80)]({'message':_0x576f84['message'],'code':0x1f4}));else throw new common_1[(_0x3ad283(0x168))](_0x576f84[_0x3ad283(0x14d)],common_1[_0x3ad283(0x87)][_0x3ad283(0x162)]);}let _0x4da9d9=errorMessage_constant_1[_0x3ad283(0x11a)][_0xf11fe3]?errorMessage_constant_1[_0x3ad283(0x11a)][_0xf11fe3]:_0x3ad283(0x6e);(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x14d)][_0x3ad283(0x130)](_0x3ad283(0xdb)))&&Number(_0x154fe3)===0x1&&(await this[_0x3ad283(0x172)][_0x3ad283(0x102)](_0x35f42c,'当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!',-0x1),_0x4da9d9=_0x3ad283(0xf5));(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x104)])===0x1ad&&_0x576f84['message'][_0x3ad283(0x130)](_0x3ad283(0x111))&&Number(_0x154fe3)===0x1&&(await this[_0x3ad283(0x172)][_0x3ad283(0x102)](_0x35f42c,'当前模型key余额已耗尽、已冻结当前调用Key、尝试重新对话试试吧!',-0x3),_0x4da9d9='当前模型key余额已耗尽');(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x104)])===0x1ad&&(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x6c)])===_0x3ad283(0x136)&&(_0x4da9d9=_0x3ad283(0xa5));(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84[_0x3ad283(0x104)])===0x191&&_0x576f84['message']['includes'](_0x3ad283(0xdc))&&Number(_0x154fe3)===0x1&&(await this[_0x3ad283(0x172)]['lockKey'](_0x35f42c,_0x3ad283(0x158),-0x2),_0x4da9d9='提供了错误的模型秘钥、已冻结当前调用Key、请重新尝试对话!');(_0x576f84===null||_0x576f84===void 0x0?void 0x0:_0x576f84['statusCode'])===0x194&&_0x576f84[_0x3ad283(0x14d)]['includes'](_0x3ad283(0x12f))&&Number(_0x154fe3)===0x1&&(await this[_0x3ad283(0x172)]['lockKey'](_0x35f42c,_0x3ad283(0x160),-0x4),_0x4da9d9=_0x3ad283(0xa3));_0x6f9ae1===0x190&&console[_0x3ad283(0x98)]('400\x20error',_0x576f84,_0x576f84[_0x3ad283(0x14d)]);const _0x4b6b08={'message':_0x4da9d9||'Please\x20check\x20the\x20back-end\x20console','code':_0x6f9ae1===0x191?0x190:_0x6f9ae1||0x1f4};if(_0x6d0c4a)return _0x6d0c4a[_0x3ad283(0xd5)](JSON[_0x3ad283(0x80)](_0x4b6b08));else throw new common_1[(_0x3ad283(0x168))](_0x4b6b08['message'],common_1[_0x3ad283(0x87)]['BAD_REQUEST']);}finally{_0x6d0c4a&&_0x6d0c4a[_0x3ad283(0xb4)]();}}async[_0x5c5e18(0xcb)](_0x1af058,_0x24630d){const _0x491829=_0x5c5e18;var _0x2622f3,_0x283782,_0x312552,_0x2a2b85;await this[_0x491829(0x10e)][_0x491829(0x7a)](_0x1af058[_0x491829(0xd8)],_0x24630d[_0x491829(0xe3)]['id']),await this[_0x491829(0x165)][_0x491829(0x147)](_0x24630d[_0x491829(0xe3)]);const _0x33eaeb=(_0x1af058===null||_0x1af058===void 0x0?void 0x0:_0x1af058[_0x491829(0x118)])==='hd'?0x4:0x2;await this['userBalanceService'][_0x491829(0xb7)](_0x24630d,_0x491829(0x15f),_0x33eaeb);let _0x4f1bc4=[];const _0x107dc0=await this[_0x491829(0x172)][_0x491829(0x134)]('dall-e-3'),_0x5170bd=_0x107dc0===null||_0x107dc0===void 0x0?void 0x0:_0x107dc0['id'],{key:_0x5aaed4,proxyResUrl:_0x1fb78d}=await this[_0x491829(0x167)](_0x107dc0);common_1['Logger']['log'](_0x491829(0x74)+_0x1af058['prompt']+_0x491829(0x86)+_0x5aaed4,_0x491829(0x8c));try{const _0x207c99=_0x1fb78d+_0x491829(0x116),_0x599ace=Object[_0x491829(0xa1)](Object[_0x491829(0xa1)]({},_0x1af058),{'model':_0x491829(0x108)});console[_0x491829(0x98)](_0x491829(0x78),_0x599ace);const _0xa205a0=await axios_1[_0x491829(0xc7)]['post'](_0x207c99,Object[_0x491829(0xa1)](Object[_0x491829(0xa1)]({},_0x599ace),{'response_format':_0x491829(0xa2)}),{'headers':{'Authorization':_0x491829(0x79)+_0x5aaed4}});_0x4f1bc4=_0xa205a0[_0x491829(0xe5)][_0x491829(0xe5)];const _0x4fa885=[];for(const _0x64a3e9 of _0x4f1bc4){const _0x51d531=uuid['v4']()['slice'](0x0,0xa)+_0x491829(0xe1),_0x5a6f73=Buffer[_0x491829(0xcd)](_0x64a3e9['b64_json'],_0x491829(0x70));_0x4fa885[_0x491829(0xec)](this[_0x491829(0x153)]['uploadFile']({'filename':_0x51d531,'buffer':_0x5a6f73}));}const _0x53d0df=await Promise[_0x491829(0x93)](_0x4fa885);await this[_0x491829(0xa7)]['deductFromBalance'](_0x24630d[_0x491829(0xe3)]['id'],'mjDraw',(_0x599ace===null||_0x599ace===void 0x0?void 0x0:_0x599ace[_0x491829(0x118)])===_0x491829(0x9a)?0x2:0x4,_0x33eaeb);const _0x2578c2=(0x0,utils_1[_0x491829(0x103)])(_0x24630d),_0x2cdb00=[],_0x4310a3=await this['uploadService'][_0x491829(0x15e)](),[_0x25e585,_0x2f3a21]=_0x1af058[_0x491829(0x7b)][_0x491829(0x13d)]('x');return _0x53d0df[_0x491829(0xcc)](_0x512a2c=>{const _0x1c46d1=_0x491829;_0x2cdb00['push'](this['chatLogService']['saveChatLog']({'curIp':_0x2578c2,'userId':_0x24630d[_0x1c46d1(0xe3)]['id'],'type':balance_constant_1[_0x1c46d1(0xc2)]['PAINT_TYPE'],'prompt':_0x1af058['prompt'],'answer':_0x512a2c,'fileInfo':JSON[_0x1c46d1(0x80)]({'cosType':_0x4310a3,'width':_0x25e585,'height':_0x2f3a21,'cosUrl':_0x512a2c}),'promptTokens':0x0,'completionTokens':0x0,'totalTokens':0x0,'model':_0x1c46d1(0x108)}));}),await Promise[_0x491829(0x93)](_0x2cdb00),_0x53d0df;}catch(_0x5eb0be){const _0x5a61bb=((_0x2622f3=_0x5eb0be===null||_0x5eb0be===void 0x0?void 0x0:_0x5eb0be[_0x491829(0x113)])===null||_0x2622f3===void 0x0?void 0x0:_0x2622f3['status'])||0x1f4;console['log'](_0x491829(0xf0),JSON[_0x491829(0x80)](_0x5eb0be),_0x5aaed4,_0x5a61bb);const _0x3aa5ce=(_0x2a2b85=(_0x312552=(_0x283782=_0x5eb0be===null||_0x5eb0be===void 0x0?void 0x0:_0x5eb0be['response'])===null||_0x283782===void 0x0?void 0x0:_0x283782[_0x491829(0xe5)])===null||_0x312552===void 0x0?void 0x0:_0x312552[_0x491829(0x12a)])===null||_0x2a2b85===void 0x0?void 0x0:_0x2a2b85[_0x491829(0x14d)];if(_0x5a61bb===0x1ad)throw new common_1['HttpException']('当前请求已过载、请稍等会儿再试试吧!',common_1['HttpStatus']['BAD_REQUEST']);if(_0x5a61bb===0x190&&_0x3aa5ce['includes'](_0x491829(0x9c)))throw new common_1['HttpException'](_0x491829(0xe4),common_1[_0x491829(0x87)][_0x491829(0x162)]);if(_0x5a61bb===0x190&&_0x3aa5ce[_0x491829(0x130)](_0x491829(0x110))){await this[_0x491829(0x172)][_0x491829(0x102)](_0x5170bd,_0x491829(0x6d),-0x1);throw new common_1[(_0x491829(0x168))](_0x491829(0x129),common_1['HttpStatus'][_0x491829(0x162)]);}if(_0x5a61bb===0x1f4)throw new common_1['HttpException'](_0x491829(0x157),common_1[_0x491829(0x87)][_0x491829(0x162)]);if(_0x5a61bb===0x191)throw new common_1[(_0x491829(0x168))](_0x491829(0xe9),common_1[_0x491829(0x87)]['BAD_REQUEST']);throw new common_1['HttpException']('绘制图片失败,请稍后试试吧!',common_1[_0x491829(0x87)]['BAD_REQUEST']);}}async[_0x5c5e18(0x123)](){const _0x3f4426=_0x5c5e18,_0x5c44e9=await this['gptKeysEntity'][_0x3f4426(0xb0)]({'where':{'status':0x1},'select':['id',_0x3f4426(0x15b),_0x3f4426(0x82),_0x3f4426(0xc3),_0x3f4426(0xd3),_0x3f4426(0x13a),_0x3f4426(0xf4),_0x3f4426(0x131)]}),_0xe944f2=_0x5c44e9[_0x3f4426(0xf1)](_0x270f75=>_0x270f75[_0x3f4426(0xc3)][_0x3f4426(0x130)](_0x3f4426(0x11e))),_0x113615=_0x5c44e9[_0x3f4426(0xf1)](_0x1007e7=>_0x1007e7['model'][_0x3f4426(0x130)](_0x3f4426(0x149)));this['keyPool']={'list3':_0xe944f2,'list4':_0x113615};}async[_0x5c5e18(0x6f)](_0x52bf81){const _0xb54738=_0x5c5e18,_0x520a5d=await this['globalConfigService'][_0xb54738(0x91)]([_0xb54738(0x175)]);return(_0x52bf81===null||_0x52bf81===void 0x0?void 0x0:_0x52bf81[_0xb54738(0x94)])||_0x520a5d||_0xb54738(0x8b);}async[_0x5c5e18(0x167)](_0xaefec7){const _0x49db58=_0x5c5e18,{openaiModel3MaxTokens:openaiModel3MaxTokens=0x0,openaiModel3MaxTokensRes:openaiModel3MaxTokensRes=0x0,openaiModel3MaxTokens16k:openaiModel3MaxTokens16k=0x0,openaiModel3MaxTokens16kRes:openaiModel3MaxTokens16kRes=0x0,openaiModel4MaxTokens:openaiModel4MaxTokens=0x0,openaiModel4MaxTokensRes:openaiModel4MaxTokensRes=0x0,openaiModel4MaxTokens32k:openaiModel4MaxTokens32k=0x0,openaiModel4MaxTokens32kRes:openaiModel4MaxTokens32kRes=0x0,openaiBaseUrl:openaiBaseUrl=''}=await this['globalConfigService'][_0x49db58(0x91)]([_0x49db58(0xd1),_0x49db58(0x14f),_0x49db58(0xd0),_0x49db58(0xb3),'openaiModel4MaxTokens','openaiModel4MaxTokensRes',_0x49db58(0xee),_0x49db58(0x92),_0x49db58(0x175)]);let _0x200dd3=null,_0x503377=null,_0x3d434a=null,{model:_0x5496f3,maxModelTokens:maxModelTokens=0x0,maxResponseTokens:maxResponseTokens=0x0,proxyUrl:proxyUrl='',key:_0x435b17}=_0xaefec7;return _0x5496f3[_0x49db58(0x71)]()['includes']('gpt-4')&&(maxModelTokens>=0x2000&&(maxModelTokens=0x2000),_0x503377>=0x1000&&(maxModelTokens=0x1000),_0x200dd3=maxModelTokens||openaiModel4MaxTokens||0x2000,_0x503377=maxResponseTokens||openaiModel4MaxTokensRes||0x1000,_0x5496f3[_0x49db58(0x71)]()[_0x49db58(0x130)](_0x49db58(0x132))&&(maxModelTokens>=0x8000&&(maxModelTokens=0x8000),_0x503377>=0x4000&&(maxModelTokens=0x4000),_0x200dd3=maxModelTokens||openaiModel4MaxTokens32k||0x8000,_0x503377=maxResponseTokens||openaiModel4MaxTokens32kRes||0x4000),_0x5496f3[_0x49db58(0x71)]()[_0x49db58(0x130)](_0x49db58(0x125))&&(maxModelTokens>=0x3ffc&&(maxModelTokens=0x3ffc),_0x503377>=0x1000&&(maxModelTokens=0x1000),_0x200dd3=maxModelTokens||0x3ffc,_0x503377=maxResponseTokens||0x1000)),_0x5496f3[_0x49db58(0x71)]()[_0x49db58(0x130)](_0x49db58(0x11e))&&(maxModelTokens>=0x1000&&(maxModelTokens=0x1000),_0x503377>=0x7d0&&(maxModelTokens=0x7d0),_0x200dd3=maxModelTokens||openaiModel3MaxTokens||0x1000,_0x503377=maxResponseTokens||openaiModel3MaxTokensRes||0x7d0,_0x5496f3[_0x49db58(0x71)]()[_0x49db58(0x130)](_0x49db58(0x144))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x503377>=0x2000&&(maxModelTokens=0x2000),_0x200dd3=maxModelTokens||openaiModel3MaxTokens16k||0x4000,_0x503377=maxResponseTokens||openaiModel3MaxTokens16kRes||0x2000),_0x5496f3['toLowerCase']()[_0x49db58(0x130)](_0x49db58(0x125))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x503377>=0x1000&&(maxModelTokens=0x1000),_0x200dd3=maxModelTokens||0x4000,_0x503377=maxResponseTokens||0x1000)),_0x3d434a=proxyUrl||openaiBaseUrl||_0x49db58(0x8b),_0x503377>=_0x200dd3&&(_0x503377=Math[_0x49db58(0xb6)](_0x200dd3/0x2)),{'key':_0x435b17,'maxToken':_0x200dd3,'maxTokenRes':_0x503377,'proxyResUrl':_0x3d434a};}async[_0x5c5e18(0x69)](_0x1a452c,_0xbebfce){const _0xd28091=_0x5c5e18;try{const {name:_0x40d198,icon:_0x3a8e91,order:_0x1257ae,id:_0x10e377,status:_0xab1484}=_0xbebfce;return _0x10e377?await this[_0xd28091(0x12d)][_0xd28091(0x7e)]({'id':_0x10e377},{'name':_0x40d198,'icon':_0x3a8e91,'order':_0x1257ae,'status':_0xab1484}):await this['chatBoxTypeEntity'][_0xd28091(0x16e)]({'name':_0x40d198,'icon':_0x3a8e91,'order':_0x1257ae,'status':_0xab1484});}catch(_0x103796){console[_0xd28091(0x98)](_0xd28091(0x166),_0x103796);}}async['delChatBoxType'](_0x837ff1,_0x1107c9){const _0x2f80fa=_0x5c5e18,{id:_0x4b74c4}=_0x1107c9;if(!_0x4b74c4)throw new common_1[(_0x2f80fa(0x168))](_0x2f80fa(0xc1),common_1[_0x2f80fa(0x87)][_0x2f80fa(0x162)]);const _0x3df69f=await this[_0x2f80fa(0x73)][_0x2f80fa(0x8e)]({'where':{'typeId':_0x4b74c4}});if(_0x3df69f)throw new common_1[(_0x2f80fa(0x168))](_0x2f80fa(0x97),common_1[_0x2f80fa(0x87)]['BAD_REQUEST']);return await this[_0x2f80fa(0x12d)][_0x2f80fa(0x13e)]({'id':_0x4b74c4});}async[_0x5c5e18(0xca)](){const _0x5adff6=_0x5c5e18;return await this[_0x5adff6(0x12d)][_0x5adff6(0xb0)]({'order':{'order':'DESC'}});}async['setChatBox'](_0x536266,_0x7f4c32){const _0xb2dc17=_0x5c5e18,{title:_0x546db4,prompt:_0x70aa35,appId:_0x4b40b7,order:_0x175336,status:_0xc99c4f,typeId:_0x5381d4,id:_0x1d7c8a,url:_0x350c76}=_0x7f4c32;if(!_0x5381d4)throw new common_1[(_0xb2dc17(0x168))]('缺失必要参数!',common_1['HttpStatus'][_0xb2dc17(0x162)]);try{const _0x15caaf={'title':_0x546db4,'order':_0x175336,'status':_0xc99c4f,'typeId':_0x5381d4,'url':_0x350c76};return _0x15caaf[_0xb2dc17(0x88)]=_0x4b40b7||0x0,_0x15caaf[_0xb2dc17(0xd8)]=_0x70aa35||'',_0x1d7c8a?await this[_0xb2dc17(0x73)][_0xb2dc17(0x7e)]({'id':_0x1d7c8a},_0x15caaf):await this[_0xb2dc17(0x73)]['save'](_0x15caaf);}catch(_0x492d22){console['log'](_0xb2dc17(0x166),_0x492d22);}}async[_0x5c5e18(0x139)](_0x1bd921,_0x4ff8c4){const _0x5b73c3=_0x5c5e18,{id:_0x4759e4}=_0x4ff8c4;if(!_0x4759e4)throw new common_1[(_0x5b73c3(0x168))](_0x5b73c3(0xc1),common_1[_0x5b73c3(0x87)][_0x5b73c3(0x162)]);return await this[_0x5b73c3(0x73)][_0x5b73c3(0x13e)]({'id':_0x4759e4});}async[_0x5c5e18(0x128)](){const _0x296f00=_0x5c5e18,_0x2c9ca2=await this[_0x296f00(0x73)]['find']({'order':{'order':'DESC'}}),_0x323478=[...new Set(_0x2c9ca2[_0x296f00(0x117)](_0x432da2=>_0x432da2['typeId']))],_0x9414b5=[...new Set(_0x2c9ca2[_0x296f00(0x117)](_0x5a3345=>_0x5a3345['appId']))],_0x3ba095=await this['chatBoxTypeEntity'][_0x296f00(0xb0)]({'where':{'id':(0x0,typeorm_1['In'])(_0x323478)}}),_0x479e88=await this[_0x296f00(0xbc)][_0x296f00(0xb0)]({'where':{'id':(0x0,typeorm_1['In'])(_0x9414b5)}});return _0x2c9ca2[_0x296f00(0x117)](_0x5d9a44=>{const _0x13dfed=_0x296f00,{typeId:_0x392359,appId:_0x39ea3e}=_0x5d9a44;return _0x5d9a44[_0x13dfed(0x7d)]=_0x3ba095[_0x13dfed(0xb0)](_0x248537=>_0x248537['id']===_0x392359),_0x5d9a44[_0x13dfed(0x15d)]=_0x479e88[_0x13dfed(0xb0)](_0xa1e4f2=>_0xa1e4f2['id']===_0x39ea3e),_0x5d9a44;});}async[_0x5c5e18(0x159)](){const _0x4eb2ef=_0x5c5e18,_0x4e94a9=await this[_0x4eb2ef(0x12d)]['find']({'order':{'order':'DESC'},'where':{'status':!![]}}),_0x34c1d1=await this[_0x4eb2ef(0x73)][_0x4eb2ef(0xb0)]({'where':{'status':!![]}}),_0x41b8cc=[...new Set(_0x34c1d1['map'](_0x1f9eee=>_0x1f9eee['appId']))],_0x4eafe7=await this[_0x4eb2ef(0xbc)][_0x4eb2ef(0xb0)]({'where':{'id':(0x0,typeorm_1['In'])(_0x41b8cc)}});return _0x34c1d1[_0x4eb2ef(0xcc)](_0x20a957=>{const _0x68ba65=_0x4eb2ef,_0xaf337a=_0x4eafe7['find'](_0x2dbbf5=>_0x2dbbf5['id']===_0x20a957['appId']);return _0x20a957[_0x68ba65(0xa9)]=_0xaf337a===null||_0xaf337a===void 0x0?void 0x0:_0xaf337a[_0x68ba65(0xa9)],_0x20a957;}),_0x4e94a9[_0x4eb2ef(0x117)](_0x2ad185=>{const _0x42ac2d=_0x4eb2ef;return _0x2ad185['childList']=_0x34c1d1['filter'](_0x333c75=>_0x333c75['typeId']===_0x2ad185['id']&&_0x333c75[_0x42ac2d(0x112)]),_0x2ad185;});}async[_0x5c5e18(0xbf)](_0x136422,_0x54a038){const _0x331c30=_0x5c5e18;try{const {name:_0x510e62,icon:_0x1d7696,order:_0x469751,id:_0x1307bb,status:_0x549316}=_0x54a038;return _0x1307bb?await this[_0x331c30(0xfd)][_0x331c30(0x7e)]({'id':_0x1307bb},{'name':_0x510e62,'icon':_0x1d7696,'order':_0x469751,'status':_0x549316}):await this[_0x331c30(0xfd)]['save']({'name':_0x510e62,'icon':_0x1d7696,'order':_0x469751,'status':_0x549316});}catch(_0x1d20ad){console['log'](_0x331c30(0x166),_0x1d20ad);}}async[_0x5c5e18(0x9f)](_0x12fe31,_0x15b7ec){const _0x19e77c=_0x5c5e18,{id:_0x384e28}=_0x15b7ec;if(!_0x384e28)throw new common_1[(_0x19e77c(0x168))](_0x19e77c(0xc1),common_1[_0x19e77c(0x87)][_0x19e77c(0x162)]);const _0x378dbc=await this[_0x19e77c(0x73)][_0x19e77c(0x8e)]({'where':{'typeId':_0x384e28}});if(_0x378dbc)throw new common_1[(_0x19e77c(0x168))]('当前分类下有未处理数据不可移除!',common_1[_0x19e77c(0x87)][_0x19e77c(0x162)]);return await this['chatPreTypeEntity']['delete']({'id':_0x384e28});}async[_0x5c5e18(0xf6)](){const _0x5969ba=_0x5c5e18;return await this[_0x5969ba(0xfd)]['find']({'order':{'order':'DESC'}});}async[_0x5c5e18(0x173)](_0x14e787,_0x5afe61){const _0xc721d8=_0x5c5e18,{title:_0x107197,prompt:_0x27b78d,appId:_0x1ebf0c,order:_0x1a3129,status:_0x366402,typeId:_0x3fd5b6,id:_0x1e71eb,url:_0x3fb1dd}=_0x5afe61;if(!_0x3fd5b6)throw new common_1[(_0xc721d8(0x168))](_0xc721d8(0x12c),common_1[_0xc721d8(0x87)]['BAD_REQUEST']);try{const _0x5453dc={'title':_0x107197,'prompt':_0x27b78d,'order':_0x1a3129,'status':_0x366402,'typeId':_0x3fd5b6,'url':_0x3fb1dd};return _0x1e71eb?await this[_0xc721d8(0x127)][_0xc721d8(0x7e)]({'id':_0x1e71eb},_0x5453dc):await this[_0xc721d8(0x127)][_0xc721d8(0x16e)](_0x5453dc);}catch(_0x4b40ad){console[_0xc721d8(0x98)]('error:\x20',_0x4b40ad);}}async[_0x5c5e18(0xfc)](_0x31a4d9,_0x4aa1cc){const _0x6436f7=_0x5c5e18,{id:_0x40109f}=_0x4aa1cc;if(!_0x40109f)throw new common_1[(_0x6436f7(0x168))](_0x6436f7(0xc1),common_1[_0x6436f7(0x87)][_0x6436f7(0x162)]);return await this[_0x6436f7(0x127)][_0x6436f7(0x13e)]({'id':_0x40109f});}async[_0x5c5e18(0x169)](){const _0x2b91f4=_0x5c5e18,_0x1b3c4e=await this[_0x2b91f4(0x127)][_0x2b91f4(0xb0)]({'order':{'order':_0x2b91f4(0xb2)}}),_0x556e49=[...new Set(_0x1b3c4e[_0x2b91f4(0x117)](_0x50cccd=>_0x50cccd[_0x2b91f4(0x76)]))],_0x176655=await this['chatPreTypeEntity'][_0x2b91f4(0xb0)]({'where':{'id':(0x0,typeorm_1['In'])(_0x556e49)}});return _0x1b3c4e[_0x2b91f4(0x117)](_0x4aa02a=>{const _0x93fd21=_0x2b91f4,{typeId:_0x2180dd,appId:_0x517f03}=_0x4aa02a;return _0x4aa02a[_0x93fd21(0x7d)]=_0x176655['find'](_0x7c4ab9=>_0x7c4ab9['id']===_0x2180dd),_0x4aa02a;});}async[_0x5c5e18(0x14b)](){const _0x13c6a9=_0x5c5e18,_0x2ccaa7=await this[_0x13c6a9(0xfd)][_0x13c6a9(0xb0)]({'order':{'order':_0x13c6a9(0xb2)},'where':{'status':!![]}}),_0xb6a78f=await this[_0x13c6a9(0x127)][_0x13c6a9(0xb0)]({'where':{'status':!![]}});return _0x2ccaa7['map'](_0x2ff144=>{const _0x19076f=_0x13c6a9;return _0x2ff144[_0x19076f(0x119)]=_0xb6a78f['filter'](_0x59040d=>_0x59040d[_0x19076f(0x76)]===_0x2ff144['id']&&_0x59040d['status']),_0x2ff144;});}async[_0x5c5e18(0xf8)](_0x550a4d,_0x497db4,_0x4e7edb){const _0x7ab2bb=_0x5c5e18;let _0x40f3d6=0x1000,_0x41c63f=0x800;return _0x550a4d[_0x7ab2bb(0x71)]()[_0x7ab2bb(0x130)](_0x7ab2bb(0x149))&&(_0x40f3d6=_0x497db4>=0x2004?0x2004:_0x497db4,_0x41c63f=_0x4e7edb>=0x1000?0x1000:_0x4e7edb,_0x550a4d[_0x7ab2bb(0x71)]()[_0x7ab2bb(0x130)]('32k')&&(_0x40f3d6=_0x497db4>=0x8000?0x8000:_0x497db4,_0x41c63f=_0x4e7edb>=0x3e80?0x3e80:_0x4e7edb),(_0x550a4d[_0x7ab2bb(0x71)]()['includes'](_0x7ab2bb(0x163))||_0x550a4d[_0x7ab2bb(0x71)]()[_0x7ab2bb(0x130)](_0x7ab2bb(0x145)))&&(_0x40f3d6=_0x497db4>=0x1f400?0x1f400:_0x497db4,_0x41c63f=_0x4e7edb>=0x1000?0x1000:_0x4e7edb)),_0x550a4d[_0x7ab2bb(0x71)]()[_0x7ab2bb(0x130)](_0x7ab2bb(0x11e))&&(_0x40f3d6=_0x497db4>=0x1000?0x1000:_0x497db4,_0x41c63f=_0x4e7edb>=0x800?0x800:_0x4e7edb,_0x550a4d['toLowerCase']()[_0x7ab2bb(0x130)](_0x7ab2bb(0x144))&&(_0x40f3d6=_0x497db4>=0x4000?0x4000:_0x497db4,_0x41c63f=_0x4e7edb>=0x1f40?0x1f40:_0x4e7edb),_0x550a4d['toLowerCase']()[_0x7ab2bb(0x130)](_0x7ab2bb(0x125))&&(_0x40f3d6=_0x497db4>=0x4000?0x4000:_0x497db4,_0x41c63f=_0x4e7edb>=0x1f40?0x1f40:_0x4e7edb)),{'maxToken':_0x40f3d6,'maxRes':_0x41c63f};}};ChatgptService=__decorate([(0x0,common_1[_0x5c5e18(0x124)])(),__param(0x0,(0x0,typeorm_2[_0x5c5e18(0x101)])(gptkeys_entity_1[_0x5c5e18(0x15a)])),__param(0x1,(0x0,typeorm_2[_0x5c5e18(0x101)])(config_entity_1[_0x5c5e18(0xba)])),__param(0x2,(0x0,typeorm_2[_0x5c5e18(0x101)])(chatBoxType_entity_1['ChatBoxTypeEntity'])),__param(0x3,(0x0,typeorm_2[_0x5c5e18(0x101)])(chatBox_entity_1['ChatBoxEntity'])),__param(0x4,(0x0,typeorm_2[_0x5c5e18(0x101)])(app_entity_1['AppEntity'])),__param(0x5,(0x0,typeorm_2['InjectRepository'])(chatPreType_entity_1[_0x5c5e18(0x177)])),__param(0x6,(0x0,typeorm_2[_0x5c5e18(0x101)])(chatPre_entity_1[_0x5c5e18(0x16d)])),__metadata(_0x5c5e18(0xbb),[typeorm_1[_0x5c5e18(0x164)],typeorm_1[_0x5c5e18(0x164)],typeorm_1['Repository'],typeorm_1[_0x5c5e18(0x164)],typeorm_1[_0x5c5e18(0x164)],typeorm_1[_0x5c5e18(0x164)],typeorm_1[_0x5c5e18(0x164)],nestjs_config_1[_0x5c5e18(0xe8)],userBalance_service_1[_0x5c5e18(0xd7)],chatLog_service_1[_0x5c5e18(0x84)],user_service_1[_0x5c5e18(0x11f)],upload_service_1[_0x5c5e18(0x154)],badwords_service_1[_0x5c5e18(0x140)],autoreply_service_1[_0x5c5e18(0x85)],globalConfig_service_1[_0x5c5e18(0xc8)],fanyi_service_1[_0x5c5e18(0x9b)],chatGroup_service_1['ChatGroupService'],models_service_1[_0x5c5e18(0x105)]])],ChatgptService),exports[_0x5c5e18(0xea)]=ChatgptService; |