mirror of
https://github.com/xiaoyiweb/YiAi.git
synced 2025-09-26 05:06:39 +08:00
1 line
43 KiB
JavaScript
1 line
43 KiB
JavaScript
'use strict';function _0x22b8(){const _0x243e87=['chat-error\x20<----------------------------------------->','onModuleInit','b64_json','defineProperty','keyPool','userBanance','setChatPre','./helper','184046riykvp','status','当前模型key已被封禁','当前流程所需要的模型已被管理员下架、请联系管理员上架专属模型!','@nestjs/common','./gptkeys.entity','../chatLog/chatLog.service','@keyv/redis','imageUrl','../../common/utils','object','openaiModel3MaxTokens','dall-e\x20draw\x20params:\x20','model','Bearer\x20','DESC','GptKeysEntity','preset','PAINT_TYPE','draw\x20paompt\x20info\x20<==**==>\x20','./zhipu','typeId','quality','gpt-3','uploadService','Incorrect\x20API\x20key\x20provided','getRandomDrawKey','configEntity','push','BAD_REQUEST','default','parse','statusText','queryUserBalance','model3','REDIS_HOST','application/octet-stream;\x20charset=utf-8','Too\x20Many\x20Requests','NineStore','response','conversationId','AppEntity','design:paramtypes','1253790yRUoid','from','decorate','686901gZvFsu','forEach','usage','weight','toLowerCase','\x20模型名称:\x20','find','当前模型key余额已耗尽、已冻结当前调用Key、尝试重新对话试试吧!','redis://','../globalConfig/globalConfig.service','ChatBoxTypeEntity','当前分类下有未处理数据不可移除!','autoreplyService','importDynamic','checkUserStatus','userService','text','getMaxTokenFromModelWithOpenAi','../../common/constants/balance.constant','error:\x20','map','write','systemMessage','badwordsService','CHAT_TYPE','./../upload/upload.service','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','nineStore','../autoreply/autoreply.service','270013DqACpR','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!','1282640OeyqLS','debug','setData','Catch\x20Error\x20','400\x20error','DeductionKey','./baidu','HttpException','chatLogService','REDIS_USER','code:\x20','typeInfo','getCurrentModelKeyInfo','1628750ZzqAhR','绘制图片失败,请稍后试试吧!','delete','error','validateBalance','unifiedFormattingResponse','all','当前Key余额已不足、请重新再试一次吧!','sendMessageFromOpenAi','appEntity','FanyiService','gpt-4-1106','../models/models.service','ChatPreTypeEntity','dall-e-3','getUuid','chatPreEntity','includes','Content-type','__param','deductFromBalance','16k','getBaseConfig','openaiModel3MaxTokens16k','close','32k','getConfigs','split','userBalanceService','appId','getRequestParams','当前模型key余额已耗尽','Billing\x20hard\x20limit\x20has\x20been\x20reached','coverImg','getModelProxyUrl','ModelsService','env','DrawService','./chatBox.entity','formatModelToken','\x0a\x20Current\x20date:\x20','Logger','PAYMENT_REQUIRED','openaiModel4MaxTokens32kRes','queryChatBoxFrontend','OpenAiErrorCodeMessage','ceil','openaiModel4MaxTokens32k','用户ID:\x20','./chatPreType.entity','fanyiService',',\x20key\x20===>\x20','addOneIfOdd','user','update','buildMessageFromParentMessageId','prompt','checkBadWords','axios','1312pPcwlZ','绘制图片失败,此次绘画被拒绝了!','The\x20OpenAI\x20account\x20associated\x20with\x20this\x20API\x20key\x20has\x20been\x20deactivated.','openaiModel3MaxTokens16kRes','getClientIp','gpt-4','model4','GlobalConfigService','result','length','InjectRepository','setChatBoxType','__decorate','systemPreMessage','configService','modelInfo','非法操作!','lockKey','ChatPreEntity','count','当前请求已过载、请稍等会儿再试试吧!','1106','queryChatPreList','toISOString','saveChatLog','uuid','gptKeysEntity','stringify','@nestjs/typeorm','UploadService','queryChatPre','你当前使用的应用已被下架、请删除当前对话开启新的对话吧!','Repository','delChatBoxType','提供了错误的模型秘钥','../app/app.entity','maxModelTokens','function','message','nestjs-config','assign','queryChatBoxType','filter','assistant','chatBoxEntity','config','openaiModel4MaxTokens','modelsService','openaiBaseUrl','ConfigService','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters','is_end','childList','HttpStatus','chat','chatPreTypeEntity','metadata','data','queryChatPreType','appInfo','BadwordsService','chatGroupService','delChatPre','UserService','end','statusCode','.png','log','dall','size','globalConfigService','getTokenCount','11228RfHBpB','setChatBox','chatBoxTypeEntity','ChatgptService','save','billing','openaiTimeoutMs','./openai','../globalConfig/config.entity','https://api.openai.com','当前模型不是聊天模型','delChatBox'];_0x22b8=function(){return _0x243e87;};return _0x22b8();}const _0x5a84e5=_0x4100;(function(_0x45145f,_0x2352cf){const _0x6829bd=_0x4100,_0x3a2275=_0x45145f();while(!![]){try{const _0x3083bf=-parseInt(_0x6829bd(0x273))/0x1+parseInt(_0x6829bd(0x228))/0x2+-parseInt(_0x6829bd(0x256))/0x3+parseInt(_0x6829bd(0x275))/0x4+parseInt(_0x6829bd(0x282))/0x5+parseInt(_0x6829bd(0x253))/0x6+parseInt(_0x6829bd(0x214))/0x7*(-parseInt(_0x6829bd(0x1cc))/0x8);if(_0x3083bf===_0x2352cf)break;else _0x3a2275['push'](_0x3a2275['shift']());}catch(_0x2804ea){_0x3a2275['push'](_0x3a2275['shift']());}}}(_0x22b8,0x2d412));function _0x4100(_0x4e7f1f,_0x566a43){const _0x22b87c=_0x22b8();return _0x4100=function(_0x410046,_0x2c662b){_0x410046=_0x410046-0x1c3;let _0xf2c8db=_0x22b87c[_0x410046];return _0xf2c8db;},_0x4100(_0x4e7f1f,_0x566a43);}var __decorate=this&&this[_0x5a84e5(0x1d8)]||function(_0x4ae00e,_0x4b9277,_0xf8431e,_0x3b3b72){const _0x3070aa=_0x5a84e5;var _0x217463=arguments[_0x3070aa(0x1d5)],_0x1ef8d9=_0x217463<0x3?_0x4b9277:_0x3b3b72===null?_0x3b3b72=Object['getOwnPropertyDescriptor'](_0x4b9277,_0xf8431e):_0x3b3b72,_0x448cca;if(typeof Reflect===_0x3070aa(0x232)&&typeof Reflect[_0x3070aa(0x255)]===_0x3070aa(0x1f1))_0x1ef8d9=Reflect[_0x3070aa(0x255)](_0x4ae00e,_0x4b9277,_0xf8431e,_0x3b3b72);else{for(var _0x12ff7c=_0x4ae00e[_0x3070aa(0x1d5)]-0x1;_0x12ff7c>=0x0;_0x12ff7c--)if(_0x448cca=_0x4ae00e[_0x12ff7c])_0x1ef8d9=(_0x217463<0x3?_0x448cca(_0x1ef8d9):_0x217463>0x3?_0x448cca(_0x4b9277,_0xf8431e,_0x1ef8d9):_0x448cca(_0x4b9277,_0xf8431e))||_0x1ef8d9;}return _0x217463>0x3&&_0x1ef8d9&&Object[_0x3070aa(0x223)](_0x4b9277,_0xf8431e,_0x1ef8d9),_0x1ef8d9;},__metadata=this&&this['__metadata']||function(_0x151752,_0x450c73){const _0x4dd535=_0x5a84e5;if(typeof Reflect===_0x4dd535(0x232)&&typeof Reflect[_0x4dd535(0x204)]===_0x4dd535(0x1f1))return Reflect[_0x4dd535(0x204)](_0x151752,_0x450c73);},__param=this&&this[_0x5a84e5(0x295)]||function(_0xe8fee1,_0x1930e0){return function(_0x258570,_0x588dca){_0x1930e0(_0x258570,_0x588dca,_0xe8fee1);};};Object[_0x5a84e5(0x223)](exports,'__esModule',{'value':!![]}),exports[_0x5a84e5(0x217)]=void 0x0;const upload_service_1=require(_0x5a84e5(0x26f)),user_service_1=require('./../user/user.service'),nestjs_config_1=require(_0x5a84e5(0x1f3)),common_1=require(_0x5a84e5(0x22c)),errorMessage_constant_1=require('../../common/constants/errorMessage.constant'),utils_1=require(_0x5a84e5(0x231)),axios_1=require(_0x5a84e5(0x1cb)),userBalance_service_1=require('../userBalance/userBalance.service'),balance_constant_1=require(_0x5a84e5(0x268)),chatLog_service_1=require(_0x5a84e5(0x22e)),uuid=require(_0x5a84e5(0x1e5)),config_entity_1=require(_0x5a84e5(0x21c)),typeorm_1=require('typeorm'),typeorm_2=require(_0x5a84e5(0x1e8)),badwords_service_1=require('../badwords/badwords.service'),autoreply_service_1=require(_0x5a84e5(0x272)),gptkeys_entity_1=require(_0x5a84e5(0x22d)),globalConfig_service_1=require(_0x5a84e5(0x25f)),fanyi_service_1=require('../fanyi/fanyi.service'),app_entity_1=require(_0x5a84e5(0x1ef)),chatGroup_service_1=require('../chatGroup/chatGroup.service'),models_service_1=require(_0x5a84e5(0x28e)),baidu_1=require(_0x5a84e5(0x27b)),helper_1=require(_0x5a84e5(0x227)),store_1=require('./store'),zhipu_1=require(_0x5a84e5(0x23c)),openai_1=require(_0x5a84e5(0x21b)),chatBoxType_entity_1=require('./chatBoxType.entity'),chatBox_entity_1=require(_0x5a84e5(0x2a8)),chatPre_entity_1=require('./chatPre.entity'),chatPreType_entity_1=require(_0x5a84e5(0x2b3));let ChatgptService=class ChatgptService{constructor(_0x4b5e30,_0x2187e3,_0x4d83cc,_0x30125c,_0x4218c1,_0x5622c6,_0x2d1e3c,_0x31201a,_0x4608b0,_0x4643f6,_0x3689f5,_0x1bfdc4,_0x3b28ff,_0x3d9000,_0x252769,_0x578a05,_0x4ff6d2,_0x3dd1d3){const _0x33d6f5=_0x5a84e5;this[_0x33d6f5(0x1e6)]=_0x4b5e30,this[_0x33d6f5(0x243)]=_0x2187e3,this[_0x33d6f5(0x216)]=_0x4d83cc,this[_0x33d6f5(0x1f8)]=_0x30125c,this[_0x33d6f5(0x28b)]=_0x4218c1,this[_0x33d6f5(0x203)]=_0x5622c6,this[_0x33d6f5(0x292)]=_0x2d1e3c,this[_0x33d6f5(0x1da)]=_0x31201a,this['userBalanceService']=_0x4608b0,this[_0x33d6f5(0x27d)]=_0x4643f6,this['userService']=_0x3689f5,this[_0x33d6f5(0x240)]=_0x1bfdc4,this[_0x33d6f5(0x26d)]=_0x3b28ff,this[_0x33d6f5(0x262)]=_0x3d9000,this['globalConfigService']=_0x252769,this[_0x33d6f5(0x1c3)]=_0x578a05,this[_0x33d6f5(0x209)]=_0x4ff6d2,this['modelsService']=_0x3dd1d3,this['nineStore']=null,this['whiteListUser']=[],this[_0x33d6f5(0x224)]={'list3':[],'list4':[]};}async[_0x5a84e5(0x221)](){const _0x4551a1=_0x5a84e5;let _0x43e61a=await(0x0,utils_1[_0x4551a1(0x263)])('chatgpt-ai-web'),_0x54bde7=await(0x0,utils_1[_0x4551a1(0x263)])(_0x4551a1(0x22f)),_0x2acc50=await(0x0,utils_1[_0x4551a1(0x263)])('keyv');_0x43e61a=(_0x43e61a===null||_0x43e61a===void 0x0?void 0x0:_0x43e61a[_0x4551a1(0x246)])?_0x43e61a[_0x4551a1(0x246)]:_0x43e61a,_0x54bde7=(_0x54bde7===null||_0x54bde7===void 0x0?void 0x0:_0x54bde7['default'])?_0x54bde7[_0x4551a1(0x246)]:_0x54bde7,_0x2acc50=(_0x2acc50===null||_0x2acc50===void 0x0?void 0x0:_0x2acc50['default'])?_0x2acc50[_0x4551a1(0x246)]:_0x2acc50;const {ChatGPTAPI:_0x13b476,ChatGPTError:_0x160b67,ChatGPTUnofficialProxyAPI:_0x525f9b}=_0x43e61a,_0x33090d=+process[_0x4551a1(0x2a6)]['REDIS_PORT'],_0x5c4f67=process[_0x4551a1(0x2a6)][_0x4551a1(0x24b)],_0x2ccdd2=process[_0x4551a1(0x2a6)]['REDIS_PASSWORD'],_0x44e426=process[_0x4551a1(0x2a6)][_0x4551a1(0x27e)],_0x256f16=_0x4551a1(0x25e)+(_0x44e426||'')+':'+(_0x2ccdd2||'')+'@'+_0x5c4f67+':'+_0x33090d,_0x33ad46=new _0x54bde7(_0x256f16),_0x5ac8a0=new _0x2acc50({'store':_0x33ad46,'namespace':'nineai-chatlog'});this[_0x4551a1(0x271)]=new store_1[(_0x4551a1(0x24e))]({'store':_0x5ac8a0,'namespace':_0x4551a1(0x202)});}async[_0x5a84e5(0x2a0)](_0x539b3e,_0x5add9c,_0x49a1aa,_0x2b67af=null){const _0x20091a=_0x5a84e5;var _0x43bbd0;!_0x2b67af&&(_0x2b67af=(_0x43bbd0=await this[_0x20091a(0x1fb)][_0x20091a(0x298)]())===null||_0x43bbd0===void 0x0?void 0x0:_0x43bbd0[_0x20091a(0x1db)]);const {timeout:timeout=0x3c}=_0x49a1aa,{topN:_0x20e8e8,model:_0x61f6fa}=_0x2b67af,{parentMessageId:parentMessageId=0x0}=_0x539b3e,_0x1b5936=await this[_0x20091a(0x212)][_0x20091a(0x29c)](['openaiTimeoutMs']),_0x5631d5=timeout*0x3e8||_0x1b5936||0x64*0x3e8,_0x36eb30={'parentMessageId':parentMessageId,'timeoutMs':+_0x5631d5,'completionParams':{'model':_0x61f6fa,'temperature':_0x20e8e8}};return _0x5add9c&&(_0x36eb30[_0x20091a(0x26c)]=_0x5add9c),_0x36eb30;}async['chatSyncFree'](_0x3cc156){const _0x31fb91=_0x5a84e5,_0x302884=await this[_0x31fb91(0x1fb)][_0x31fb91(0x242)](),_0x23d92f=await this[_0x31fb91(0x212)][_0x31fb91(0x29c)]([_0x31fb91(0x1d9)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x594f87,model:_0x487405}=_0x302884,_0x116317=await this[_0x31fb91(0x2a4)](_0x302884),{context:_0x119fc8}=await this[_0x31fb91(0x271)]['buildMessageFromParentMessageId'](_0x3cc156,{'parentMessageId':'','systemMessage':_0x23d92f});try{const _0x25b08e=await(0x0,openai_1[_0x31fb91(0x28a)])(_0x119fc8,{'apiKey':(0x0,utils_1['removeSpecialCharacters'])(_0x594f87),'model':_0x487405,'proxyUrl':_0x116317,'onProgress':null});return _0x25b08e===null||_0x25b08e===void 0x0?void 0x0:_0x25b08e[_0x31fb91(0x266)];}catch(_0x3b12ae){console[_0x31fb91(0x20f)](_0x31fb91(0x269),_0x3b12ae);}}async['chatProcess'](_0x54572c,_0x44b492,_0x355b0d){const _0x591ebb=_0x5a84e5;var _0x54e764,_0x18de57,_0x3d3b7a,_0x20bd0f;const _0x24f0eb=_0x44b492['abortController'],{options:options={},appId:_0x1401a9,cusromPrompt:_0x3a8595,systemMessage:systemMessage=''}=_0x54572c;let _0x5a6759=systemMessage;const {parentMessageId:_0x231b25}=options,{prompt:_0x1ca16e,imageUrl:_0x2d596b,model:_0x5d669a}=_0x54572c,{groupId:_0x47c118,usingNetwork:_0x253670}=options,_0x445a9b=await this['chatGroupService']['getGroupInfoFromId'](_0x47c118),_0x1386ee=(_0x445a9b===null||_0x445a9b===void 0x0?void 0x0:_0x445a9b[_0x591ebb(0x1f9)])?JSON[_0x591ebb(0x247)](_0x445a9b['config']):await this['modelsService'][_0x591ebb(0x298)](),{keyType:_0x15cd99,model:_0xd98657,topN:_0xaffb90,systemMessage:_0x2f3f91,rounds:_0x3d0e9d}=_0x1386ee[_0x591ebb(0x1db)];let _0x5918eb=null;!_0x3a8595?_0x5918eb=await this[_0x591ebb(0x1fb)]['getCurrentModelKeyInfo'](_0xd98657):_0x5918eb=await this['modelsService'][_0x591ebb(0x242)]();if(!_0x5918eb)throw new common_1[(_0x591ebb(0x27c))](_0x591ebb(0x22b),common_1['HttpStatus'][_0x591ebb(0x245)]);const {deduct:_0x43aa1d,isTokenBased:_0x4c18a0,tokenFeeRatio:_0x43c8b9,deductType:_0x37e604,key:_0x368974,secret:_0x5b96c8,modelName:_0x51ddc7,id:_0x52db76,accessToken:_0x39c27c}=_0x5918eb;await this[_0x591ebb(0x265)][_0x591ebb(0x264)](_0x44b492[_0x591ebb(0x1c6)]),await this[_0x591ebb(0x29e)][_0x591ebb(0x286)](_0x44b492,_0x37e604===0x1?_0x591ebb(0x24a):_0x591ebb(0x1d2),_0x43aa1d),_0x355b0d&&_0x355b0d['setHeader'](_0x591ebb(0x294),_0x591ebb(0x24c)),await this[_0x591ebb(0x26d)][_0x591ebb(0x1ca)](_0x1ca16e,_0x44b492['user']['id']);const _0x520a81=await this[_0x591ebb(0x262)]['checkAutoReply'](_0x1ca16e);if(_0x520a81&&_0x355b0d){const _0x4ead48={'message':_0x520a81,'code':0x1f4};return _0x355b0d[_0x591ebb(0x26b)](JSON[_0x591ebb(0x1e7)](_0x4ead48)),_0x355b0d[_0x591ebb(0x20c)]();}if(_0x1401a9){const _0x48279a=await this[_0x591ebb(0x28b)]['findOne']({'where':{'id':_0x1401a9,'status':(0x0,typeorm_1['In'])([0x1,0x3,0x4,0x5])}});if(!_0x48279a)throw new common_1[(_0x591ebb(0x27c))](_0x591ebb(0x1eb),common_1['HttpStatus'][_0x591ebb(0x245)]);_0x48279a[_0x591ebb(0x239)]&&(_0x5a6759=_0x48279a['preset']);}else{if(_0x3a8595)_0x5a6759=systemMessage;else{if(_0x2f3f91)_0x5a6759=_0x2f3f91;else{const _0x8d5370=new Date()[_0x591ebb(0x1e3)]()[_0x591ebb(0x29d)]('T')[0x0],_0x34d5ea=await this[_0x591ebb(0x212)]['getConfigs']([_0x591ebb(0x1d9)]);_0x5a6759=_0x34d5ea+(_0x591ebb(0x2aa)+_0x8d5370);}}}let _0x5a13ee='';if(_0x253670){_0x5a13ee=await(0x0,utils_1['compileNetwork'])(_0x1ca16e);const _0x549f6a=new Date()['toISOString']()[_0x591ebb(0x29d)]('T')[0x0],_0x4f5a31=await this[_0x591ebb(0x212)]['getConfigs']([_0x591ebb(0x1d9)]);_0x5a6759=_0x4f5a31+(_0x591ebb(0x2aa)+_0x549f6a);}const _0x16e050=await this[_0x591ebb(0x2a0)](options,_0x5a6759,_0x5918eb,_0x1386ee[_0x591ebb(0x1db)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x10d297}=_0x5918eb;_0x355b0d&&_0x355b0d[_0x591ebb(0x229)](0xc8);let _0x414d7a=null,_0x3b909f=null;try{if(_0x355b0d){let _0xcc12c4=null,_0x7c2dfe=![];_0x355b0d['on'](_0x591ebb(0x29a),async()=>{const _0x574843=_0x591ebb;if(_0x7c2dfe)return;_0x24f0eb['abort']();const _0x37b4bc=await(0x0,openai_1[_0x574843(0x213)])(_0x1ca16e)||0x0,_0x27d0dd=await(0x0,openai_1['getTokenCount'])(_0xcc12c4===null||_0xcc12c4===void 0x0?void 0x0:_0xcc12c4[_0x574843(0x266)])||0x0,_0x246121=_0x37b4bc+_0x27d0dd,_0x35183e=(0x0,utils_1['getClientIp'])(_0x44b492);await this['chatLogService']['saveChatLog']({'appId':_0x1401a9,'curIp':_0x35183e,'userId':_0x44b492['user']['id'],'type':balance_constant_1[_0x574843(0x27a)][_0x574843(0x26e)],'prompt':_0x1ca16e,'imageUrl':_0x2d596b,'activeModel':_0x5d669a,'answer':'','promptTokens':_0x37b4bc,'completionTokens':0x0,'totalTokens':_0x37b4bc,'model':_0xd98657,'role':_0x574843(0x1c6),'groupId':_0x47c118,'requestOptions':JSON['stringify']({'options':null,'prompt':_0x1ca16e})}),await this[_0x574843(0x27d)][_0x574843(0x1e4)]({'appId':_0x1401a9,'curIp':_0x35183e,'userId':_0x44b492[_0x574843(0x1c6)]['id'],'type':balance_constant_1[_0x574843(0x27a)][_0x574843(0x26e)],'prompt':_0x1ca16e,'answer':_0xcc12c4===null||_0xcc12c4===void 0x0?void 0x0:_0xcc12c4['text'],'promptTokens':_0x37b4bc,'completionTokens':_0x27d0dd,'totalTokens':_0x246121,'model':_0xd98657,'role':'assistant','groupId':_0x47c118,'requestOptions':JSON[_0x574843(0x1e7)]({'options':{'model':_0xd98657,'temperature':_0xaffb90},'prompt':_0x1ca16e}),'conversationOptions':JSON[_0x574843(0x1e7)]({'conversationId':_0xcc12c4===null||_0xcc12c4===void 0x0?void 0x0:_0xcc12c4[_0x574843(0x250)],'model':_0xd98657,'parentMessageId':_0xcc12c4===null||_0xcc12c4===void 0x0?void 0x0:_0xcc12c4['id'],'temperature':_0xaffb90})});let _0x2e7df5=_0x43aa1d;_0x4c18a0===!![]&&(_0x2e7df5=Math[_0x574843(0x2b0)](_0x43aa1d*_0x246121/_0x43c8b9)),await this[_0x574843(0x29e)]['deductFromBalance'](_0x44b492[_0x574843(0x1c6)]['id'],_0x574843(0x235)+(_0x37e604===0x1?0x3:0x4),_0x2e7df5,_0x246121);});if(Number(_0x15cd99)===0x1){const {key:_0x20c730,maxToken:_0x4b94a5,maxTokenRes:_0x12a2db,proxyResUrl:_0x583639}=await this[_0x591ebb(0x2a9)](_0x5918eb),{parentMessageId:_0x1f20c8,completionParams:_0xf26bbe,systemMessage:_0x329c38}=_0x16e050,{model:_0x65c33d,temperature:_0x48ad85}=_0xf26bbe,{context:_0x331d89}=await this[_0x591ebb(0x271)][_0x591ebb(0x1c8)](_0x253670?_0x5a13ee:_0x1ca16e,{'parentMessageId':_0x1f20c8,'systemMessage':_0x329c38,'maxModelToken':_0x4b94a5,'maxResponseTokens':_0x12a2db,'maxRounds':(0x0,helper_1['addOneIfOdd'])(_0x3d0e9d),'imageUrl':_0x2d596b,'activeModel':_0x5d669a});let _0x40c401=!![];_0x414d7a=await(0x0,openai_1[_0x591ebb(0x28a)])(_0x331d89,{'maxToken':_0x4b94a5,'maxTokenRes':_0x12a2db,'apiKey':_0x368974,'model':_0x65c33d,'prompt':_0x1ca16e,'activeModel':_0x5d669a,'imageUrl':_0x2d596b,'temperature':_0x48ad85,'proxyUrl':_0x583639,'onProgress':_0x7aed8f=>{const _0x2820c8=_0x591ebb;_0x355b0d[_0x2820c8(0x26b)](_0x40c401?JSON[_0x2820c8(0x1e7)](_0x7aed8f):'\x0a'+JSON[_0x2820c8(0x1e7)](_0x7aed8f)),_0xcc12c4=_0x7aed8f,_0x40c401=![];}},this[_0x591ebb(0x240)]),_0x7c2dfe=!![];}if(Number(_0x15cd99)===0x2){let _0x2a6358=!![];const {context:_0x23a38f}=await this['nineStore'][_0x591ebb(0x1c8)](_0x253670?_0x5a13ee:_0x1ca16e,{'parentMessageId':_0x231b25,'maxRounds':(0x0,helper_1['addOneIfOdd'])(_0x3d0e9d)});_0x414d7a=await(0x0,baidu_1['sendMessageFromBaidu'])(_0x253670?_0x5a13ee:_0x23a38f,{'temperature':_0xaffb90,'accessToken':_0x39c27c,'model':_0xd98657,'onProgress':_0x1d0962=>{const _0x33d571=_0x591ebb;_0x355b0d[_0x33d571(0x26b)](_0x2a6358?JSON[_0x33d571(0x1e7)](_0x1d0962):'\x0a'+JSON['stringify'](_0x1d0962)),_0x2a6358=![],_0xcc12c4=_0x1d0962;}}),_0x7c2dfe=!![];}if(Number(_0x15cd99)===0x3){let _0x2f9f51=!![];const {context:_0x3ec42a}=await this[_0x591ebb(0x271)][_0x591ebb(0x1c8)](_0x253670?_0x5a13ee:_0x1ca16e,{'parentMessageId':_0x231b25,'maxRounds':(0x0,helper_1[_0x591ebb(0x1c5)])(_0x3d0e9d)});_0x414d7a=await(0x0,zhipu_1['sendMessageFromZhipu'])(_0x253670?_0x5a13ee:_0x3ec42a,{'temperature':_0xaffb90,'key':_0x10d297,'model':_0xd98657,'onProgress':_0x42143d=>{const _0x3a3832=_0x591ebb;_0x355b0d[_0x3a3832(0x26b)](_0x2f9f51?JSON['stringify'](_0x42143d):'\x0a'+JSON['stringify'](_0x42143d)),_0x2f9f51=![],_0xcc12c4=_0x42143d;}}),_0x7c2dfe=!![];}const _0x2c5b19={'id':this[_0x591ebb(0x271)][_0x591ebb(0x291)](),'text':_0x1ca16e,'role':'user','name':undefined,'usage':null,'imageUrl':_0x2d596b,'activeModel':_0x5d669a,'parentMessageId':_0x231b25,'conversationId':_0x414d7a===null||_0x414d7a===void 0x0?void 0x0:_0x414d7a[_0x591ebb(0x250)]};_0x3b909f={'model':_0xd98657,'parentMessageId':_0x231b25},await this[_0x591ebb(0x271)]['setData'](_0x2c5b19);const _0x11f8b6={'id':_0x414d7a['id'],'text':_0x414d7a[_0x591ebb(0x266)],'role':_0x591ebb(0x1f7),'name':undefined,'usage':_0x414d7a===null||_0x414d7a===void 0x0?void 0x0:_0x414d7a['usage'],'imageUrl':_0x2d596b,'parentMessageId':_0x2c5b19['id'],'conversationId':_0x414d7a===null||_0x414d7a===void 0x0?void 0x0:_0x414d7a['conversationId']};await this[_0x591ebb(0x271)][_0x591ebb(0x277)](_0x11f8b6),_0x3b909f={'model':_0xd98657,'parentMessageId':_0x2c5b19['id']};}else{const {key:_0x310121,maxToken:_0x237b51,maxTokenRes:_0x5fb7ea,proxyResUrl:_0x168c21}=await this[_0x591ebb(0x2a9)](_0x5918eb),{parentMessageId:_0x261ec0,completionParams:_0x3f66df,systemMessage:_0x538d35}=_0x16e050,{model:_0x1b2a9d,temperature:_0x2d1524}=_0x3f66df,{context:_0x37b607}=await this['nineStore'][_0x591ebb(0x1c8)](_0x253670?_0x5a13ee:_0x1ca16e,{'parentMessageId':_0x261ec0,'systemMessage':_0x538d35,'maxRounds':(0x0,helper_1[_0x591ebb(0x1c5)])(_0x3d0e9d)});_0x414d7a=await(0x0,openai_1['sendMessageFromOpenAi'])(_0x37b607,{'apiKey':_0x368974,'model':_0x1b2a9d,'temperature':_0x2d1524,'proxyUrl':_0x168c21,'onProgress':null,'prompt':_0x1ca16e});}let _0x3bb484=null,_0x5d603e=null;_0xd98657[_0x591ebb(0x293)](_0x591ebb(0x210))?_0x3bb484=((_0x54e764=_0x414d7a['detail'])===null||_0x54e764===void 0x0?void 0x0:_0x54e764['usage'])||{'prompt_tokens':0x1,'completion_tokens':0x1,'total_tokens':0x2}:_0x5d603e=await(0x0,helper_1[_0x591ebb(0x287)])(_0x15cd99,_0x414d7a,_0x3b909f);const {prompt_tokens:_0x1aaf68,completion_tokens:_0x5553f8,total_tokens:_0x31636f}=_0xd98657[_0x591ebb(0x293)](_0x591ebb(0x210))?_0x3bb484:_0x5d603e[_0x591ebb(0x258)];let _0x470ee3=_0x43aa1d;_0x4c18a0===!![]&&(_0x470ee3=Math[_0x591ebb(0x2b0)](_0x43aa1d*_0x31636f/_0x43c8b9));await this[_0x591ebb(0x29e)]['deductFromBalance'](_0x44b492['user']['id'],_0x591ebb(0x235)+(_0x37e604===0x1?0x3:0x4),_0x470ee3,_0x31636f),await this['modelsService']['saveUseLog'](_0x52db76,_0x31636f);const _0xee6e13=(0x0,utils_1['getClientIp'])(_0x44b492);await this[_0x591ebb(0x27d)][_0x591ebb(0x1e4)]({'appId':_0x1401a9,'curIp':_0xee6e13,'userId':_0x44b492[_0x591ebb(0x1c6)]['id'],'type':balance_constant_1['DeductionKey']['CHAT_TYPE'],'prompt':_0x1ca16e,'imageUrl':_0x2d596b,'activeModel':_0x5d669a,'answer':'','promptTokens':_0x1aaf68,'completionTokens':0x0,'totalTokens':_0x31636f,'model':_0xd98657,'role':_0x591ebb(0x1c6),'groupId':_0x47c118,'requestOptions':JSON[_0x591ebb(0x1e7)]({'options':null,'prompt':_0x1ca16e})}),await this[_0x591ebb(0x27d)][_0x591ebb(0x1e4)]({'appId':_0x1401a9,'curIp':_0xee6e13,'userId':_0x44b492['user']['id'],'type':balance_constant_1['DeductionKey'][_0x591ebb(0x26e)],'prompt':_0x1ca16e,'imageUrl':_0x414d7a===null||_0x414d7a===void 0x0?void 0x0:_0x414d7a[_0x591ebb(0x230)],'answer':_0x414d7a[_0x591ebb(0x266)],'promptTokens':_0x1aaf68,'completionTokens':_0x5553f8,'totalTokens':_0x31636f,'model':_0xd98657,'role':_0x591ebb(0x1f7),'groupId':_0x47c118,'requestOptions':JSON['stringify']({'options':{'model':_0xd98657,'temperature':_0xaffb90},'prompt':_0x1ca16e}),'conversationOptions':JSON['stringify']({'conversationId':_0x414d7a[_0x591ebb(0x250)],'model':_0xd98657,'parentMessageId':_0x414d7a['id'],'temperature':_0xaffb90})}),common_1[_0x591ebb(0x2ab)][_0x591ebb(0x276)](_0x591ebb(0x2b2)+_0x44b492[_0x591ebb(0x1c6)]['id']+_0x591ebb(0x25b)+_0x51ddc7+'-'+_0x5d669a+',\x20消耗token:\x20'+_0x31636f+',\x20消耗积分:\x20'+_0x470ee3,_0x591ebb(0x217));const _0x3ee304=await this[_0x591ebb(0x29e)][_0x591ebb(0x249)](_0x44b492[_0x591ebb(0x1c6)]['id']);return _0x414d7a[_0x591ebb(0x225)]=Object[_0x591ebb(0x1f4)]({},_0x3ee304),_0x414d7a['result']&&(_0x414d7a[_0x591ebb(0x1d4)]=''),_0x414d7a[_0x591ebb(0x1ff)]=!![],_0x355b0d?_0x355b0d['write']('\x0a'+JSON[_0x591ebb(0x1e7)](_0x414d7a)):_0x414d7a[_0x591ebb(0x266)];}catch(_0x7a096f){console[_0x591ebb(0x20f)](_0x591ebb(0x220),_0x368974,_0x7a096f);const _0x469d6f=(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x20d)])||0x190,_0x48237a=((_0x18de57=_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x24f)])===null||_0x18de57===void 0x0?void 0x0:_0x18de57[_0x591ebb(0x229)])||(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f['statusCode'])||0x190;console[_0x591ebb(0x20f)]('chat-error-detail\x20\x20<----------------------------------------->',_0x591ebb(0x27f),_0x469d6f,_0x591ebb(0x1f2),_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x1f2)],'statusText:',(_0x3d3b7a=_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x24f)])===null||_0x3d3b7a===void 0x0?void 0x0:_0x3d3b7a[_0x591ebb(0x248)],_0x591ebb(0x229),(_0x20bd0f=_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x24f)])===null||_0x20bd0f===void 0x0?void 0x0:_0x20bd0f['status']);if(_0x7a096f[_0x591ebb(0x229)]&&_0x7a096f['status']===0x192){const _0x5f0fed={'message':_0x591ebb(0x278)+_0x7a096f[_0x591ebb(0x1f2)],'code':0x192};if(_0x355b0d)return _0x355b0d['write'](JSON[_0x591ebb(0x1e7)](_0x5f0fed));else throw new common_1[(_0x591ebb(0x27c))](_0x7a096f[_0x591ebb(0x1f2)],common_1['HttpStatus'][_0x591ebb(0x2ac)]);}if(!_0x48237a){if(_0x355b0d)return _0x355b0d[_0x591ebb(0x26b)](JSON[_0x591ebb(0x1e7)]({'message':_0x7a096f[_0x591ebb(0x1f2)],'code':0x1f4}));else throw new common_1[(_0x591ebb(0x27c))](_0x7a096f[_0x591ebb(0x1f2)],common_1[_0x591ebb(0x201)]['BAD_REQUEST']);}let _0x53d009=errorMessage_constant_1[_0x591ebb(0x2af)][_0x48237a]?errorMessage_constant_1[_0x591ebb(0x2af)][_0x48237a]:'服务异常、请重新试试吧!!!';(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x1f2)][_0x591ebb(0x293)](_0x591ebb(0x1ce)))&&Number(_0x15cd99)===0x1&&(await this[_0x591ebb(0x1fb)][_0x591ebb(0x1dd)](_0x52db76,_0x591ebb(0x274),-0x1),_0x53d009=_0x591ebb(0x22a));(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f['statusCode'])===0x1ad&&_0x7a096f[_0x591ebb(0x1f2)]['includes'](_0x591ebb(0x219))&&Number(_0x15cd99)===0x1&&(await this[_0x591ebb(0x1fb)][_0x591ebb(0x1dd)](_0x52db76,_0x591ebb(0x25d),-0x3),_0x53d009=_0x591ebb(0x2a1));(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x20d)])===0x1ad&&(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x248)])===_0x591ebb(0x24d)&&(_0x53d009='当前模型调用过于频繁、请重新试试吧!');(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f[_0x591ebb(0x20d)])===0x191&&_0x7a096f[_0x591ebb(0x1f2)]['includes'](_0x591ebb(0x241))&&Number(_0x15cd99)===0x1&&(await this[_0x591ebb(0x1fb)][_0x591ebb(0x1dd)](_0x52db76,_0x591ebb(0x1ee),-0x2),_0x53d009='提供了错误的模型秘钥、已冻结当前调用Key、请重新尝试对话!');(_0x7a096f===null||_0x7a096f===void 0x0?void 0x0:_0x7a096f['statusCode'])===0x194&&_0x7a096f['message']['includes']('This\x20is\x20not\x20a\x20chat\x20model\x20and\x20thus\x20not\x20supported')&&Number(_0x15cd99)===0x1&&(await this[_0x591ebb(0x1fb)][_0x591ebb(0x1dd)](_0x52db76,_0x591ebb(0x21e),-0x4),_0x53d009='当前模型不是聊天模型、已冻结当前调用Key、请重新尝试对话!');_0x469d6f===0x190&&console[_0x591ebb(0x20f)](_0x591ebb(0x279),_0x7a096f,_0x7a096f[_0x591ebb(0x1f2)]);const _0x59c9c4={'message':_0x53d009||'Please\x20check\x20the\x20back-end\x20console','code':_0x469d6f===0x191?0x190:_0x469d6f||0x1f4};if(_0x355b0d)return _0x355b0d[_0x591ebb(0x26b)](JSON[_0x591ebb(0x1e7)](_0x59c9c4));else throw new common_1[(_0x591ebb(0x27c))](_0x59c9c4[_0x591ebb(0x1f2)],common_1[_0x591ebb(0x201)][_0x591ebb(0x245)]);}finally{_0x355b0d&&_0x355b0d['end']();}}async['draw'](_0x2b3df0,_0x1d1785){const _0x1d7ef6=_0x5a84e5;var _0x2923e2,_0x3e4ec0,_0x16b54d,_0x240508;await this['badwordsService'][_0x1d7ef6(0x1ca)](_0x2b3df0['prompt'],_0x1d1785[_0x1d7ef6(0x1c6)]['id']),await this[_0x1d7ef6(0x265)][_0x1d7ef6(0x264)](_0x1d1785[_0x1d7ef6(0x1c6)]);const _0x29e0ea=(_0x2b3df0===null||_0x2b3df0===void 0x0?void 0x0:_0x2b3df0[_0x1d7ef6(0x23e)])==='hd'?0x4:0x2;await this['userBalanceService'][_0x1d7ef6(0x286)](_0x1d1785,'mjDraw',_0x29e0ea);let _0x4b3ede=[];const _0x27a6dd=await this[_0x1d7ef6(0x1fb)][_0x1d7ef6(0x281)](_0x1d7ef6(0x290)),_0x232ece=_0x27a6dd===null||_0x27a6dd===void 0x0?void 0x0:_0x27a6dd['id'],{key:_0x542921,proxyResUrl:_0x3b1785}=await this[_0x1d7ef6(0x2a9)](_0x27a6dd);common_1[_0x1d7ef6(0x2ab)][_0x1d7ef6(0x20f)](_0x1d7ef6(0x23b)+_0x2b3df0[_0x1d7ef6(0x1c9)]+_0x1d7ef6(0x1c4)+_0x542921,_0x1d7ef6(0x2a7));try{const _0x2c7b7f=_0x3b1785+'/v1/images/generations',_0x407f54=Object['assign'](Object['assign']({},_0x2b3df0),{'model':_0x1d7ef6(0x290)});console[_0x1d7ef6(0x20f)](_0x1d7ef6(0x234),_0x407f54);const _0x52091b=await axios_1[_0x1d7ef6(0x246)]['post'](_0x2c7b7f,Object['assign'](Object[_0x1d7ef6(0x1f4)]({},_0x407f54),{'response_format':_0x1d7ef6(0x222)}),{'headers':{'Authorization':_0x1d7ef6(0x236)+_0x542921}});_0x4b3ede=_0x52091b[_0x1d7ef6(0x205)][_0x1d7ef6(0x205)];const _0x1b8d0d=[];for(const _0x536968 of _0x4b3ede){const _0x4a8183=uuid['v4']()['slice'](0x0,0xa)+_0x1d7ef6(0x20e),_0x415991=Buffer[_0x1d7ef6(0x254)](_0x536968['b64_json'],'base64');_0x1b8d0d[_0x1d7ef6(0x244)](this[_0x1d7ef6(0x240)]['uploadFile']({'filename':_0x4a8183,'buffer':_0x415991}));}const _0x105fb5=await Promise[_0x1d7ef6(0x288)](_0x1b8d0d);await this[_0x1d7ef6(0x29e)][_0x1d7ef6(0x296)](_0x1d1785[_0x1d7ef6(0x1c6)]['id'],'mjDraw',(_0x407f54===null||_0x407f54===void 0x0?void 0x0:_0x407f54[_0x1d7ef6(0x23e)])==='standard'?0x2:0x4,_0x29e0ea);const _0x27078c=(0x0,utils_1[_0x1d7ef6(0x1d0)])(_0x1d1785),_0x5a78e4=[],_0x1288a7=await this['uploadService']['getUploadType'](),[_0x65b469,_0x8dba26]=_0x2b3df0[_0x1d7ef6(0x211)][_0x1d7ef6(0x29d)]('x');return _0x105fb5[_0x1d7ef6(0x257)](_0xa2a2bf=>{const _0x1127f7=_0x1d7ef6;_0x5a78e4['push'](this[_0x1127f7(0x27d)][_0x1127f7(0x1e4)]({'curIp':_0x27078c,'userId':_0x1d1785[_0x1127f7(0x1c6)]['id'],'type':balance_constant_1[_0x1127f7(0x27a)][_0x1127f7(0x23a)],'prompt':_0x2b3df0[_0x1127f7(0x1c9)],'answer':_0xa2a2bf,'fileInfo':JSON[_0x1127f7(0x1e7)]({'cosType':_0x1288a7,'width':_0x65b469,'height':_0x8dba26,'cosUrl':_0xa2a2bf}),'promptTokens':0x0,'completionTokens':0x0,'totalTokens':0x0,'model':'dall-e-3'}));}),await Promise[_0x1d7ef6(0x288)](_0x5a78e4),_0x105fb5;}catch(_0x19ba90){const _0x46a3e6=((_0x2923e2=_0x19ba90===null||_0x19ba90===void 0x0?void 0x0:_0x19ba90[_0x1d7ef6(0x24f)])===null||_0x2923e2===void 0x0?void 0x0:_0x2923e2[_0x1d7ef6(0x229)])||0x1f4;console['log']('openai-draw\x20error:\x20',JSON[_0x1d7ef6(0x1e7)](_0x19ba90),_0x542921,_0x46a3e6);const _0x42d49c=(_0x240508=(_0x16b54d=(_0x3e4ec0=_0x19ba90===null||_0x19ba90===void 0x0?void 0x0:_0x19ba90['response'])===null||_0x3e4ec0===void 0x0?void 0x0:_0x3e4ec0[_0x1d7ef6(0x205)])===null||_0x16b54d===void 0x0?void 0x0:_0x16b54d[_0x1d7ef6(0x285)])===null||_0x240508===void 0x0?void 0x0:_0x240508[_0x1d7ef6(0x1f2)];if(_0x46a3e6===0x1ad)throw new common_1[(_0x1d7ef6(0x27c))](_0x1d7ef6(0x1e0),common_1['HttpStatus'][_0x1d7ef6(0x245)]);if(_0x46a3e6===0x190&&_0x42d49c[_0x1d7ef6(0x293)](_0x1d7ef6(0x1fe)))throw new common_1[(_0x1d7ef6(0x27c))](_0x1d7ef6(0x270),common_1[_0x1d7ef6(0x201)][_0x1d7ef6(0x245)]);if(_0x46a3e6===0x190&&_0x42d49c[_0x1d7ef6(0x293)](_0x1d7ef6(0x2a2))){await this[_0x1d7ef6(0x1fb)]['lockKey'](_0x232ece,_0x1d7ef6(0x274),-0x1);throw new common_1[(_0x1d7ef6(0x27c))](_0x1d7ef6(0x289),common_1[_0x1d7ef6(0x201)][_0x1d7ef6(0x245)]);}if(_0x46a3e6===0x1f4)throw new common_1[(_0x1d7ef6(0x27c))]('绘制图片失败,请检查你的提示词是否有非法描述!',common_1[_0x1d7ef6(0x201)][_0x1d7ef6(0x245)]);if(_0x46a3e6===0x191)throw new common_1[(_0x1d7ef6(0x27c))](_0x1d7ef6(0x1cd),common_1['HttpStatus'][_0x1d7ef6(0x245)]);throw new common_1['HttpException'](_0x1d7ef6(0x283),common_1[_0x1d7ef6(0x201)][_0x1d7ef6(0x245)]);}}async['getAllKeyList'](){const _0x3b014b=_0x5a84e5,_0x3a01e1=await this[_0x3b014b(0x1e6)]['find']({'where':{'status':0x1},'select':['id','key',_0x3b014b(0x259),_0x3b014b(0x235),_0x3b014b(0x1f0),'maxResponseTokens','openaiProxyUrl',_0x3b014b(0x21a)]}),_0x2b0c47=_0x3a01e1['filter'](_0x26a878=>_0x26a878[_0x3b014b(0x235)]['includes'](_0x3b014b(0x23f))),_0x143983=_0x3a01e1[_0x3b014b(0x1f6)](_0x40ea9e=>_0x40ea9e['model'][_0x3b014b(0x293)](_0x3b014b(0x1d1)));this[_0x3b014b(0x224)]={'list3':_0x2b0c47,'list4':_0x143983};}async[_0x5a84e5(0x2a4)](_0x4bb8b2){const _0x24c50d=_0x5a84e5,_0x1ab4bc=await this[_0x24c50d(0x212)][_0x24c50d(0x29c)]([_0x24c50d(0x1fc)]);return(_0x4bb8b2===null||_0x4bb8b2===void 0x0?void 0x0:_0x4bb8b2['proxyUrl'])||_0x1ab4bc||_0x24c50d(0x21d);}async[_0x5a84e5(0x2a9)](_0x1cd7f0){const _0x5a07a2=_0x5a84e5,{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[_0x5a07a2(0x212)][_0x5a07a2(0x29c)]([_0x5a07a2(0x233),'openaiModel3MaxTokensRes',_0x5a07a2(0x299),_0x5a07a2(0x1cf),_0x5a07a2(0x1fa),'openaiModel4MaxTokensRes',_0x5a07a2(0x2b1),_0x5a07a2(0x2ad),_0x5a07a2(0x1fc)]);let _0x4bdb0f=null,_0x8e9cd3=null,_0x3a4d7a=null,{model:_0xc2079a,maxModelTokens:maxModelTokens=0x0,maxResponseTokens:maxResponseTokens=0x0,proxyUrl:proxyUrl='',key:_0xa7aa5b}=_0x1cd7f0;return _0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)](_0x5a07a2(0x1d1))&&(maxModelTokens>=0x2000&&(maxModelTokens=0x2000),_0x8e9cd3>=0x1000&&(maxModelTokens=0x1000),_0x4bdb0f=maxModelTokens||openaiModel4MaxTokens||0x2000,_0x8e9cd3=maxResponseTokens||openaiModel4MaxTokensRes||0x1000,_0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)](_0x5a07a2(0x29b))&&(maxModelTokens>=0x8000&&(maxModelTokens=0x8000),_0x8e9cd3>=0x4000&&(maxModelTokens=0x4000),_0x4bdb0f=maxModelTokens||openaiModel4MaxTokens32k||0x8000,_0x8e9cd3=maxResponseTokens||openaiModel4MaxTokens32kRes||0x4000),_0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)](_0x5a07a2(0x1e1))&&(maxModelTokens>=0x3ffc&&(maxModelTokens=0x3ffc),_0x8e9cd3>=0x1000&&(maxModelTokens=0x1000),_0x4bdb0f=maxModelTokens||0x3ffc,_0x8e9cd3=maxResponseTokens||0x1000)),_0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)](_0x5a07a2(0x23f))&&(maxModelTokens>=0x1000&&(maxModelTokens=0x1000),_0x8e9cd3>=0x7d0&&(maxModelTokens=0x7d0),_0x4bdb0f=maxModelTokens||openaiModel3MaxTokens||0x1000,_0x8e9cd3=maxResponseTokens||openaiModel3MaxTokensRes||0x7d0,_0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)](_0x5a07a2(0x297))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x8e9cd3>=0x2000&&(maxModelTokens=0x2000),_0x4bdb0f=maxModelTokens||openaiModel3MaxTokens16k||0x4000,_0x8e9cd3=maxResponseTokens||openaiModel3MaxTokens16kRes||0x2000),_0xc2079a[_0x5a07a2(0x25a)]()[_0x5a07a2(0x293)]('1106')&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x8e9cd3>=0x1000&&(maxModelTokens=0x1000),_0x4bdb0f=maxModelTokens||0x4000,_0x8e9cd3=maxResponseTokens||0x1000)),_0x3a4d7a=proxyUrl||openaiBaseUrl||_0x5a07a2(0x21d),_0x8e9cd3>=_0x4bdb0f&&(_0x8e9cd3=Math['floor'](_0x4bdb0f/0x2)),{'key':_0xa7aa5b,'maxToken':_0x4bdb0f,'maxTokenRes':_0x8e9cd3,'proxyResUrl':_0x3a4d7a};}async[_0x5a84e5(0x1d7)](_0x10b983,_0x45584e){const _0x1201cc=_0x5a84e5;try{const {name:_0x536841,icon:_0x523a6f,order:_0x51b804,id:_0x181c9d,status:_0x290817}=_0x45584e;return _0x181c9d?await this[_0x1201cc(0x216)][_0x1201cc(0x1c7)]({'id':_0x181c9d},{'name':_0x536841,'icon':_0x523a6f,'order':_0x51b804,'status':_0x290817}):await this[_0x1201cc(0x216)][_0x1201cc(0x218)]({'name':_0x536841,'icon':_0x523a6f,'order':_0x51b804,'status':_0x290817});}catch(_0x308b06){console[_0x1201cc(0x20f)](_0x1201cc(0x269),_0x308b06);}}async[_0x5a84e5(0x1ed)](_0x3cd3d3,_0x105488){const _0x1d5a49=_0x5a84e5,{id:_0x26b07f}=_0x105488;if(!_0x26b07f)throw new common_1[(_0x1d5a49(0x27c))]('非法操作!',common_1[_0x1d5a49(0x201)][_0x1d5a49(0x245)]);const _0x1a32e6=await this[_0x1d5a49(0x1f8)]['count']({'where':{'typeId':_0x26b07f}});if(_0x1a32e6)throw new common_1[(_0x1d5a49(0x27c))]('当前分类下有未处理数据不可移除!',common_1[_0x1d5a49(0x201)][_0x1d5a49(0x245)]);return await this[_0x1d5a49(0x216)][_0x1d5a49(0x284)]({'id':_0x26b07f});}async[_0x5a84e5(0x1f5)](){const _0x3adcb7=_0x5a84e5;return await this[_0x3adcb7(0x216)][_0x3adcb7(0x25c)]({'order':{'order':'DESC'}});}async[_0x5a84e5(0x215)](_0x2347d2,_0xbaffaa){const _0x129278=_0x5a84e5,{title:_0x554830,prompt:_0x1704b4,appId:_0x37c9cc,order:_0x1ec5fe,status:_0x597559,typeId:_0x3a31ba,id:_0x363c05,url:_0x4a6248}=_0xbaffaa;if(!_0x3a31ba)throw new common_1['HttpException']('缺失必要参数!',common_1['HttpStatus'][_0x129278(0x245)]);try{const _0x4ef214={'title':_0x554830,'order':_0x1ec5fe,'status':_0x597559,'typeId':_0x3a31ba,'url':_0x4a6248};return _0x4ef214[_0x129278(0x29f)]=_0x37c9cc||0x0,_0x4ef214['prompt']=_0x1704b4||'',_0x363c05?await this[_0x129278(0x1f8)][_0x129278(0x1c7)]({'id':_0x363c05},_0x4ef214):await this[_0x129278(0x1f8)][_0x129278(0x218)](_0x4ef214);}catch(_0x56fc75){console[_0x129278(0x20f)](_0x129278(0x269),_0x56fc75);}}async[_0x5a84e5(0x21f)](_0x3a1151,_0x5201ce){const _0x3c7674=_0x5a84e5,{id:_0x161e87}=_0x5201ce;if(!_0x161e87)throw new common_1[(_0x3c7674(0x27c))](_0x3c7674(0x1dc),common_1['HttpStatus'][_0x3c7674(0x245)]);return await this[_0x3c7674(0x1f8)][_0x3c7674(0x284)]({'id':_0x161e87});}async['queryChatBox'](){const _0x17b1ef=_0x5a84e5,_0x103606=await this[_0x17b1ef(0x1f8)]['find']({'order':{'order':_0x17b1ef(0x237)}}),_0x1199af=[...new Set(_0x103606['map'](_0x42a46d=>_0x42a46d[_0x17b1ef(0x23d)]))],_0x2d7427=[...new Set(_0x103606[_0x17b1ef(0x26a)](_0x20113c=>_0x20113c[_0x17b1ef(0x29f)]))],_0x449f9b=await this[_0x17b1ef(0x216)][_0x17b1ef(0x25c)]({'where':{'id':(0x0,typeorm_1['In'])(_0x1199af)}}),_0x3d2c9a=await this['appEntity'][_0x17b1ef(0x25c)]({'where':{'id':(0x0,typeorm_1['In'])(_0x2d7427)}});return _0x103606[_0x17b1ef(0x26a)](_0x23a44b=>{const _0x285194=_0x17b1ef,{typeId:_0x30fc89,appId:_0xa1cda3}=_0x23a44b;return _0x23a44b[_0x285194(0x280)]=_0x449f9b[_0x285194(0x25c)](_0x51f5df=>_0x51f5df['id']===_0x30fc89),_0x23a44b[_0x285194(0x207)]=_0x3d2c9a[_0x285194(0x25c)](_0x2f7abc=>_0x2f7abc['id']===_0xa1cda3),_0x23a44b;});}async[_0x5a84e5(0x2ae)](){const _0x52018f=_0x5a84e5,_0x30580a=await this[_0x52018f(0x216)]['find']({'order':{'order':_0x52018f(0x237)},'where':{'status':!![]}}),_0x449d73=await this[_0x52018f(0x1f8)]['find']({'where':{'status':!![]}}),_0x32dace=[...new Set(_0x449d73[_0x52018f(0x26a)](_0x4c90eb=>_0x4c90eb[_0x52018f(0x29f)]))],_0x2693f8=await this[_0x52018f(0x28b)][_0x52018f(0x25c)]({'where':{'id':(0x0,typeorm_1['In'])(_0x32dace)}});return _0x449d73[_0x52018f(0x257)](_0x32fc70=>{const _0x1d0ea8=_0x52018f,_0x22664d=_0x2693f8[_0x1d0ea8(0x25c)](_0x3b94ad=>_0x3b94ad['id']===_0x32fc70[_0x1d0ea8(0x29f)]);return _0x32fc70[_0x1d0ea8(0x2a3)]=_0x22664d===null||_0x22664d===void 0x0?void 0x0:_0x22664d[_0x1d0ea8(0x2a3)],_0x32fc70;}),_0x30580a['map'](_0x88dc44=>{const _0x49ebac=_0x52018f;return _0x88dc44['childList']=_0x449d73[_0x49ebac(0x1f6)](_0x43c738=>_0x43c738[_0x49ebac(0x23d)]===_0x88dc44['id']&&_0x43c738[_0x49ebac(0x229)]),_0x88dc44;});}async['setChatPreType'](_0x1106c0,_0x3aacba){const _0x1ddf00=_0x5a84e5;try{const {name:_0x3047f8,icon:_0x183070,order:_0x4fcdc8,id:_0xbc7339,status:_0x48d43d}=_0x3aacba;return _0xbc7339?await this[_0x1ddf00(0x203)][_0x1ddf00(0x1c7)]({'id':_0xbc7339},{'name':_0x3047f8,'icon':_0x183070,'order':_0x4fcdc8,'status':_0x48d43d}):await this['chatPreTypeEntity'][_0x1ddf00(0x218)]({'name':_0x3047f8,'icon':_0x183070,'order':_0x4fcdc8,'status':_0x48d43d});}catch(_0x2fe9f2){console[_0x1ddf00(0x20f)](_0x1ddf00(0x269),_0x2fe9f2);}}async['delChatPreType'](_0x369e0e,_0x1ac542){const _0x471fa7=_0x5a84e5,{id:_0x35c16f}=_0x1ac542;if(!_0x35c16f)throw new common_1['HttpException'](_0x471fa7(0x1dc),common_1[_0x471fa7(0x201)][_0x471fa7(0x245)]);const _0x58c105=await this[_0x471fa7(0x1f8)][_0x471fa7(0x1df)]({'where':{'typeId':_0x35c16f}});if(_0x58c105)throw new common_1['HttpException'](_0x471fa7(0x261),common_1['HttpStatus'][_0x471fa7(0x245)]);return await this[_0x471fa7(0x203)]['delete']({'id':_0x35c16f});}async[_0x5a84e5(0x206)](){const _0x26a66a=_0x5a84e5;return await this[_0x26a66a(0x203)]['find']({'order':{'order':_0x26a66a(0x237)}});}async[_0x5a84e5(0x226)](_0x989a23,_0x31de6d){const _0x3d69d9=_0x5a84e5,{title:_0x39f3d2,prompt:_0x38ad30,appId:_0x300bc9,order:_0x137009,status:_0x474148,typeId:_0x37cb2c,id:_0x90d8e5,url:_0x50e006}=_0x31de6d;if(!_0x37cb2c)throw new common_1['HttpException']('缺失必要参数!',common_1['HttpStatus'][_0x3d69d9(0x245)]);try{const _0xac3609={'title':_0x39f3d2,'prompt':_0x38ad30,'order':_0x137009,'status':_0x474148,'typeId':_0x37cb2c,'url':_0x50e006};return _0x90d8e5?await this[_0x3d69d9(0x292)][_0x3d69d9(0x1c7)]({'id':_0x90d8e5},_0xac3609):await this['chatPreEntity']['save'](_0xac3609);}catch(_0x4b9b9e){console[_0x3d69d9(0x20f)](_0x3d69d9(0x269),_0x4b9b9e);}}async[_0x5a84e5(0x20a)](_0x313998,_0x85b90c){const _0x2ce64b=_0x5a84e5,{id:_0x31f278}=_0x85b90c;if(!_0x31f278)throw new common_1['HttpException'](_0x2ce64b(0x1dc),common_1['HttpStatus'][_0x2ce64b(0x245)]);return await this[_0x2ce64b(0x292)]['delete']({'id':_0x31f278});}async[_0x5a84e5(0x1ea)](){const _0x36e41e=_0x5a84e5,_0x375a21=await this[_0x36e41e(0x292)]['find']({'order':{'order':'DESC'}}),_0x57693d=[...new Set(_0x375a21[_0x36e41e(0x26a)](_0x4eb63e=>_0x4eb63e[_0x36e41e(0x23d)]))],_0x27e2a1=await this[_0x36e41e(0x203)][_0x36e41e(0x25c)]({'where':{'id':(0x0,typeorm_1['In'])(_0x57693d)}});return _0x375a21[_0x36e41e(0x26a)](_0x1e5f42=>{const _0x2c8a98=_0x36e41e,{typeId:_0x487927,appId:_0x5f141d}=_0x1e5f42;return _0x1e5f42[_0x2c8a98(0x280)]=_0x27e2a1['find'](_0x2cd3d7=>_0x2cd3d7['id']===_0x487927),_0x1e5f42;});}async[_0x5a84e5(0x1e2)](){const _0x59bda3=_0x5a84e5,_0x4576bc=await this[_0x59bda3(0x203)][_0x59bda3(0x25c)]({'order':{'order':_0x59bda3(0x237)},'where':{'status':!![]}}),_0xeafb21=await this['chatPreEntity']['find']({'where':{'status':!![]}});return _0x4576bc[_0x59bda3(0x26a)](_0x2de7a2=>{const _0x514829=_0x59bda3;return _0x2de7a2[_0x514829(0x200)]=_0xeafb21[_0x514829(0x1f6)](_0x593277=>_0x593277[_0x514829(0x23d)]===_0x2de7a2['id']&&_0x593277[_0x514829(0x229)]),_0x2de7a2;});}async[_0x5a84e5(0x267)](_0x2456e0,_0x5db947,_0x3a4502){const _0x34dfe3=_0x5a84e5;let _0x5b94d0=0x1000,_0x5ba1fb=0x800;return _0x2456e0[_0x34dfe3(0x25a)]()[_0x34dfe3(0x293)](_0x34dfe3(0x1d1))&&(_0x5b94d0=_0x5db947>=0x2004?0x2004:_0x5db947,_0x5ba1fb=_0x3a4502>=0x1000?0x1000:_0x3a4502,_0x2456e0[_0x34dfe3(0x25a)]()[_0x34dfe3(0x293)](_0x34dfe3(0x29b))&&(_0x5b94d0=_0x5db947>=0x8000?0x8000:_0x5db947,_0x5ba1fb=_0x3a4502>=0x3e80?0x3e80:_0x3a4502),(_0x2456e0[_0x34dfe3(0x25a)]()['includes'](_0x34dfe3(0x28d))||_0x2456e0['toLowerCase']()[_0x34dfe3(0x293)]('gpt-4-vision-preview'))&&(_0x5b94d0=_0x5db947>=0x1f400?0x1f400:_0x5db947,_0x5ba1fb=_0x3a4502>=0x1000?0x1000:_0x3a4502)),_0x2456e0[_0x34dfe3(0x25a)]()[_0x34dfe3(0x293)](_0x34dfe3(0x23f))&&(_0x5b94d0=_0x5db947>=0x1000?0x1000:_0x5db947,_0x5ba1fb=_0x3a4502>=0x800?0x800:_0x3a4502,_0x2456e0['toLowerCase']()[_0x34dfe3(0x293)](_0x34dfe3(0x297))&&(_0x5b94d0=_0x5db947>=0x4000?0x4000:_0x5db947,_0x5ba1fb=_0x3a4502>=0x1f40?0x1f40:_0x3a4502),_0x2456e0[_0x34dfe3(0x25a)]()[_0x34dfe3(0x293)]('1106')&&(_0x5b94d0=_0x5db947>=0x4000?0x4000:_0x5db947,_0x5ba1fb=_0x3a4502>=0x1f40?0x1f40:_0x3a4502)),{'maxToken':_0x5b94d0,'maxRes':_0x5ba1fb};}};ChatgptService=__decorate([(0x0,common_1['Injectable'])(),__param(0x0,(0x0,typeorm_2[_0x5a84e5(0x1d6)])(gptkeys_entity_1[_0x5a84e5(0x238)])),__param(0x1,(0x0,typeorm_2[_0x5a84e5(0x1d6)])(config_entity_1['ConfigEntity'])),__param(0x2,(0x0,typeorm_2[_0x5a84e5(0x1d6)])(chatBoxType_entity_1[_0x5a84e5(0x260)])),__param(0x3,(0x0,typeorm_2[_0x5a84e5(0x1d6)])(chatBox_entity_1['ChatBoxEntity'])),__param(0x4,(0x0,typeorm_2[_0x5a84e5(0x1d6)])(app_entity_1[_0x5a84e5(0x251)])),__param(0x5,(0x0,typeorm_2['InjectRepository'])(chatPreType_entity_1[_0x5a84e5(0x28f)])),__param(0x6,(0x0,typeorm_2['InjectRepository'])(chatPre_entity_1[_0x5a84e5(0x1de)])),__metadata(_0x5a84e5(0x252),[typeorm_1['Repository'],typeorm_1[_0x5a84e5(0x1ec)],typeorm_1[_0x5a84e5(0x1ec)],typeorm_1[_0x5a84e5(0x1ec)],typeorm_1[_0x5a84e5(0x1ec)],typeorm_1[_0x5a84e5(0x1ec)],typeorm_1[_0x5a84e5(0x1ec)],nestjs_config_1[_0x5a84e5(0x1fd)],userBalance_service_1['UserBalanceService'],chatLog_service_1['ChatLogService'],user_service_1[_0x5a84e5(0x20b)],upload_service_1[_0x5a84e5(0x1e9)],badwords_service_1[_0x5a84e5(0x208)],autoreply_service_1['AutoreplyService'],globalConfig_service_1[_0x5a84e5(0x1d3)],fanyi_service_1[_0x5a84e5(0x28c)],chatGroup_service_1['ChatGroupService'],models_service_1[_0x5a84e5(0x2a5)]])],ChatgptService),exports[_0x5a84e5(0x217)]=ChatgptService; |