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

1 line
44 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 _0x32fb10=_0x47d0;function _0x547a(){const _0x43f3e8=['getCurrentModelKeyInfo','nineStore','draw\x20paompt\x20info\x20<==**==>\x20','getOwnPropertyDescriptor','autoreplyService','queryChatPreList','setHeader','error','lockKey','../globalConfig/config.entity','find','statusText','getRequestParams','end','ChatBoxEntity','chatGroupService','openai-draw\x20error:\x20','AppEntity','\x20模型名称:\x20','assistant','count','PAYMENT_REQUIRED','270oJhnAf','../autoreply/autoreply.service','from','chatLogService','ModelsService','191354voJAdC','InjectRepository','dall-e-3','1106','getUploadType','includes','openaiProxyUrl','b64_json','setData','chat-error\x20<----------------------------------------->','statusCode','parse','write','all','../fanyi/fanyi.service','standard','./../upload/upload.service','The\x20OpenAI\x20account\x20associated\x20with\x20this\x20API\x20key\x20has\x20been\x20deactivated.','dall','openaiModel3MaxTokensRes','非法操作!','userBalanceService','saveChatLog','绘制图片失败,此次绘画被拒绝了!','queryChatBox','object','validateBalance','toLowerCase','getAllKeyList','缺失必要参数!','Repository','onModuleInit','update','abortController','./helper','formatModelToken','openaiModel3MaxTokens16k','getRandomDrawKey','REDIS_PASSWORD','.png','6315632USemEx','axios','__param','importDynamic','mjDraw','\x0a\x20Current\x20date:\x20','configService','当前模型key已被封禁','userBanance','modelsService','debug','../chatGroup/chatGroup.service','./baidu','CHAT_TYPE','typeorm','13340483NIoPXF','childList','chatPreTypeEntity','PAINT_TYPE','globalConfigService','3437731dKDcJW','getGroupInfoFromId','当前请求已过载、请稍等会儿再试试吧!','function','setChatPreType','ConfigService','BAD_REQUEST','Incorrect\x20API\x20key\x20provided','GptKeysEntity','getConfigs','appInfo','15ttVKRD','checkUserStatus','OpenAiErrorCodeMessage','UploadService','stringify','./gptkeys.entity','../../common/constants/balance.constant','toISOString','badwordsService','key','delChatBox','Bearer\x20','32k','sendMessageFromZhipu','chatProcess','UserBalanceService','../../common/constants/errorMessage.constant','NineStore','is_end','default','application/octet-stream;\x20charset=utf-8','./chatBoxType.entity','./zhipu','queryChatBoxType','save','unifiedFormattingResponse','abort','openaiTimeoutMs','getTokenCount','statusText:','uploadFile','26375ryekCl','openaiModel3MaxTokens16kRes','queryChatPreType','绘制图片失败,请稍后试试吧!','ChatGroupService','16k','gptKeysEntity','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','openaiModel3MaxTokens','https://api.openai.com','Logger','@nestjs/common','当前Key余额已不足、请重新再试一次吧','maxModelTokens','push','text','billing','user','findOne','服务异常、请重新试试吧!!!','ChatLogService','defineProperty','error:\x20','gpt-4-vision-preview','filter','usage','ChatPreTypeEntity','getUuid','../userBalance/userBalance.service','openaiModel4MaxTokens','uploadService','__esModule','modelInfo','typeInfo','post','config','REDIS_USER','preset','当前模型调用过于频繁、请重新试试吧!','assign','用户ID:\x20','base64','size','Injectable','forEach','getBaseConfig','nestjs-config','checkBadWords','delChatPreType','12ohrNBc','queryChatBoxFrontend','deductFromBalance','534xbVkcf','close','proxyUrl','400\x20error','gpt-4-1106','userService','typeId','message','DESC','7soxAiQ','REDIS_HOST','getModelProxyUrl','openaiBaseUrl','data','compileNetwork','maxResponseTokens','result','../../common/utils','imageUrl','UserService','ChatgptService','HttpException','__decorate','gpt-3','BadwordsService','chatPreEntity','DeductionKey','quality','buildMessageFromParentMessageId','getMaxTokenFromModelWithOpenAi','setChatBoxType','decorate','chatBoxEntity','keyPool','AutoreplyService','dall-e\x20draw\x20params:\x20','delete','gpt-4','map','log','This\x20is\x20not\x20a\x20chat\x20model\x20and\x20thus\x20not\x20supported','split','model3','detail','conversationId','model','redis://','setChatPre','../models/models.service','chatSyncFree','saveUseLog','chatBoxTypeEntity','addOneIfOdd','1333840cMyExE','25371dobEZS','Please\x20check\x20the\x20back-end\x20console','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters','当前模型不是聊天模型、已冻结当前调用Key、请重新尝试对话','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧','12zMzHvQ','code:\x20','queryChatPre','ceil','当前模型不是聊天模型',',\x20消耗积分\x20','DrawService','getClientIp','length','提供了错误的模型秘钥','systemPreMessage','openaiModel4MaxTokensRes','ChatBoxTypeEntity','当前分类下有未处理数据不可移除!','sendMessageFromBaidu','chat-error-detail\x20\x20<----------------------------------------->','./chatBox.entity','configEntity','sendMessageFromOpenAi','HttpStatus','./chatPre.entity','appEntity','prompt','response','status','setChatBox','slice','提供了错误的模型秘钥、已冻结当前调用Key、请重新尝试对话','env','ChatPreEntity','removeSpecialCharacters','Billing\x20hard\x20limit\x20has\x20been\x20reached','appId','@keyv/redis'];_0x547a=function(){return _0x43f3e8;};return _0x547a();}(function(_0x2d9206,_0x3dc530){const _0x6782ab=_0x47d0,_0x435417=_0x2d9206();while(!![]){try{const _0x294c4b=parseInt(_0x6782ab(0x21d))/0x1*(parseInt(_0x6782ab(0x1d6))/0x2)+-parseInt(_0x6782ab(0x199))/0x3*(-parseInt(_0x6782ab(0x193))/0x4)+-parseInt(_0x6782ab(0x23c))/0x5*(parseInt(_0x6782ab(0x270))/0x6)+-parseInt(_0x6782ab(0x279))/0x7*(parseInt(_0x6782ab(0x1fe))/0x8)+parseInt(_0x6782ab(0x194))/0x9*(-parseInt(_0x6782ab(0x1d1))/0xa)+parseInt(_0x6782ab(0x212))/0xb*(parseInt(_0x6782ab(0x26d))/0xc)+-parseInt(_0x6782ab(0x20d))/0xd;if(_0x294c4b===_0x3dc530)break;else _0x435417['push'](_0x435417['shift']());}catch(_0x48dded){_0x435417['push'](_0x435417['shift']());}}}(_0x547a,0xafd9b));var __decorate=this&&this[_0x32fb10(0x174)]||function(_0x10ab42,_0x5c07e2,_0x12042b,_0x5a49d7){const _0x41b3a4=_0x32fb10;var _0x4b0008=arguments[_0x41b3a4(0x1a1)],_0x47a256=_0x4b0008<0x3?_0x5c07e2:_0x5a49d7===null?_0x5a49d7=Object[_0x41b3a4(0x1be)](_0x5c07e2,_0x12042b):_0x5a49d7,_0x2d5682;if(typeof Reflect===_0x41b3a4(0x1ef)&&typeof Reflect[_0x41b3a4(0x17d)]===_0x41b3a4(0x215))_0x47a256=Reflect[_0x41b3a4(0x17d)](_0x10ab42,_0x5c07e2,_0x12042b,_0x5a49d7);else{for(var _0x1d4dd9=_0x10ab42[_0x41b3a4(0x1a1)]-0x1;_0x1d4dd9>=0x0;_0x1d4dd9--)if(_0x2d5682=_0x10ab42[_0x1d4dd9])_0x47a256=(_0x4b0008<0x3?_0x2d5682(_0x47a256):_0x4b0008>0x3?_0x2d5682(_0x5c07e2,_0x12042b,_0x47a256):_0x2d5682(_0x5c07e2,_0x12042b))||_0x47a256;}return _0x4b0008>0x3&&_0x47a256&&Object[_0x41b3a4(0x251)](_0x5c07e2,_0x12042b,_0x47a256),_0x47a256;},__metadata=this&&this['__metadata']||function(_0x248357,_0x84604a){const _0x3deb45=_0x32fb10;if(typeof Reflect===_0x3deb45(0x1ef)&&typeof Reflect['metadata']===_0x3deb45(0x215))return Reflect['metadata'](_0x248357,_0x84604a);},__param=this&&this[_0x32fb10(0x200)]||function(_0x1cbadd,_0x119828){return function(_0xa78336,_0x246537){_0x119828(_0xa78336,_0x246537,_0x1cbadd);};};Object[_0x32fb10(0x251)](exports,_0x32fb10(0x25b),{'value':!![]}),exports['ChatgptService']=void 0x0;const upload_service_1=require(_0x32fb10(0x1e6)),user_service_1=require('./../user/user.service'),nestjs_config_1=require(_0x32fb10(0x26a)),common_1=require(_0x32fb10(0x247)),errorMessage_constant_1=require(_0x32fb10(0x22d)),utils_1=require(_0x32fb10(0x281)),axios_1=require(_0x32fb10(0x1ff)),userBalance_service_1=require(_0x32fb10(0x258)),balance_constant_1=require(_0x32fb10(0x223)),chatLog_service_1=require('../chatLog/chatLog.service'),uuid=require('uuid'),config_entity_1=require(_0x32fb10(0x1c4)),typeorm_1=require(_0x32fb10(0x20c)),typeorm_2=require('@nestjs/typeorm'),badwords_service_1=require('../badwords/badwords.service'),autoreply_service_1=require(_0x32fb10(0x1d2)),gptkeys_entity_1=require(_0x32fb10(0x222)),globalConfig_service_1=require('../globalConfig/globalConfig.service'),fanyi_service_1=require(_0x32fb10(0x1e4)),app_entity_1=require('../app/app.entity'),chatGroup_service_1=require(_0x32fb10(0x209)),models_service_1=require(_0x32fb10(0x18e)),baidu_1=require(_0x32fb10(0x20a)),helper_1=require(_0x32fb10(0x1f8)),store_1=require('./store'),zhipu_1=require(_0x32fb10(0x233)),openai_1=require('./openai'),chatBoxType_entity_1=require(_0x32fb10(0x232)),chatBox_entity_1=require(_0x32fb10(0x1a9)),chatPre_entity_1=require(_0x32fb10(0x1ad)),chatPreType_entity_1=require('./chatPreType.entity');function _0x47d0(_0xd07a47,_0x5721e8){const _0x547a44=_0x547a();return _0x47d0=function(_0x47d026,_0x553752){_0x47d026=_0x47d026-0x172;let _0x3c1bfb=_0x547a44[_0x47d026];return _0x3c1bfb;},_0x47d0(_0xd07a47,_0x5721e8);}let ChatgptService=class ChatgptService{constructor(_0x2e2a9a,_0x31bb85,_0x489169,_0x149001,_0x2eff59,_0x524671,_0xf86d22,_0x48b5f8,_0x2a2c3b,_0xe5935d,_0x3fb946,_0x21d21a,_0x358ed4,_0xf24c6f,_0x404482,_0x1ca9ba,_0x5345cf,_0x5a6e18){const _0x3f5916=_0x32fb10;this['gptKeysEntity']=_0x2e2a9a,this[_0x3f5916(0x1aa)]=_0x31bb85,this['chatBoxTypeEntity']=_0x489169,this[_0x3f5916(0x17e)]=_0x149001,this[_0x3f5916(0x1ae)]=_0x2eff59,this['chatPreTypeEntity']=_0x524671,this[_0x3f5916(0x177)]=_0xf86d22,this[_0x3f5916(0x204)]=_0x48b5f8,this[_0x3f5916(0x1eb)]=_0x2a2c3b,this[_0x3f5916(0x1d4)]=_0xe5935d,this[_0x3f5916(0x275)]=_0x3fb946,this[_0x3f5916(0x25a)]=_0x21d21a,this[_0x3f5916(0x225)]=_0x358ed4,this[_0x3f5916(0x1bf)]=_0xf24c6f,this[_0x3f5916(0x211)]=_0x404482,this['fanyiService']=_0x1ca9ba,this[_0x3f5916(0x1ca)]=_0x5345cf,this[_0x3f5916(0x207)]=_0x5a6e18,this['nineStore']=null,this['whiteListUser']=[],this[_0x3f5916(0x17f)]={'list3':[],'list4':[]};}async[_0x32fb10(0x1f5)](){const _0x17961c=_0x32fb10;let _0x48dbd8=await(0x0,utils_1[_0x17961c(0x201)])('chatgpt-ai-web'),_0xce549f=await(0x0,utils_1[_0x17961c(0x201)])(_0x17961c(0x1ba)),_0xde31c2=await(0x0,utils_1[_0x17961c(0x201)])('keyv');_0x48dbd8=(_0x48dbd8===null||_0x48dbd8===void 0x0?void 0x0:_0x48dbd8[_0x17961c(0x230)])?_0x48dbd8[_0x17961c(0x230)]:_0x48dbd8,_0xce549f=(_0xce549f===null||_0xce549f===void 0x0?void 0x0:_0xce549f[_0x17961c(0x230)])?_0xce549f[_0x17961c(0x230)]:_0xce549f,_0xde31c2=(_0xde31c2===null||_0xde31c2===void 0x0?void 0x0:_0xde31c2[_0x17961c(0x230)])?_0xde31c2['default']:_0xde31c2;const {ChatGPTAPI:_0x58a1a9,ChatGPTError:_0x183d30,ChatGPTUnofficialProxyAPI:_0x47113d}=_0x48dbd8,_0x4a0fc8=+process[_0x17961c(0x1b5)]['REDIS_PORT'],_0x5751c1=process[_0x17961c(0x1b5)][_0x17961c(0x27a)],_0x25068a=process[_0x17961c(0x1b5)][_0x17961c(0x1fc)],_0x171ebf=process['env'][_0x17961c(0x260)],_0x1189a4=_0x17961c(0x18c)+(_0x171ebf||'')+':'+(_0x25068a||'')+'@'+_0x5751c1+':'+_0x4a0fc8,_0x124907=new _0xce549f(_0x1189a4),_0x2e4f09=new _0xde31c2({'store':_0x124907,'namespace':'nineai-chatlog'});this[_0x17961c(0x1bc)]=new store_1[(_0x17961c(0x22e))]({'store':_0x2e4f09,'namespace':'chat'});}async[_0x32fb10(0x1c7)](_0x55713a,_0x41da80,_0x256f91,_0x2a62b9=null){const _0x501085=_0x32fb10;var _0xdd0440;!_0x2a62b9&&(_0x2a62b9=(_0xdd0440=await this[_0x501085(0x207)][_0x501085(0x269)]())===null||_0xdd0440===void 0x0?void 0x0:_0xdd0440['modelInfo']);const {timeout:timeout=0x3c}=_0x256f91,{topN:_0x2bdb93,model:_0x849da}=_0x2a62b9,{parentMessageId:parentMessageId=0x0}=_0x55713a,_0x3fd727=await this[_0x501085(0x211)]['getConfigs']([_0x501085(0x238)]),_0x5bd79b=timeout*0x3e8||_0x3fd727||0x64*0x3e8,_0x32536c={'parentMessageId':parentMessageId,'timeoutMs':+_0x5bd79b,'completionParams':{'model':_0x849da,'temperature':_0x2bdb93}};return _0x41da80&&(_0x32536c['systemMessage']=_0x41da80),_0x32536c;}async[_0x32fb10(0x18f)](_0x3d9345){const _0x189f70=_0x32fb10,_0x40dbce=await this[_0x189f70(0x207)][_0x189f70(0x1fb)](),_0xd63dcf=await this[_0x189f70(0x211)]['getConfigs']([_0x189f70(0x1a3)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x53f003,model:_0x13230e}=_0x40dbce,_0x542926=await this[_0x189f70(0x27b)](_0x40dbce),{context:_0x43bd09}=await this[_0x189f70(0x1bc)][_0x189f70(0x17a)](_0x3d9345,{'parentMessageId':'','systemMessage':_0xd63dcf});try{const _0xa09a84=await(0x0,openai_1[_0x189f70(0x1ab)])(_0x43bd09,{'apiKey':(0x0,utils_1[_0x189f70(0x1b7)])(_0x53f003),'model':_0x13230e,'proxyUrl':_0x542926,'onProgress':null});return _0xa09a84===null||_0xa09a84===void 0x0?void 0x0:_0xa09a84[_0x189f70(0x24b)];}catch(_0xd746f9){console[_0x189f70(0x185)]('error:\x20',_0xd746f9);}}async[_0x32fb10(0x22b)](_0x584ce0,_0xbccdf9,_0x5bdb96){const _0x3734f1=_0x32fb10;var _0x50aec6,_0x459b13,_0x3cce78,_0x3c6f79;const _0x60fc97=_0xbccdf9[_0x3734f1(0x1f7)],{options:options={},appId:_0x4837a4,cusromPrompt:_0xae5eff,systemMessage:systemMessage=''}=_0x584ce0;let _0x4cf51d=systemMessage;const {parentMessageId:_0x25148b}=options,{prompt:_0x1c759c,imageUrl:_0x4bd58e,model:_0x13364f}=_0x584ce0,{groupId:_0x26f3aa,usingNetwork:_0x456d46}=options,_0x250462=await this[_0x3734f1(0x1ca)][_0x3734f1(0x213)](_0x26f3aa),_0x2b249a=(_0x250462===null||_0x250462===void 0x0?void 0x0:_0x250462[_0x3734f1(0x25f)])?JSON[_0x3734f1(0x1e1)](_0x250462[_0x3734f1(0x25f)]):await this[_0x3734f1(0x207)][_0x3734f1(0x269)](),{keyType:_0x13cd85,model:_0xa33ca7,topN:_0x277b8f,systemMessage:_0x28a7d9,rounds:_0x6ee328}=_0x2b249a[_0x3734f1(0x25c)];let _0x339ed7=null;!_0xae5eff?_0x339ed7=await this[_0x3734f1(0x207)][_0x3734f1(0x1bb)](_0xa33ca7):_0x339ed7=await this['modelsService'][_0x3734f1(0x1fb)]();if(!_0x339ed7)throw new common_1['HttpException']('当前流程所需要的模型已被管理员下架、请联系管理员上架专属模型!',common_1['HttpStatus'][_0x3734f1(0x218)]);const {deduct:_0x222c39,isTokenBased:_0x2ee5d6,tokenFeeRatio:_0x9ec514,deductType:_0x26ec70,key:_0xe24feb,secret:_0x19ccb1,modelName:_0x1ae02d,id:_0x1f3c37,accessToken:_0x25650b}=_0x339ed7;await this['userService']['checkUserStatus'](_0xbccdf9[_0x3734f1(0x24d)]),await this[_0x3734f1(0x1eb)]['validateBalance'](_0xbccdf9,_0x26ec70===0x1?_0x3734f1(0x188):'model4',_0x222c39),_0x5bdb96&&_0x5bdb96[_0x3734f1(0x1c1)]('Content-type',_0x3734f1(0x231)),await this['badwordsService'][_0x3734f1(0x26b)](_0x1c759c,_0xbccdf9['user']['id']);const _0x2a4c40=await this[_0x3734f1(0x1bf)]['checkAutoReply'](_0x1c759c);if(_0x2a4c40&&_0x5bdb96){const _0x4b9aeb={'message':_0x2a4c40,'code':0x1f4};return _0x5bdb96[_0x3734f1(0x1e2)](JSON[_0x3734f1(0x221)](_0x4b9aeb)),_0x5bdb96[_0x3734f1(0x1c8)]();}if(_0x4837a4){const _0x4b71fc=await this['appEntity'][_0x3734f1(0x24e)]({'where':{'id':_0x4837a4,'status':(0x0,typeorm_1['In'])([0x1,0x3,0x4,0x5])}});if(!_0x4b71fc)throw new common_1['HttpException']('你当前使用的应用已被下架、请删除当前对话开启新的对话吧!',common_1[_0x3734f1(0x1ac)][_0x3734f1(0x218)]);_0x4b71fc[_0x3734f1(0x261)]&&(_0x4cf51d=_0x4b71fc[_0x3734f1(0x261)]);}else{if(_0xae5eff)_0x4cf51d=systemMessage;else{if(_0x28a7d9)_0x4cf51d=_0x28a7d9;else{const _0x2a9666=new Date()[_0x3734f1(0x224)]()[_0x3734f1(0x187)]('T')[0x0],_0x35f2c9=await this[_0x3734f1(0x211)][_0x3734f1(0x21b)]([_0x3734f1(0x1a3)]);_0x4cf51d=_0x35f2c9+('\x0a\x20Current\x20date:\x20'+_0x2a9666);}}}let _0xd7ac09='';if(_0x456d46){_0xd7ac09=await(0x0,utils_1[_0x3734f1(0x27e)])(_0x1c759c);const _0x55a599=new Date()[_0x3734f1(0x224)]()[_0x3734f1(0x187)]('T')[0x0],_0x1b32a2=await this[_0x3734f1(0x211)][_0x3734f1(0x21b)](['systemPreMessage']);_0x4cf51d=_0x1b32a2+(_0x3734f1(0x203)+_0x55a599);}const _0x42285b=await this[_0x3734f1(0x1c7)](options,_0x4cf51d,_0x339ed7,_0x2b249a[_0x3734f1(0x25c)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x6e51da}=_0x339ed7;_0x5bdb96&&_0x5bdb96[_0x3734f1(0x1b1)](0xc8);let _0x3c7649=null,_0x2ba83c=null;try{if(_0x5bdb96){let _0x405276=null,_0x20af5a=![];_0x5bdb96['on'](_0x3734f1(0x271),async()=>{const _0x1787f8=_0x3734f1;if(_0x20af5a)return;_0x60fc97[_0x1787f8(0x237)]();const _0x1d4bfa=await(0x0,openai_1[_0x1787f8(0x239)])(_0x1c759c)||0x0,_0x24cd27=await(0x0,openai_1[_0x1787f8(0x239)])(_0x405276===null||_0x405276===void 0x0?void 0x0:_0x405276[_0x1787f8(0x24b)])||0x0,_0x5df560=_0x1d4bfa+_0x24cd27,_0x522fac=(0x0,utils_1[_0x1787f8(0x1a0)])(_0xbccdf9);await this[_0x1787f8(0x1d4)][_0x1787f8(0x1ec)]({'appId':_0x4837a4,'curIp':_0x522fac,'userId':_0xbccdf9[_0x1787f8(0x24d)]['id'],'type':balance_constant_1[_0x1787f8(0x178)]['CHAT_TYPE'],'prompt':_0x1c759c,'imageUrl':_0x4bd58e,'activeModel':_0x13364f,'answer':'','promptTokens':_0x1d4bfa,'completionTokens':0x0,'totalTokens':_0x1d4bfa,'model':_0xa33ca7,'role':'user','groupId':_0x26f3aa,'requestOptions':JSON['stringify']({'options':null,'prompt':_0x1c759c})}),await this[_0x1787f8(0x1d4)][_0x1787f8(0x1ec)]({'appId':_0x4837a4,'curIp':_0x522fac,'userId':_0xbccdf9[_0x1787f8(0x24d)]['id'],'type':balance_constant_1[_0x1787f8(0x178)][_0x1787f8(0x20b)],'prompt':_0x1c759c,'answer':_0x405276===null||_0x405276===void 0x0?void 0x0:_0x405276[_0x1787f8(0x24b)],'promptTokens':_0x1d4bfa,'completionTokens':_0x24cd27,'totalTokens':_0x5df560,'model':_0xa33ca7,'role':'assistant','groupId':_0x26f3aa,'requestOptions':JSON[_0x1787f8(0x221)]({'options':{'model':_0xa33ca7,'temperature':_0x277b8f},'prompt':_0x1c759c}),'conversationOptions':JSON[_0x1787f8(0x221)]({'conversationId':_0x405276===null||_0x405276===void 0x0?void 0x0:_0x405276[_0x1787f8(0x18a)],'model':_0xa33ca7,'parentMessageId':_0x405276===null||_0x405276===void 0x0?void 0x0:_0x405276['id'],'temperature':_0x277b8f})});let _0x3c32e2=_0x222c39;_0x2ee5d6===!![]&&(_0x3c32e2=Math[_0x1787f8(0x19c)](_0x222c39*_0x5df560/_0x9ec514)),await this[_0x1787f8(0x1eb)][_0x1787f8(0x26f)](_0xbccdf9[_0x1787f8(0x24d)]['id'],_0x1787f8(0x18b)+(_0x26ec70===0x1?0x3:0x4),_0x3c32e2,_0x5df560);});if(Number(_0x13cd85)===0x1){const {key:_0x22e0c0,maxToken:_0x53e129,maxTokenRes:_0x2a5df6,proxyResUrl:_0x5198ad}=await this[_0x3734f1(0x1f9)](_0x339ed7),{parentMessageId:_0x2e4907,completionParams:_0x2a3dc7,systemMessage:_0x5ddb1e}=_0x42285b,{model:_0xbd1af,temperature:_0x67d5bf}=_0x2a3dc7,{context:_0x5f2c6a}=await this[_0x3734f1(0x1bc)][_0x3734f1(0x17a)](_0x456d46?_0xd7ac09:_0x1c759c,{'parentMessageId':_0x2e4907,'systemMessage':_0x5ddb1e,'maxModelToken':_0x53e129,'maxResponseTokens':_0x2a5df6,'maxRounds':(0x0,helper_1['addOneIfOdd'])(_0x6ee328),'imageUrl':_0x4bd58e,'activeModel':_0x13364f});let _0x318c34=!![];_0x3c7649=await(0x0,openai_1[_0x3734f1(0x1ab)])(_0x5f2c6a,{'maxToken':_0x53e129,'maxTokenRes':_0x2a5df6,'apiKey':_0xe24feb,'model':_0xbd1af,'prompt':_0x1c759c,'activeModel':_0x13364f,'imageUrl':_0x4bd58e,'temperature':_0x67d5bf,'proxyUrl':_0x5198ad,'onProgress':_0x5c2c53=>{const _0x4bee93=_0x3734f1;_0x5bdb96[_0x4bee93(0x1e2)](_0x318c34?JSON[_0x4bee93(0x221)](_0x5c2c53):'\x0a'+JSON['stringify'](_0x5c2c53)),_0x405276=_0x5c2c53,_0x318c34=![];}},this['uploadService']),_0x20af5a=!![];}if(Number(_0x13cd85)===0x2){let _0x29a4db=!![];const {context:_0x3498ad}=await this[_0x3734f1(0x1bc)][_0x3734f1(0x17a)](_0x456d46?_0xd7ac09:_0x1c759c,{'parentMessageId':_0x25148b,'maxRounds':(0x0,helper_1[_0x3734f1(0x192)])(_0x6ee328)});_0x3c7649=await(0x0,baidu_1[_0x3734f1(0x1a7)])(_0x456d46?_0xd7ac09:_0x3498ad,{'temperature':_0x277b8f,'accessToken':_0x25650b,'model':_0xa33ca7,'onProgress':_0x2fa785=>{const _0x6517e2=_0x3734f1;_0x5bdb96['write'](_0x29a4db?JSON[_0x6517e2(0x221)](_0x2fa785):'\x0a'+JSON['stringify'](_0x2fa785)),_0x29a4db=![],_0x405276=_0x2fa785;}}),_0x20af5a=!![];}if(Number(_0x13cd85)===0x3){let _0x1cfdde=!![];const {context:_0x5c2c71}=await this[_0x3734f1(0x1bc)]['buildMessageFromParentMessageId'](_0x456d46?_0xd7ac09:_0x1c759c,{'parentMessageId':_0x25148b,'maxRounds':(0x0,helper_1[_0x3734f1(0x192)])(_0x6ee328)});_0x3c7649=await(0x0,zhipu_1[_0x3734f1(0x22a)])(_0x456d46?_0xd7ac09:_0x5c2c71,{'temperature':_0x277b8f,'key':_0x6e51da,'model':_0xa33ca7,'onProgress':_0x178f4f=>{const _0x54acb5=_0x3734f1;_0x5bdb96[_0x54acb5(0x1e2)](_0x1cfdde?JSON[_0x54acb5(0x221)](_0x178f4f):'\x0a'+JSON[_0x54acb5(0x221)](_0x178f4f)),_0x1cfdde=![],_0x405276=_0x178f4f;}}),_0x20af5a=!![];}const _0x39913e={'id':this[_0x3734f1(0x1bc)][_0x3734f1(0x257)](),'text':_0x1c759c,'role':_0x3734f1(0x24d),'name':undefined,'usage':null,'imageUrl':_0x4bd58e,'activeModel':_0x13364f,'parentMessageId':_0x25148b,'conversationId':_0x3c7649===null||_0x3c7649===void 0x0?void 0x0:_0x3c7649['conversationId']};_0x2ba83c={'model':_0xa33ca7,'parentMessageId':_0x25148b},await this[_0x3734f1(0x1bc)][_0x3734f1(0x1de)](_0x39913e);const _0x3f1f37={'id':_0x3c7649['id'],'text':_0x3c7649[_0x3734f1(0x24b)],'role':_0x3734f1(0x1ce),'name':undefined,'usage':_0x3c7649===null||_0x3c7649===void 0x0?void 0x0:_0x3c7649[_0x3734f1(0x255)],'imageUrl':_0x4bd58e,'parentMessageId':_0x39913e['id'],'conversationId':_0x3c7649===null||_0x3c7649===void 0x0?void 0x0:_0x3c7649['conversationId']};await this[_0x3734f1(0x1bc)][_0x3734f1(0x1de)](_0x3f1f37),_0x2ba83c={'model':_0xa33ca7,'parentMessageId':_0x39913e['id']};}else{const {key:_0x31c11d,maxToken:_0x21691d,maxTokenRes:_0x1fbda4,proxyResUrl:_0x4fef00}=await this[_0x3734f1(0x1f9)](_0x339ed7),{parentMessageId:_0x3dd316,completionParams:_0x4a14fa,systemMessage:_0x549401}=_0x42285b,{model:_0x53f721,temperature:_0x5b3c2d}=_0x4a14fa,{context:_0x448449}=await this[_0x3734f1(0x1bc)][_0x3734f1(0x17a)](_0x456d46?_0xd7ac09:_0x1c759c,{'parentMessageId':_0x3dd316,'systemMessage':_0x549401,'maxRounds':(0x0,helper_1['addOneIfOdd'])(_0x6ee328)});_0x3c7649=await(0x0,openai_1[_0x3734f1(0x1ab)])(_0x448449,{'apiKey':_0xe24feb,'model':_0x53f721,'temperature':_0x5b3c2d,'proxyUrl':_0x4fef00,'onProgress':null,'prompt':_0x1c759c});}let _0x5f3a31=null,_0x5aa113=null;_0xa33ca7['includes'](_0x3734f1(0x1e8))?_0x5f3a31=((_0x50aec6=_0x3c7649[_0x3734f1(0x189)])===null||_0x50aec6===void 0x0?void 0x0:_0x50aec6[_0x3734f1(0x255)])||{'prompt_tokens':0x1,'completion_tokens':0x1,'total_tokens':0x2}:_0x5aa113=await(0x0,helper_1[_0x3734f1(0x236)])(_0x13cd85,_0x3c7649,_0x2ba83c);const {prompt_tokens:_0x3daba1,completion_tokens:_0x5206be,total_tokens:_0x508dba}=_0xa33ca7[_0x3734f1(0x1db)](_0x3734f1(0x1e8))?_0x5f3a31:_0x5aa113['usage'];let _0x41012f=_0x222c39;_0x2ee5d6===!![]&&(_0x41012f=Math['ceil'](_0x222c39*_0x508dba/_0x9ec514));await this[_0x3734f1(0x1eb)]['deductFromBalance'](_0xbccdf9['user']['id'],_0x3734f1(0x18b)+(_0x26ec70===0x1?0x3:0x4),_0x41012f,_0x508dba),await this['modelsService'][_0x3734f1(0x190)](_0x1f3c37,_0x508dba);const _0x47a298=(0x0,utils_1[_0x3734f1(0x1a0)])(_0xbccdf9);await this['chatLogService']['saveChatLog']({'appId':_0x4837a4,'curIp':_0x47a298,'userId':_0xbccdf9[_0x3734f1(0x24d)]['id'],'type':balance_constant_1['DeductionKey'][_0x3734f1(0x20b)],'prompt':_0x1c759c,'imageUrl':_0x4bd58e,'activeModel':_0x13364f,'answer':'','promptTokens':_0x3daba1,'completionTokens':0x0,'totalTokens':_0x508dba,'model':_0xa33ca7,'role':'user','groupId':_0x26f3aa,'requestOptions':JSON[_0x3734f1(0x221)]({'options':null,'prompt':_0x1c759c})}),await this[_0x3734f1(0x1d4)][_0x3734f1(0x1ec)]({'appId':_0x4837a4,'curIp':_0x47a298,'userId':_0xbccdf9[_0x3734f1(0x24d)]['id'],'type':balance_constant_1[_0x3734f1(0x178)][_0x3734f1(0x20b)],'prompt':_0x1c759c,'imageUrl':_0x3c7649===null||_0x3c7649===void 0x0?void 0x0:_0x3c7649[_0x3734f1(0x282)],'answer':_0x3c7649[_0x3734f1(0x24b)],'promptTokens':_0x3daba1,'completionTokens':_0x5206be,'totalTokens':_0x508dba,'model':_0xa33ca7,'role':_0x3734f1(0x1ce),'groupId':_0x26f3aa,'requestOptions':JSON[_0x3734f1(0x221)]({'options':{'model':_0xa33ca7,'temperature':_0x277b8f},'prompt':_0x1c759c}),'conversationOptions':JSON[_0x3734f1(0x221)]({'conversationId':_0x3c7649[_0x3734f1(0x18a)],'model':_0xa33ca7,'parentMessageId':_0x3c7649['id'],'temperature':_0x277b8f})}),common_1[_0x3734f1(0x246)][_0x3734f1(0x208)](_0x3734f1(0x264)+_0xbccdf9[_0x3734f1(0x24d)]['id']+_0x3734f1(0x1cd)+_0x1ae02d+'-'+_0x13364f+',\x20消耗token:\x20'+_0x508dba+_0x3734f1(0x19e)+_0x41012f,_0x3734f1(0x172));const _0x3a5af2=await this['userBalanceService']['queryUserBalance'](_0xbccdf9[_0x3734f1(0x24d)]['id']);return _0x3c7649[_0x3734f1(0x206)]=Object[_0x3734f1(0x263)]({},_0x3a5af2),_0x3c7649[_0x3734f1(0x280)]&&(_0x3c7649[_0x3734f1(0x280)]=''),_0x3c7649[_0x3734f1(0x22f)]=!![],_0x5bdb96?_0x5bdb96['write']('\x0a'+JSON[_0x3734f1(0x221)](_0x3c7649)):_0x3c7649['text'];}catch(_0x28739e){console[_0x3734f1(0x185)](_0x3734f1(0x1df),_0xe24feb,_0x28739e);const _0x95558e=(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1e0)])||0x190,_0x1c9e6e=((_0x459b13=_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1b0)])===null||_0x459b13===void 0x0?void 0x0:_0x459b13[_0x3734f1(0x1b1)])||(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e['statusCode'])||0x190;console[_0x3734f1(0x185)](_0x3734f1(0x1a8),_0x3734f1(0x19a),_0x95558e,_0x3734f1(0x277),_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x277)],_0x3734f1(0x23a),(_0x3cce78=_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1b0)])===null||_0x3cce78===void 0x0?void 0x0:_0x3cce78[_0x3734f1(0x1c6)],_0x3734f1(0x1b1),(_0x3c6f79=_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1b0)])===null||_0x3c6f79===void 0x0?void 0x0:_0x3c6f79[_0x3734f1(0x1b1)]);if(_0x28739e[_0x3734f1(0x1b1)]&&_0x28739e[_0x3734f1(0x1b1)]===0x192){const _0x5adfaa={'message':'Catch\x20Error\x20'+_0x28739e['message'],'code':0x192};if(_0x5bdb96)return _0x5bdb96[_0x3734f1(0x1e2)](JSON[_0x3734f1(0x221)](_0x5adfaa));else throw new common_1[(_0x3734f1(0x173))](_0x28739e[_0x3734f1(0x277)],common_1[_0x3734f1(0x1ac)][_0x3734f1(0x1d0)]);}if(!_0x1c9e6e){if(_0x5bdb96)return _0x5bdb96[_0x3734f1(0x1e2)](JSON['stringify']({'message':_0x28739e[_0x3734f1(0x277)],'code':0x1f4}));else throw new common_1['HttpException'](_0x28739e[_0x3734f1(0x277)],common_1[_0x3734f1(0x1ac)][_0x3734f1(0x218)]);}let _0x2db0fc=errorMessage_constant_1['OpenAiErrorCodeMessage'][_0x1c9e6e]?errorMessage_constant_1[_0x3734f1(0x21f)][_0x1c9e6e]:_0x3734f1(0x24f);(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x277)]['includes'](_0x3734f1(0x1e7)))&&Number(_0x13cd85)===0x1&&(await this[_0x3734f1(0x207)][_0x3734f1(0x1c3)](_0x1f3c37,_0x3734f1(0x198),-0x1),_0x2db0fc=_0x3734f1(0x205));(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1e0)])===0x1ad&&_0x28739e[_0x3734f1(0x277)][_0x3734f1(0x1db)](_0x3734f1(0x24c))&&Number(_0x13cd85)===0x1&&(await this[_0x3734f1(0x207)]['lockKey'](_0x1f3c37,'当前模型key余额已耗尽、已冻结当前调用Key、尝试重新对话试试吧',-0x3),_0x2db0fc='当前模型key余额已耗尽');(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1e0)])===0x1ad&&(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e['statusText'])==='Too\x20Many\x20Requests'&&(_0x2db0fc=_0x3734f1(0x262));(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e[_0x3734f1(0x1e0)])===0x191&&_0x28739e[_0x3734f1(0x277)][_0x3734f1(0x1db)](_0x3734f1(0x219))&&Number(_0x13cd85)===0x1&&(await this[_0x3734f1(0x207)][_0x3734f1(0x1c3)](_0x1f3c37,_0x3734f1(0x1a2),-0x2),_0x2db0fc=_0x3734f1(0x1b4));(_0x28739e===null||_0x28739e===void 0x0?void 0x0:_0x28739e['statusCode'])===0x194&&_0x28739e['message'][_0x3734f1(0x1db)](_0x3734f1(0x186))&&Number(_0x13cd85)===0x1&&(await this[_0x3734f1(0x207)]['lockKey'](_0x1f3c37,_0x3734f1(0x19d),-0x4),_0x2db0fc=_0x3734f1(0x197));_0x95558e===0x190&&console[_0x3734f1(0x185)](_0x3734f1(0x273),_0x28739e,_0x28739e[_0x3734f1(0x277)]);const _0x1f2511={'message':_0x2db0fc||_0x3734f1(0x195),'code':_0x95558e===0x191?0x190:_0x95558e||0x1f4};if(_0x5bdb96)return _0x5bdb96['write'](JSON['stringify'](_0x1f2511));else throw new common_1[(_0x3734f1(0x173))](_0x1f2511['message'],common_1['HttpStatus'][_0x3734f1(0x218)]);}finally{_0x5bdb96&&_0x5bdb96[_0x3734f1(0x1c8)]();}}async['draw'](_0x59884b,_0x45f47b){const _0x2d6020=_0x32fb10;var _0xc3d525,_0x1c7713,_0x4c617a,_0x127010;await this[_0x2d6020(0x225)][_0x2d6020(0x26b)](_0x59884b[_0x2d6020(0x1af)],_0x45f47b[_0x2d6020(0x24d)]['id']),await this[_0x2d6020(0x275)][_0x2d6020(0x21e)](_0x45f47b[_0x2d6020(0x24d)]);const _0xbbfc3d=(_0x59884b===null||_0x59884b===void 0x0?void 0x0:_0x59884b[_0x2d6020(0x179)])==='hd'?0x4:0x2;await this['userBalanceService'][_0x2d6020(0x1f0)](_0x45f47b,_0x2d6020(0x202),_0xbbfc3d);let _0x31d531=[];const _0x2b58d2=await this[_0x2d6020(0x207)][_0x2d6020(0x1bb)](_0x2d6020(0x1d8)),_0x933fdf=_0x2b58d2===null||_0x2b58d2===void 0x0?void 0x0:_0x2b58d2['id'],{key:_0x2323b4,proxyResUrl:_0x1a442e}=await this['formatModelToken'](_0x2b58d2);common_1[_0x2d6020(0x246)][_0x2d6020(0x185)](_0x2d6020(0x1bd)+_0x59884b['prompt']+',\x20key\x20===>\x20'+_0x2323b4,_0x2d6020(0x19f));try{const _0x277a6f=_0x1a442e+'/v1/images/generations',_0x589029=Object['assign'](Object[_0x2d6020(0x263)]({},_0x59884b),{'model':_0x2d6020(0x1d8)});console[_0x2d6020(0x185)](_0x2d6020(0x181),_0x589029);const _0x5aa0a5=await axios_1[_0x2d6020(0x230)][_0x2d6020(0x25e)](_0x277a6f,Object[_0x2d6020(0x263)](Object[_0x2d6020(0x263)]({},_0x589029),{'response_format':_0x2d6020(0x1dd)}),{'headers':{'Authorization':_0x2d6020(0x228)+_0x2323b4}});_0x31d531=_0x5aa0a5['data'][_0x2d6020(0x27d)];const _0x3d17cf=[];for(const _0x4f4ca9 of _0x31d531){const _0xc2b5ed=uuid['v4']()[_0x2d6020(0x1b3)](0x0,0xa)+_0x2d6020(0x1fd),_0x4fefa2=Buffer[_0x2d6020(0x1d3)](_0x4f4ca9[_0x2d6020(0x1dd)],_0x2d6020(0x265));_0x3d17cf[_0x2d6020(0x24a)](this[_0x2d6020(0x25a)][_0x2d6020(0x23b)]({'filename':_0xc2b5ed,'buffer':_0x4fefa2}));}const _0x4d5f14=await Promise[_0x2d6020(0x1e3)](_0x3d17cf);await this[_0x2d6020(0x1eb)][_0x2d6020(0x26f)](_0x45f47b['user']['id'],_0x2d6020(0x202),(_0x589029===null||_0x589029===void 0x0?void 0x0:_0x589029[_0x2d6020(0x179)])===_0x2d6020(0x1e5)?0x2:0x4,_0xbbfc3d);const _0x2e41b4=(0x0,utils_1['getClientIp'])(_0x45f47b),_0x403de9=[],_0x38524f=await this[_0x2d6020(0x25a)][_0x2d6020(0x1da)](),[_0x24ca04,_0xd059fc]=_0x59884b[_0x2d6020(0x266)][_0x2d6020(0x187)]('x');return _0x4d5f14['forEach'](_0x3d8568=>{const _0x5e286f=_0x2d6020;_0x403de9[_0x5e286f(0x24a)](this[_0x5e286f(0x1d4)][_0x5e286f(0x1ec)]({'curIp':_0x2e41b4,'userId':_0x45f47b[_0x5e286f(0x24d)]['id'],'type':balance_constant_1[_0x5e286f(0x178)][_0x5e286f(0x210)],'prompt':_0x59884b[_0x5e286f(0x1af)],'answer':_0x3d8568,'fileInfo':JSON[_0x5e286f(0x221)]({'cosType':_0x38524f,'width':_0x24ca04,'height':_0xd059fc,'cosUrl':_0x3d8568}),'promptTokens':0x0,'completionTokens':0x0,'totalTokens':0x0,'model':'dall-e-3'}));}),await Promise[_0x2d6020(0x1e3)](_0x403de9),_0x4d5f14;}catch(_0x3d8d1c){const _0x5c6abb=((_0xc3d525=_0x3d8d1c===null||_0x3d8d1c===void 0x0?void 0x0:_0x3d8d1c[_0x2d6020(0x1b0)])===null||_0xc3d525===void 0x0?void 0x0:_0xc3d525[_0x2d6020(0x1b1)])||0x1f4;console[_0x2d6020(0x185)](_0x2d6020(0x1cb),JSON[_0x2d6020(0x221)](_0x3d8d1c),_0x2323b4,_0x5c6abb);const _0x197053=(_0x127010=(_0x4c617a=(_0x1c7713=_0x3d8d1c===null||_0x3d8d1c===void 0x0?void 0x0:_0x3d8d1c[_0x2d6020(0x1b0)])===null||_0x1c7713===void 0x0?void 0x0:_0x1c7713['data'])===null||_0x4c617a===void 0x0?void 0x0:_0x4c617a[_0x2d6020(0x1c2)])===null||_0x127010===void 0x0?void 0x0:_0x127010[_0x2d6020(0x277)];if(_0x5c6abb===0x1ad)throw new common_1[(_0x2d6020(0x173))](_0x2d6020(0x214),common_1[_0x2d6020(0x1ac)][_0x2d6020(0x218)]);if(_0x5c6abb===0x190&&_0x197053[_0x2d6020(0x1db)](_0x2d6020(0x196)))throw new common_1['HttpException'](_0x2d6020(0x243),common_1['HttpStatus'][_0x2d6020(0x218)]);if(_0x5c6abb===0x190&&_0x197053[_0x2d6020(0x1db)](_0x2d6020(0x1b8))){await this[_0x2d6020(0x207)][_0x2d6020(0x1c3)](_0x933fdf,_0x2d6020(0x198),-0x1);throw new common_1[(_0x2d6020(0x173))](_0x2d6020(0x248),common_1[_0x2d6020(0x1ac)][_0x2d6020(0x218)]);}if(_0x5c6abb===0x1f4)throw new common_1[(_0x2d6020(0x173))]('绘制图片失败,请检查你的提示词是否有非法描述!',common_1['HttpStatus'][_0x2d6020(0x218)]);if(_0x5c6abb===0x191)throw new common_1[(_0x2d6020(0x173))](_0x2d6020(0x1ed),common_1['HttpStatus'][_0x2d6020(0x218)]);throw new common_1['HttpException'](_0x2d6020(0x23f),common_1['HttpStatus'][_0x2d6020(0x218)]);}}async[_0x32fb10(0x1f2)](){const _0x487082=_0x32fb10,_0x24b82d=await this[_0x487082(0x242)][_0x487082(0x1c5)]({'where':{'status':0x1},'select':['id',_0x487082(0x226),'weight',_0x487082(0x18b),_0x487082(0x249),_0x487082(0x27f),_0x487082(0x1dc),_0x487082(0x238)]}),_0x431f2d=_0x24b82d[_0x487082(0x254)](_0x3d2e9d=>_0x3d2e9d[_0x487082(0x18b)][_0x487082(0x1db)]('gpt-3')),_0x3e98b1=_0x24b82d[_0x487082(0x254)](_0x1834dc=>_0x1834dc['model']['includes'](_0x487082(0x183)));this[_0x487082(0x17f)]={'list3':_0x431f2d,'list4':_0x3e98b1};}async[_0x32fb10(0x27b)](_0x3d54bb){const _0x3629dc=_0x32fb10,_0x560840=await this[_0x3629dc(0x211)][_0x3629dc(0x21b)]([_0x3629dc(0x27c)]);return(_0x3d54bb===null||_0x3d54bb===void 0x0?void 0x0:_0x3d54bb[_0x3629dc(0x272)])||_0x560840||'https://api.openai.com';}async[_0x32fb10(0x1f9)](_0xb53987){const _0x30debe=_0x32fb10,{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[_0x30debe(0x211)][_0x30debe(0x21b)]([_0x30debe(0x244),_0x30debe(0x1e9),_0x30debe(0x1fa),_0x30debe(0x23d),_0x30debe(0x259),_0x30debe(0x1a4),'openaiModel4MaxTokens32k','openaiModel4MaxTokens32kRes',_0x30debe(0x27c)]);let _0x44d67a=null,_0x3f3f0c=null,_0x2b5bad=null,{model:_0x45f438,maxModelTokens:maxModelTokens=0x0,maxResponseTokens:maxResponseTokens=0x0,proxyUrl:proxyUrl='',key:_0x48b7dc}=_0xb53987;return _0x45f438[_0x30debe(0x1f1)]()[_0x30debe(0x1db)]('gpt-4')&&(maxModelTokens>=0x2000&&(maxModelTokens=0x2000),_0x3f3f0c>=0x1000&&(maxModelTokens=0x1000),_0x44d67a=maxModelTokens||openaiModel4MaxTokens||0x2000,_0x3f3f0c=maxResponseTokens||openaiModel4MaxTokensRes||0x1000,_0x45f438[_0x30debe(0x1f1)]()['includes'](_0x30debe(0x229))&&(maxModelTokens>=0x8000&&(maxModelTokens=0x8000),_0x3f3f0c>=0x4000&&(maxModelTokens=0x4000),_0x44d67a=maxModelTokens||openaiModel4MaxTokens32k||0x8000,_0x3f3f0c=maxResponseTokens||openaiModel4MaxTokens32kRes||0x4000),_0x45f438['toLowerCase']()[_0x30debe(0x1db)](_0x30debe(0x1d9))&&(maxModelTokens>=0x3ffc&&(maxModelTokens=0x3ffc),_0x3f3f0c>=0x1000&&(maxModelTokens=0x1000),_0x44d67a=maxModelTokens||0x3ffc,_0x3f3f0c=maxResponseTokens||0x1000)),_0x45f438['toLowerCase']()['includes'](_0x30debe(0x175))&&(maxModelTokens>=0x1000&&(maxModelTokens=0x1000),_0x3f3f0c>=0x7d0&&(maxModelTokens=0x7d0),_0x44d67a=maxModelTokens||openaiModel3MaxTokens||0x1000,_0x3f3f0c=maxResponseTokens||openaiModel3MaxTokensRes||0x7d0,_0x45f438[_0x30debe(0x1f1)]()[_0x30debe(0x1db)](_0x30debe(0x241))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x3f3f0c>=0x2000&&(maxModelTokens=0x2000),_0x44d67a=maxModelTokens||openaiModel3MaxTokens16k||0x4000,_0x3f3f0c=maxResponseTokens||openaiModel3MaxTokens16kRes||0x2000),_0x45f438['toLowerCase']()[_0x30debe(0x1db)]('1106')&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x3f3f0c>=0x1000&&(maxModelTokens=0x1000),_0x44d67a=maxModelTokens||0x4000,_0x3f3f0c=maxResponseTokens||0x1000)),_0x2b5bad=proxyUrl||openaiBaseUrl||_0x30debe(0x245),_0x3f3f0c>=_0x44d67a&&(_0x3f3f0c=Math['floor'](_0x44d67a/0x2)),{'key':_0x48b7dc,'maxToken':_0x44d67a,'maxTokenRes':_0x3f3f0c,'proxyResUrl':_0x2b5bad};}async[_0x32fb10(0x17c)](_0x53c4c4,_0x327cba){const _0x563a8c=_0x32fb10;try{const {name:_0x19ee01,icon:_0x264b11,order:_0x3883c4,id:_0x5345dc,status:_0x79c1b1}=_0x327cba;return _0x5345dc?await this['chatBoxTypeEntity']['update']({'id':_0x5345dc},{'name':_0x19ee01,'icon':_0x264b11,'order':_0x3883c4,'status':_0x79c1b1}):await this[_0x563a8c(0x191)][_0x563a8c(0x235)]({'name':_0x19ee01,'icon':_0x264b11,'order':_0x3883c4,'status':_0x79c1b1});}catch(_0x558038){console[_0x563a8c(0x185)](_0x563a8c(0x252),_0x558038);}}async['delChatBoxType'](_0x81860a,_0x1fa1c1){const _0x36fe2b=_0x32fb10,{id:_0x2b7487}=_0x1fa1c1;if(!_0x2b7487)throw new common_1[(_0x36fe2b(0x173))](_0x36fe2b(0x1ea),common_1[_0x36fe2b(0x1ac)][_0x36fe2b(0x218)]);const _0x5c649b=await this[_0x36fe2b(0x17e)][_0x36fe2b(0x1cf)]({'where':{'typeId':_0x2b7487}});if(_0x5c649b)throw new common_1[(_0x36fe2b(0x173))](_0x36fe2b(0x1a6),common_1[_0x36fe2b(0x1ac)][_0x36fe2b(0x218)]);return await this['chatBoxTypeEntity']['delete']({'id':_0x2b7487});}async[_0x32fb10(0x234)](){const _0x3f9ae4=_0x32fb10;return await this['chatBoxTypeEntity'][_0x3f9ae4(0x1c5)]({'order':{'order':_0x3f9ae4(0x278)}});}async[_0x32fb10(0x1b2)](_0x5ce2bb,_0x46d94a){const _0xa48250=_0x32fb10,{title:_0x5f46b8,prompt:_0x5632a7,appId:_0x44d338,order:_0x20ae8c,status:_0x597b8d,typeId:_0x432105,id:_0x49f484,url:_0x234b56}=_0x46d94a;if(!_0x432105)throw new common_1[(_0xa48250(0x173))](_0xa48250(0x1f3),common_1[_0xa48250(0x1ac)][_0xa48250(0x218)]);try{const _0x3c2c46={'title':_0x5f46b8,'order':_0x20ae8c,'status':_0x597b8d,'typeId':_0x432105,'url':_0x234b56};return _0x3c2c46['appId']=_0x44d338||0x0,_0x3c2c46[_0xa48250(0x1af)]=_0x5632a7||'',_0x49f484?await this['chatBoxEntity'][_0xa48250(0x1f6)]({'id':_0x49f484},_0x3c2c46):await this['chatBoxEntity'][_0xa48250(0x235)](_0x3c2c46);}catch(_0x56f08b){console[_0xa48250(0x185)](_0xa48250(0x252),_0x56f08b);}}async[_0x32fb10(0x227)](_0x30627b,_0x396d15){const _0x461819=_0x32fb10,{id:_0x446cc2}=_0x396d15;if(!_0x446cc2)throw new common_1['HttpException'](_0x461819(0x1ea),common_1[_0x461819(0x1ac)][_0x461819(0x218)]);return await this[_0x461819(0x17e)][_0x461819(0x182)]({'id':_0x446cc2});}async[_0x32fb10(0x1ee)](){const _0x20d6d1=_0x32fb10,_0x197bf3=await this['chatBoxEntity']['find']({'order':{'order':_0x20d6d1(0x278)}}),_0x54e13c=[...new Set(_0x197bf3[_0x20d6d1(0x184)](_0x4ee9fc=>_0x4ee9fc[_0x20d6d1(0x276)]))],_0x26bcea=[...new Set(_0x197bf3[_0x20d6d1(0x184)](_0x50d201=>_0x50d201['appId']))],_0x40e9da=await this[_0x20d6d1(0x191)][_0x20d6d1(0x1c5)]({'where':{'id':(0x0,typeorm_1['In'])(_0x54e13c)}}),_0x35cc89=await this[_0x20d6d1(0x1ae)][_0x20d6d1(0x1c5)]({'where':{'id':(0x0,typeorm_1['In'])(_0x26bcea)}});return _0x197bf3[_0x20d6d1(0x184)](_0x2e3100=>{const _0x2386ca=_0x20d6d1,{typeId:_0x343e5b,appId:_0x59a043}=_0x2e3100;return _0x2e3100[_0x2386ca(0x25d)]=_0x40e9da[_0x2386ca(0x1c5)](_0x537f6d=>_0x537f6d['id']===_0x343e5b),_0x2e3100[_0x2386ca(0x21c)]=_0x35cc89[_0x2386ca(0x1c5)](_0x5747a7=>_0x5747a7['id']===_0x59a043),_0x2e3100;});}async[_0x32fb10(0x26e)](){const _0x216cf6=_0x32fb10,_0x5a059c=await this[_0x216cf6(0x191)][_0x216cf6(0x1c5)]({'order':{'order':_0x216cf6(0x278)},'where':{'status':!![]}}),_0x4fdc1a=await this[_0x216cf6(0x17e)][_0x216cf6(0x1c5)]({'where':{'status':!![]}}),_0x49eb7e=[...new Set(_0x4fdc1a[_0x216cf6(0x184)](_0x318600=>_0x318600['appId']))],_0x43cf8a=await this[_0x216cf6(0x1ae)]['find']({'where':{'id':(0x0,typeorm_1['In'])(_0x49eb7e)}});return _0x4fdc1a[_0x216cf6(0x268)](_0x454f40=>{const _0xa34a48=_0x216cf6,_0x1800b2=_0x43cf8a[_0xa34a48(0x1c5)](_0x288d18=>_0x288d18['id']===_0x454f40[_0xa34a48(0x1b9)]);return _0x454f40['coverImg']=_0x1800b2===null||_0x1800b2===void 0x0?void 0x0:_0x1800b2['coverImg'],_0x454f40;}),_0x5a059c['map'](_0x31a4ea=>{const _0x4eb508=_0x216cf6;return _0x31a4ea[_0x4eb508(0x20e)]=_0x4fdc1a[_0x4eb508(0x254)](_0x4b2184=>_0x4b2184[_0x4eb508(0x276)]===_0x31a4ea['id']&&_0x4b2184[_0x4eb508(0x1b1)]),_0x31a4ea;});}async[_0x32fb10(0x216)](_0x1786c3,_0x3a2e43){const _0xf3a95d=_0x32fb10;try{const {name:_0x5e0a33,icon:_0x1be696,order:_0x5777e7,id:_0x3c1155,status:_0x5364c4}=_0x3a2e43;return _0x3c1155?await this[_0xf3a95d(0x20f)][_0xf3a95d(0x1f6)]({'id':_0x3c1155},{'name':_0x5e0a33,'icon':_0x1be696,'order':_0x5777e7,'status':_0x5364c4}):await this[_0xf3a95d(0x20f)][_0xf3a95d(0x235)]({'name':_0x5e0a33,'icon':_0x1be696,'order':_0x5777e7,'status':_0x5364c4});}catch(_0x1573e3){console[_0xf3a95d(0x185)]('error:\x20',_0x1573e3);}}async[_0x32fb10(0x26c)](_0xd6265d,_0x529b27){const _0x4e56af=_0x32fb10,{id:_0x2dcb35}=_0x529b27;if(!_0x2dcb35)throw new common_1[(_0x4e56af(0x173))](_0x4e56af(0x1ea),common_1['HttpStatus'][_0x4e56af(0x218)]);const _0x474931=await this[_0x4e56af(0x17e)][_0x4e56af(0x1cf)]({'where':{'typeId':_0x2dcb35}});if(_0x474931)throw new common_1[(_0x4e56af(0x173))](_0x4e56af(0x1a6),common_1['HttpStatus']['BAD_REQUEST']);return await this[_0x4e56af(0x20f)]['delete']({'id':_0x2dcb35});}async[_0x32fb10(0x23e)](){const _0x5cebf7=_0x32fb10;return await this[_0x5cebf7(0x20f)][_0x5cebf7(0x1c5)]({'order':{'order':_0x5cebf7(0x278)}});}async[_0x32fb10(0x18d)](_0x4c1925,_0xb52088){const _0x1dc72a=_0x32fb10,{title:_0x4fb516,prompt:_0x4d7305,appId:_0x5b680c,order:_0x10b397,status:_0xf0ea0c,typeId:_0x273bd6,id:_0x5d345f,url:_0x1a5ff6}=_0xb52088;if(!_0x273bd6)throw new common_1[(_0x1dc72a(0x173))](_0x1dc72a(0x1f3),common_1['HttpStatus'][_0x1dc72a(0x218)]);try{const _0x455cca={'title':_0x4fb516,'prompt':_0x4d7305,'order':_0x10b397,'status':_0xf0ea0c,'typeId':_0x273bd6,'url':_0x1a5ff6};return _0x5d345f?await this[_0x1dc72a(0x177)]['update']({'id':_0x5d345f},_0x455cca):await this['chatPreEntity'][_0x1dc72a(0x235)](_0x455cca);}catch(_0x526173){console[_0x1dc72a(0x185)](_0x1dc72a(0x252),_0x526173);}}async['delChatPre'](_0x48ac91,_0x165e36){const _0x62f354=_0x32fb10,{id:_0x213f77}=_0x165e36;if(!_0x213f77)throw new common_1[(_0x62f354(0x173))]('非法操作!',common_1[_0x62f354(0x1ac)][_0x62f354(0x218)]);return await this[_0x62f354(0x177)][_0x62f354(0x182)]({'id':_0x213f77});}async[_0x32fb10(0x19b)](){const _0x116b05=_0x32fb10,_0x48b512=await this[_0x116b05(0x177)][_0x116b05(0x1c5)]({'order':{'order':_0x116b05(0x278)}}),_0x3b1cd4=[...new Set(_0x48b512[_0x116b05(0x184)](_0x1d7c4f=>_0x1d7c4f[_0x116b05(0x276)]))],_0x50ef74=await this[_0x116b05(0x20f)][_0x116b05(0x1c5)]({'where':{'id':(0x0,typeorm_1['In'])(_0x3b1cd4)}});return _0x48b512[_0x116b05(0x184)](_0x2936db=>{const _0x736959=_0x116b05,{typeId:_0x199453,appId:_0x2a45a7}=_0x2936db;return _0x2936db['typeInfo']=_0x50ef74[_0x736959(0x1c5)](_0x4d7697=>_0x4d7697['id']===_0x199453),_0x2936db;});}async[_0x32fb10(0x1c0)](){const _0x3f2c7b=_0x32fb10,_0x437ea0=await this[_0x3f2c7b(0x20f)][_0x3f2c7b(0x1c5)]({'order':{'order':_0x3f2c7b(0x278)},'where':{'status':!![]}}),_0x36a906=await this['chatPreEntity'][_0x3f2c7b(0x1c5)]({'where':{'status':!![]}});return _0x437ea0[_0x3f2c7b(0x184)](_0x3745ee=>{const _0x123e7d=_0x3f2c7b;return _0x3745ee[_0x123e7d(0x20e)]=_0x36a906[_0x123e7d(0x254)](_0x56416c=>_0x56416c['typeId']===_0x3745ee['id']&&_0x56416c['status']),_0x3745ee;});}async[_0x32fb10(0x17b)](_0x30a37a,_0x461032,_0x14c5de){const _0x5e07e7=_0x32fb10;let _0x36faa1=0x1000,_0x2fc1c5=0x800;return _0x30a37a['toLowerCase']()[_0x5e07e7(0x1db)](_0x5e07e7(0x183))&&(_0x36faa1=_0x461032>=0x2004?0x2004:_0x461032,_0x2fc1c5=_0x14c5de>=0x1000?0x1000:_0x14c5de,_0x30a37a[_0x5e07e7(0x1f1)]()[_0x5e07e7(0x1db)]('32k')&&(_0x36faa1=_0x461032>=0x8000?0x8000:_0x461032,_0x2fc1c5=_0x14c5de>=0x3e80?0x3e80:_0x14c5de),(_0x30a37a[_0x5e07e7(0x1f1)]()['includes'](_0x5e07e7(0x274))||_0x30a37a['toLowerCase']()[_0x5e07e7(0x1db)](_0x5e07e7(0x253)))&&(_0x36faa1=_0x461032>=0x1f400?0x1f400:_0x461032,_0x2fc1c5=_0x14c5de>=0x1000?0x1000:_0x14c5de)),_0x30a37a[_0x5e07e7(0x1f1)]()[_0x5e07e7(0x1db)](_0x5e07e7(0x175))&&(_0x36faa1=_0x461032>=0x1000?0x1000:_0x461032,_0x2fc1c5=_0x14c5de>=0x800?0x800:_0x14c5de,_0x30a37a['toLowerCase']()[_0x5e07e7(0x1db)](_0x5e07e7(0x241))&&(_0x36faa1=_0x461032>=0x4000?0x4000:_0x461032,_0x2fc1c5=_0x14c5de>=0x1f40?0x1f40:_0x14c5de),_0x30a37a['toLowerCase']()[_0x5e07e7(0x1db)](_0x5e07e7(0x1d9))&&(_0x36faa1=_0x461032>=0x4000?0x4000:_0x461032,_0x2fc1c5=_0x14c5de>=0x1f40?0x1f40:_0x14c5de)),{'maxToken':_0x36faa1,'maxRes':_0x2fc1c5};}};ChatgptService=__decorate([(0x0,common_1[_0x32fb10(0x267)])(),__param(0x0,(0x0,typeorm_2['InjectRepository'])(gptkeys_entity_1[_0x32fb10(0x21a)])),__param(0x1,(0x0,typeorm_2[_0x32fb10(0x1d7)])(config_entity_1['ConfigEntity'])),__param(0x2,(0x0,typeorm_2[_0x32fb10(0x1d7)])(chatBoxType_entity_1[_0x32fb10(0x1a5)])),__param(0x3,(0x0,typeorm_2['InjectRepository'])(chatBox_entity_1[_0x32fb10(0x1c9)])),__param(0x4,(0x0,typeorm_2['InjectRepository'])(app_entity_1[_0x32fb10(0x1cc)])),__param(0x5,(0x0,typeorm_2[_0x32fb10(0x1d7)])(chatPreType_entity_1[_0x32fb10(0x256)])),__param(0x6,(0x0,typeorm_2['InjectRepository'])(chatPre_entity_1[_0x32fb10(0x1b6)])),__metadata('design:paramtypes',[typeorm_1[_0x32fb10(0x1f4)],typeorm_1['Repository'],typeorm_1[_0x32fb10(0x1f4)],typeorm_1[_0x32fb10(0x1f4)],typeorm_1[_0x32fb10(0x1f4)],typeorm_1[_0x32fb10(0x1f4)],typeorm_1[_0x32fb10(0x1f4)],nestjs_config_1[_0x32fb10(0x217)],userBalance_service_1[_0x32fb10(0x22c)],chatLog_service_1[_0x32fb10(0x250)],user_service_1[_0x32fb10(0x283)],upload_service_1[_0x32fb10(0x220)],badwords_service_1[_0x32fb10(0x176)],autoreply_service_1[_0x32fb10(0x180)],globalConfig_service_1['GlobalConfigService'],fanyi_service_1['FanyiService'],chatGroup_service_1[_0x32fb10(0x240)],models_service_1[_0x32fb10(0x1d5)]])],ChatgptService),exports['ChatgptService']=ChatgptService;