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

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 _0x21f677=_0x4881;(function(_0x50a027,_0x22d107){const _0x31ee33=_0x4881,_0x26eec8=_0x50a027();while(!![]){try{const _0x2d32b5=parseInt(_0x31ee33(0x204))/0x1*(-parseInt(_0x31ee33(0x19e))/0x2)+parseInt(_0x31ee33(0x1f9))/0x3+parseInt(_0x31ee33(0x120))/0x4+parseInt(_0x31ee33(0x139))/0x5*(parseInt(_0x31ee33(0x200))/0x6)+parseInt(_0x31ee33(0x1a2))/0x7+-parseInt(_0x31ee33(0x1c1))/0x8+parseInt(_0x31ee33(0x10a))/0x9*(-parseInt(_0x31ee33(0x13e))/0xa);if(_0x2d32b5===_0x22d107)break;else _0x26eec8['push'](_0x26eec8['shift']());}catch(_0x468cc0){_0x26eec8['push'](_0x26eec8['shift']());}}}(_0x535a,0x7adc5));function _0x4881(_0x230349,_0x556c91){const _0x535a77=_0x535a();return _0x4881=function(_0x4881c7,_0x6bb4d7){_0x4881c7=_0x4881c7-0xff;let _0xc606cb=_0x535a77[_0x4881c7];return _0xc606cb;},_0x4881(_0x230349,_0x556c91);}var __decorate=this&&this['__decorate']||function(_0x1bca56,_0x4a9aec,_0xfcc384,_0x5b29fc){const _0xdf14e3=_0x4881;var _0x4984cb=arguments[_0xdf14e3(0x108)],_0x120109=_0x4984cb<0x3?_0x4a9aec:_0x5b29fc===null?_0x5b29fc=Object[_0xdf14e3(0x11f)](_0x4a9aec,_0xfcc384):_0x5b29fc,_0x1edbcd;if(typeof Reflect===_0xdf14e3(0x122)&&typeof Reflect[_0xdf14e3(0x1ca)]===_0xdf14e3(0x17b))_0x120109=Reflect[_0xdf14e3(0x1ca)](_0x1bca56,_0x4a9aec,_0xfcc384,_0x5b29fc);else{for(var _0xb4f56e=_0x1bca56[_0xdf14e3(0x108)]-0x1;_0xb4f56e>=0x0;_0xb4f56e--)if(_0x1edbcd=_0x1bca56[_0xb4f56e])_0x120109=(_0x4984cb<0x3?_0x1edbcd(_0x120109):_0x4984cb>0x3?_0x1edbcd(_0x4a9aec,_0xfcc384,_0x120109):_0x1edbcd(_0x4a9aec,_0xfcc384))||_0x120109;}return _0x4984cb>0x3&&_0x120109&&Object[_0xdf14e3(0x1a4)](_0x4a9aec,_0xfcc384,_0x120109),_0x120109;},__metadata=this&&this['__metadata']||function(_0x2feea,_0x316b02){const _0xf88399=_0x4881;if(typeof Reflect==='object'&&typeof Reflect[_0xf88399(0x1c9)]===_0xf88399(0x17b))return Reflect['metadata'](_0x2feea,_0x316b02);},__param=this&&this[_0x21f677(0x208)]||function(_0x38d08d,_0x5387f7){return function(_0x249a66,_0x39e96a){_0x5387f7(_0x249a66,_0x39e96a,_0x38d08d);};};function _0x535a(){const _0x3cb1a0=['@keyv/redis','sendMessageFromOpenAi','UserService','This\x20is\x20not\x20a\x20chat\x20model\x20and\x20thus\x20not\x20supported','20fBkDIX','../../common/constants/balance.constant','draw\x20paompt\x20info\x20<==**==>\x20','./../user/user.service','keyv','Injectable','model','uploadService','chatBoxTypeEntity','buildMessageFromParentMessageId','gptKeysEntity','abortController','key','detail','findOne','imageUrl','chatBoxEntity','saveChatLog','axios','floor','openaiModel3MaxTokens16kRes','PAINT_TYPE','当前模型key已被封禁','nineai-chatlog','conversationId','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters','usage','configService',',\x20消耗积分\x20','当前模型不是聊天模型','globalConfigService','openaiBaseUrl','delChatBox','queryChatBoxFrontend','openaiModel3MaxTokensRes','removeSpecialCharacters','openaiProxyUrl','preset','当前Key余额已不足、请重新再试一次吧','openaiModel4MaxTokens','@nestjs/common','response','chatPreTypeEntity','log','getClientIp','ModelsService','16k','onModuleInit','find','is_end','setHeader','user','ChatGroupService','The\x20OpenAI\x20account\x20associated\x20with\x20this\x20API\x20key\x20has\x20been\x20deactivated.','prompt','forEach','openaiModel3MaxTokens','queryChatPreType','../../common/utils','saveUseLog','getUploadType','function','whiteListUser','status','PAYMENT_REQUIRED','map','statusText:','chatgpt-ai-web','getTokenCount','save','billing','queryChatPreList','你当前使用的应用已被下架、请删除当前对话开启新的对话吧!','@nestjs/typeorm','GlobalConfigService','post','childList','env','slice','deductFromBalance','AutoreplyService','formatModelToken','当前模型不是聊天模型、已冻结当前调用Key、请重新尝试对话','服务异常、请重新试试吧!!!','maxModelTokens','setChatPre',',\x20key\x20===>\x20','UserBalanceService','push','compileNetwork','openaiModel4MaxTokensRes','setChatPreType','OpenAiErrorCodeMessage','https://api.openai.com','stringify','text','10HGOUvu','CHAT_TYPE','includes','typeorm','5454596rRiAhe','autoreplyService','defineProperty','userService','error:\x20','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','delChatPreType','../chatGroup/chatGroup.service','toISOString','REDIS_USER','badwordsService','setChatBox','./gptkeys.entity','checkAutoReply','getMaxTokenFromModelWithOpenAi','uploadFile','draw','message','getConfigs','./helper','appEntity','getRandomDrawKey','getCurrentModelKeyInfo','assistant','delChatBoxType','InjectRepository','nineStore','chatLogService','DeductionKey','typeInfo','ConfigEntity','4365144nNCdTz','data','BAD_REQUEST','./chatPreType.entity','result','Repository','abort','code:\x20','metadata','decorate','application/octet-stream;\x20charset=utf-8','chat-error\x20<----------------------------------------->','ConfigService','../chatLog/chatLog.service','400\x20error','当前请求已过载、请稍等会儿再试试吧!','当前流程所需要的模型已被管理员下架、请联系管理员上架专属模型!','sendMessageFromBaidu','chatGroupService','size','filter','statusCode','../globalConfig/globalConfig.service','\x0a\x20Current\x20date:\x20','chatPreEntity','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧','../autoreply/autoreply.service','当前模型调用过于频繁、请重新试试吧!','DESC','getGroupInfoFromId','getUuid','绘制图片失败,请稍后试试吧!','Incorrect\x20API\x20key\x20provided','openaiModel4MaxTokens32kRes','uuid','base64','write','./chatBoxType.entity','lockKey','systemMessage','typeId','maxResponseTokens','setData','32k','openaiModel3MaxTokens16k','appId','../app/app.entity','design:paramtypes','getModelProxyUrl','REDIS_PORT','from','nestjs-config','ChatgptService','HttpStatus','assign','model4','2078070gMerjN','Bearer\x20','checkBadWords','当前分类下有未处理数据不可移除!','dall-e-3','error','delChatPre','330MfxdoJ','addOneIfOdd','./baidu','systemPreMessage','153128uhqDuS','delete','count','getRequestParams','__param','config','REDIS_PASSWORD','ChatBoxEntity','keyPool','checkUserStatus','end','userBalanceService','/v1/images/generations','Content-type','ChatLogService','缺失必要参数!','length','Billing\x20hard\x20limit\x20has\x20been\x20reached','1686753BuqVyy','./chatBox.entity','importDynamic','提供了错误的模型秘钥、已冻结当前调用Key、请重新尝试对话','ChatPreEntity','validateBalance','../../common/constants/errorMessage.constant','update','openaiTimeoutMs','mjDraw','getAllKeyList','queryChatPre','getBaseConfig','chat','dall','../fanyi/fanyi.service','AppEntity','modelInfo','./../upload/upload.service','proxyUrl','toLowerCase','getOwnPropertyDescriptor','1019764ahymMw','GptKeysEntity','object','default','modelsService','openaiModel4MaxTokens32k','Catch\x20Error\x20','unifiedFormattingResponse','../userBalance/userBalance.service','chatProcess','all','split','Please\x20check\x20the\x20back-end\x20console','gpt-3','queryChatBox','REDIS_HOST','非法操作!','sendMessageFromZhipu','../globalConfig/config.entity','1106','standard','HttpException','Logger','coverImg','quality','42045uVBTSi'];_0x535a=function(){return _0x3cb1a0;};return _0x535a();}Object[_0x21f677(0x1a4)](exports,'__esModule',{'value':!![]}),exports[_0x21f677(0x1f5)]=void 0x0;const upload_service_1=require(_0x21f677(0x11c)),user_service_1=require(_0x21f677(0x141)),nestjs_config_1=require(_0x21f677(0x1f4)),common_1=require(_0x21f677(0x166)),errorMessage_constant_1=require(_0x21f677(0x110)),utils_1=require(_0x21f677(0x178)),axios_1=require(_0x21f677(0x150)),userBalance_service_1=require(_0x21f677(0x128)),balance_constant_1=require(_0x21f677(0x13f)),chatLog_service_1=require(_0x21f677(0x1ce)),uuid=require(_0x21f677(0x1e3)),config_entity_1=require(_0x21f677(0x132)),typeorm_1=require(_0x21f677(0x1a1)),typeorm_2=require(_0x21f677(0x187)),badwords_service_1=require('../badwords/badwords.service'),autoreply_service_1=require(_0x21f677(0x1db)),gptkeys_entity_1=require(_0x21f677(0x1ae)),globalConfig_service_1=require(_0x21f677(0x1d7)),fanyi_service_1=require(_0x21f677(0x119)),app_entity_1=require(_0x21f677(0x1ef)),chatGroup_service_1=require(_0x21f677(0x1a9)),models_service_1=require('../models/models.service'),baidu_1=require(_0x21f677(0x202)),helper_1=require(_0x21f677(0x1b5)),store_1=require('./store'),zhipu_1=require('./zhipu'),openai_1=require('./openai'),chatBoxType_entity_1=require(_0x21f677(0x1e6)),chatBox_entity_1=require(_0x21f677(0x10b)),chatPre_entity_1=require('./chatPre.entity'),chatPreType_entity_1=require(_0x21f677(0x1c4));let ChatgptService=class ChatgptService{constructor(_0x3b53ee,_0x45634b,_0x21303d,_0x19872b,_0x2ac0b6,_0x41330f,_0x3cf8f8,_0x63df56,_0x571b9b,_0x3a306a,_0x3810f0,_0x239e35,_0x3f3f28,_0xc47afe,_0x570807,_0xe7381,_0x4e680c,_0x510f11){const _0x294ba6=_0x21f677;this[_0x294ba6(0x148)]=_0x3b53ee,this['configEntity']=_0x45634b,this['chatBoxTypeEntity']=_0x21303d,this['chatBoxEntity']=_0x19872b,this[_0x294ba6(0x1b6)]=_0x2ac0b6,this['chatPreTypeEntity']=_0x41330f,this[_0x294ba6(0x1d9)]=_0x3cf8f8,this[_0x294ba6(0x159)]=_0x63df56,this[_0x294ba6(0x103)]=_0x571b9b,this['chatLogService']=_0x3a306a,this[_0x294ba6(0x1a5)]=_0x3810f0,this[_0x294ba6(0x145)]=_0x239e35,this[_0x294ba6(0x1ac)]=_0x3f3f28,this['autoreplyService']=_0xc47afe,this[_0x294ba6(0x15c)]=_0x570807,this['fanyiService']=_0xe7381,this['chatGroupService']=_0x4e680c,this[_0x294ba6(0x124)]=_0x510f11,this['nineStore']=null,this[_0x294ba6(0x17c)]=[],this[_0x294ba6(0x100)]={'list3':[],'list4':[]};}async[_0x21f677(0x16d)](){const _0x51762f=_0x21f677;let _0x3625cb=await(0x0,utils_1['importDynamic'])(_0x51762f(0x181)),_0x46b4bc=await(0x0,utils_1['importDynamic'])(_0x51762f(0x13a)),_0x30c1d3=await(0x0,utils_1[_0x51762f(0x10c)])(_0x51762f(0x142));_0x3625cb=(_0x3625cb===null||_0x3625cb===void 0x0?void 0x0:_0x3625cb[_0x51762f(0x123)])?_0x3625cb[_0x51762f(0x123)]:_0x3625cb,_0x46b4bc=(_0x46b4bc===null||_0x46b4bc===void 0x0?void 0x0:_0x46b4bc['default'])?_0x46b4bc[_0x51762f(0x123)]:_0x46b4bc,_0x30c1d3=(_0x30c1d3===null||_0x30c1d3===void 0x0?void 0x0:_0x30c1d3[_0x51762f(0x123)])?_0x30c1d3[_0x51762f(0x123)]:_0x30c1d3;const {ChatGPTAPI:_0x3cf080,ChatGPTError:_0x45c9a9,ChatGPTUnofficialProxyAPI:_0x12d3f2}=_0x3625cb,_0x5d9488=+process[_0x51762f(0x18b)][_0x51762f(0x1f2)],_0x44ccd9=process[_0x51762f(0x18b)][_0x51762f(0x12f)],_0x316174=process[_0x51762f(0x18b)][_0x51762f(0x20a)],_0x37bcf2=process[_0x51762f(0x18b)][_0x51762f(0x1ab)],_0x2132ca='redis://'+(_0x37bcf2||'')+':'+(_0x316174||'')+'@'+_0x44ccd9+':'+_0x5d9488,_0x533200=new _0x46b4bc(_0x2132ca),_0x406f10=new _0x30c1d3({'store':_0x533200,'namespace':_0x51762f(0x155)});this[_0x51762f(0x1bc)]=new store_1['NineStore']({'store':_0x406f10,'namespace':_0x51762f(0x117)});}async[_0x21f677(0x207)](_0x486239,_0xa13fcd,_0x467bd0,_0x168426=null){const _0x26d4f3=_0x21f677;var _0x1c2678;!_0x168426&&(_0x168426=(_0x1c2678=await this['modelsService'][_0x26d4f3(0x116)]())===null||_0x1c2678===void 0x0?void 0x0:_0x1c2678[_0x26d4f3(0x11b)]);const {timeout:timeout=0x3c}=_0x467bd0,{topN:_0x412a64,model:_0x5662c6}=_0x168426,{parentMessageId:parentMessageId=0x0}=_0x486239,_0x4a3600=await this[_0x26d4f3(0x15c)][_0x26d4f3(0x1b4)]([_0x26d4f3(0x112)]),_0xc55f04=timeout*0x3e8||_0x4a3600||0x64*0x3e8,_0xc67e82={'parentMessageId':parentMessageId,'timeoutMs':+_0xc55f04,'completionParams':{'model':_0x5662c6,'temperature':_0x412a64}};return _0xa13fcd&&(_0xc67e82[_0x26d4f3(0x1e8)]=_0xa13fcd),_0xc67e82;}async['chatSyncFree'](_0x266386){const _0x12cdfe=_0x21f677,_0x12aebe=await this[_0x12cdfe(0x124)][_0x12cdfe(0x1b7)](),_0x1e2e25=await this[_0x12cdfe(0x15c)]['getConfigs']([_0x12cdfe(0x203)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x4fe9f0,model:_0x27c201}=_0x12aebe,_0x21edf7=await this[_0x12cdfe(0x1f1)](_0x12aebe),{context:_0x58ade9}=await this[_0x12cdfe(0x1bc)][_0x12cdfe(0x147)](_0x266386,{'parentMessageId':'','systemMessage':_0x1e2e25});try{const _0x3643d1=await(0x0,openai_1[_0x12cdfe(0x13b)])(_0x58ade9,{'apiKey':(0x0,utils_1[_0x12cdfe(0x161)])(_0x4fe9f0),'model':_0x27c201,'proxyUrl':_0x21edf7,'onProgress':null});return _0x3643d1===null||_0x3643d1===void 0x0?void 0x0:_0x3643d1[_0x12cdfe(0x19d)];}catch(_0x5a0aef){console['log'](_0x12cdfe(0x1a6),_0x5a0aef);}}async[_0x21f677(0x129)](_0x2c9e0e,_0x5e695b,_0x313bbb){const _0x3a38f6=_0x21f677;var _0x28b7ea,_0x49f877,_0x14cf7d,_0x3447d9;const _0x19bd5d=_0x5e695b[_0x3a38f6(0x149)],{options:options={},appId:_0x1581d0,cusromPrompt:_0x1eb42a,systemMessage:systemMessage=''}=_0x2c9e0e;let _0x17c007=systemMessage;const {parentMessageId:_0x1185f5}=options,{prompt:_0x1bcf9d,imageUrl:_0x323c7a,model:_0x5b7241}=_0x2c9e0e,{groupId:_0x38e778,usingNetwork:_0x67671c}=options,_0x57568c=await this[_0x3a38f6(0x1d3)][_0x3a38f6(0x1de)](_0x38e778),_0x26cad2=(_0x57568c===null||_0x57568c===void 0x0?void 0x0:_0x57568c[_0x3a38f6(0x209)])?JSON['parse'](_0x57568c[_0x3a38f6(0x209)]):await this[_0x3a38f6(0x124)]['getBaseConfig'](),{keyType:_0x3fe850,model:_0x11162f,topN:_0x3c56dc,systemMessage:_0x441b99,rounds:_0x18c8a6}=_0x26cad2[_0x3a38f6(0x11b)];let _0x3cc4b6=null;!_0x1eb42a?_0x3cc4b6=await this['modelsService'][_0x3a38f6(0x1b8)](_0x11162f):_0x3cc4b6=await this['modelsService'][_0x3a38f6(0x1b7)]();if(!_0x3cc4b6)throw new common_1[(_0x3a38f6(0x135))](_0x3a38f6(0x1d1),common_1['HttpStatus']['BAD_REQUEST']);const {deduct:_0x4ec9d4,isTokenBased:_0x160446,tokenFeeRatio:_0x14fcdc,deductType:_0x58e628,key:_0x63c3f2,secret:_0x3fbaf8,modelName:_0x2e1d99,id:_0x4d4c62,accessToken:_0x5e8170}=_0x3cc4b6;await this[_0x3a38f6(0x1a5)][_0x3a38f6(0x101)](_0x5e695b['user']),await this[_0x3a38f6(0x103)][_0x3a38f6(0x10f)](_0x5e695b,_0x58e628===0x1?'model3':_0x3a38f6(0x1f8),_0x4ec9d4),_0x313bbb&&_0x313bbb[_0x3a38f6(0x170)](_0x3a38f6(0x105),_0x3a38f6(0x1cb)),await this[_0x3a38f6(0x1ac)]['checkBadWords'](_0x1bcf9d,_0x5e695b[_0x3a38f6(0x171)]['id']);const _0x108db4=await this[_0x3a38f6(0x1a3)][_0x3a38f6(0x1af)](_0x1bcf9d);if(_0x108db4&&_0x313bbb){const _0x545d89={'message':_0x108db4,'code':0x1f4};return _0x313bbb[_0x3a38f6(0x1e5)](JSON['stringify'](_0x545d89)),_0x313bbb[_0x3a38f6(0x102)]();}if(_0x1581d0){const _0x5731f5=await this[_0x3a38f6(0x1b6)][_0x3a38f6(0x14c)]({'where':{'id':_0x1581d0,'status':(0x0,typeorm_1['In'])([0x1,0x3,0x4,0x5])}});if(!_0x5731f5)throw new common_1[(_0x3a38f6(0x135))](_0x3a38f6(0x186),common_1[_0x3a38f6(0x1f6)]['BAD_REQUEST']);_0x5731f5[_0x3a38f6(0x163)]&&(_0x17c007=_0x5731f5[_0x3a38f6(0x163)]);}else{if(_0x1eb42a)_0x17c007=systemMessage;else{if(_0x441b99)_0x17c007=_0x441b99;else{const _0x132874=new Date()[_0x3a38f6(0x1aa)]()['split']('T')[0x0],_0x545ec1=await this[_0x3a38f6(0x15c)][_0x3a38f6(0x1b4)]([_0x3a38f6(0x203)]);_0x17c007=_0x545ec1+(_0x3a38f6(0x1d8)+_0x132874);}}}let _0x4ab3b2='';if(_0x67671c){_0x4ab3b2=await(0x0,utils_1[_0x3a38f6(0x197)])(_0x1bcf9d);const _0x5f5479=new Date()[_0x3a38f6(0x1aa)]()[_0x3a38f6(0x12b)]('T')[0x0],_0x4ac52f=await this[_0x3a38f6(0x15c)][_0x3a38f6(0x1b4)]([_0x3a38f6(0x203)]);_0x17c007=_0x4ac52f+(_0x3a38f6(0x1d8)+_0x5f5479);}const _0x3aac60=await this[_0x3a38f6(0x207)](options,_0x17c007,_0x3cc4b6,_0x26cad2[_0x3a38f6(0x11b)]),{maxModelTokens:maxModelTokens=0x1f40,maxResponseTokens:maxResponseTokens=0x1000,key:_0x33e20b}=_0x3cc4b6;_0x313bbb&&_0x313bbb[_0x3a38f6(0x17d)](0xc8);let _0x5d5750=null,_0x104830=null;try{if(_0x313bbb){let _0x57dccc=null,_0x5e2dd2=![];_0x313bbb['on']('close',async()=>{const _0x35a3ec=_0x3a38f6;if(_0x5e2dd2)return;_0x19bd5d[_0x35a3ec(0x1c7)]();const _0x1074b2=await(0x0,openai_1['getTokenCount'])(_0x1bcf9d)||0x0,_0x1a4b3b=await(0x0,openai_1[_0x35a3ec(0x182)])(_0x57dccc===null||_0x57dccc===void 0x0?void 0x0:_0x57dccc[_0x35a3ec(0x19d)])||0x0,_0x2a86bf=_0x1074b2+_0x1a4b3b,_0x385911=(0x0,utils_1[_0x35a3ec(0x16a)])(_0x5e695b);await this[_0x35a3ec(0x1bd)][_0x35a3ec(0x14f)]({'appId':_0x1581d0,'curIp':_0x385911,'userId':_0x5e695b[_0x35a3ec(0x171)]['id'],'type':balance_constant_1[_0x35a3ec(0x1be)][_0x35a3ec(0x19f)],'prompt':_0x1bcf9d,'imageUrl':_0x323c7a,'activeModel':_0x5b7241,'answer':'','promptTokens':_0x1074b2,'completionTokens':0x0,'totalTokens':_0x1074b2,'model':_0x11162f,'role':_0x35a3ec(0x171),'groupId':_0x38e778,'requestOptions':JSON[_0x35a3ec(0x19c)]({'options':null,'prompt':_0x1bcf9d})}),await this[_0x35a3ec(0x1bd)][_0x35a3ec(0x14f)]({'appId':_0x1581d0,'curIp':_0x385911,'userId':_0x5e695b[_0x35a3ec(0x171)]['id'],'type':balance_constant_1[_0x35a3ec(0x1be)]['CHAT_TYPE'],'prompt':_0x1bcf9d,'answer':_0x57dccc===null||_0x57dccc===void 0x0?void 0x0:_0x57dccc[_0x35a3ec(0x19d)],'promptTokens':_0x1074b2,'completionTokens':_0x1a4b3b,'totalTokens':_0x2a86bf,'model':_0x11162f,'role':_0x35a3ec(0x1b9),'groupId':_0x38e778,'requestOptions':JSON[_0x35a3ec(0x19c)]({'options':{'model':_0x11162f,'temperature':_0x3c56dc},'prompt':_0x1bcf9d}),'conversationOptions':JSON[_0x35a3ec(0x19c)]({'conversationId':_0x57dccc===null||_0x57dccc===void 0x0?void 0x0:_0x57dccc['conversationId'],'model':_0x11162f,'parentMessageId':_0x57dccc===null||_0x57dccc===void 0x0?void 0x0:_0x57dccc['id'],'temperature':_0x3c56dc})});let _0xd2c048=_0x4ec9d4;_0x160446===!![]&&(_0xd2c048=Math['ceil'](_0x4ec9d4*_0x2a86bf/_0x14fcdc)),await this[_0x35a3ec(0x103)]['deductFromBalance'](_0x5e695b[_0x35a3ec(0x171)]['id'],_0x35a3ec(0x144)+(_0x58e628===0x1?0x3:0x4),_0xd2c048,_0x2a86bf);});if(Number(_0x3fe850)===0x1){const {key:_0x506969,maxToken:_0x1de76e,maxTokenRes:_0x496cb1,proxyResUrl:_0x38f118}=await this[_0x3a38f6(0x18f)](_0x3cc4b6),{parentMessageId:_0x3c8cc5,completionParams:_0x185fb6,systemMessage:_0x258d1b}=_0x3aac60,{model:_0x14056a,temperature:_0x1083b0}=_0x185fb6,{context:_0x4d58f1}=await this['nineStore']['buildMessageFromParentMessageId'](_0x67671c?_0x4ab3b2:_0x1bcf9d,{'parentMessageId':_0x3c8cc5,'systemMessage':_0x258d1b,'maxModelToken':_0x1de76e,'maxResponseTokens':_0x496cb1,'maxRounds':(0x0,helper_1[_0x3a38f6(0x201)])(_0x18c8a6),'imageUrl':_0x323c7a,'activeModel':_0x5b7241});let _0x4ca5dd=!![];_0x5d5750=await(0x0,openai_1[_0x3a38f6(0x13b)])(_0x4d58f1,{'maxToken':_0x1de76e,'maxTokenRes':_0x496cb1,'apiKey':_0x63c3f2,'model':_0x14056a,'prompt':_0x1bcf9d,'activeModel':_0x5b7241,'imageUrl':_0x323c7a,'temperature':_0x1083b0,'proxyUrl':_0x38f118,'onProgress':_0x5bad3c=>{const _0x2cce88=_0x3a38f6;_0x313bbb[_0x2cce88(0x1e5)](_0x4ca5dd?JSON[_0x2cce88(0x19c)](_0x5bad3c):'\x0a'+JSON[_0x2cce88(0x19c)](_0x5bad3c)),_0x57dccc=_0x5bad3c,_0x4ca5dd=![];}},this[_0x3a38f6(0x145)]),_0x5e2dd2=!![];}if(Number(_0x3fe850)===0x2){let _0x290030=!![];const {context:_0x50f1f0}=await this['nineStore'][_0x3a38f6(0x147)](_0x67671c?_0x4ab3b2:_0x1bcf9d,{'parentMessageId':_0x1185f5,'maxRounds':(0x0,helper_1[_0x3a38f6(0x201)])(_0x18c8a6)});_0x5d5750=await(0x0,baidu_1[_0x3a38f6(0x1d2)])(_0x67671c?_0x4ab3b2:_0x50f1f0,{'temperature':_0x3c56dc,'accessToken':_0x5e8170,'model':_0x11162f,'onProgress':_0x11b66a=>{const _0x110e22=_0x3a38f6;_0x313bbb[_0x110e22(0x1e5)](_0x290030?JSON['stringify'](_0x11b66a):'\x0a'+JSON[_0x110e22(0x19c)](_0x11b66a)),_0x290030=![],_0x57dccc=_0x11b66a;}}),_0x5e2dd2=!![];}if(Number(_0x3fe850)===0x3){let _0x2e4b85=!![];const {context:_0x12a48e}=await this['nineStore']['buildMessageFromParentMessageId'](_0x67671c?_0x4ab3b2:_0x1bcf9d,{'parentMessageId':_0x1185f5,'maxRounds':(0x0,helper_1['addOneIfOdd'])(_0x18c8a6)});_0x5d5750=await(0x0,zhipu_1[_0x3a38f6(0x131)])(_0x67671c?_0x4ab3b2:_0x12a48e,{'temperature':_0x3c56dc,'key':_0x33e20b,'model':_0x11162f,'onProgress':_0x1a0af=>{const _0xff9867=_0x3a38f6;_0x313bbb[_0xff9867(0x1e5)](_0x2e4b85?JSON['stringify'](_0x1a0af):'\x0a'+JSON[_0xff9867(0x19c)](_0x1a0af)),_0x2e4b85=![],_0x57dccc=_0x1a0af;}}),_0x5e2dd2=!![];}const _0xc34fab={'id':this[_0x3a38f6(0x1bc)][_0x3a38f6(0x1df)](),'text':_0x1bcf9d,'role':_0x3a38f6(0x171),'name':undefined,'usage':null,'imageUrl':_0x323c7a,'activeModel':_0x5b7241,'parentMessageId':_0x1185f5,'conversationId':_0x5d5750===null||_0x5d5750===void 0x0?void 0x0:_0x5d5750[_0x3a38f6(0x156)]};_0x104830={'model':_0x11162f,'parentMessageId':_0x1185f5},await this[_0x3a38f6(0x1bc)][_0x3a38f6(0x1eb)](_0xc34fab);const _0xda0ba2={'id':_0x5d5750['id'],'text':_0x5d5750[_0x3a38f6(0x19d)],'role':_0x3a38f6(0x1b9),'name':undefined,'usage':_0x5d5750===null||_0x5d5750===void 0x0?void 0x0:_0x5d5750[_0x3a38f6(0x158)],'imageUrl':_0x323c7a,'parentMessageId':_0xc34fab['id'],'conversationId':_0x5d5750===null||_0x5d5750===void 0x0?void 0x0:_0x5d5750[_0x3a38f6(0x156)]};await this[_0x3a38f6(0x1bc)]['setData'](_0xda0ba2),_0x104830={'model':_0x11162f,'parentMessageId':_0xc34fab['id']};}else{const {key:_0x27e9a1,maxToken:_0x1c62b2,maxTokenRes:_0x4682bb,proxyResUrl:_0x2ccf1e}=await this[_0x3a38f6(0x18f)](_0x3cc4b6),{parentMessageId:_0x1012a4,completionParams:_0x195dc4,systemMessage:_0x47dbc1}=_0x3aac60,{model:_0xcb9efc,temperature:_0x5bc8c0}=_0x195dc4,{context:_0x4b39ea}=await this[_0x3a38f6(0x1bc)]['buildMessageFromParentMessageId'](_0x67671c?_0x4ab3b2:_0x1bcf9d,{'parentMessageId':_0x1012a4,'systemMessage':_0x47dbc1,'maxRounds':(0x0,helper_1[_0x3a38f6(0x201)])(_0x18c8a6)});_0x5d5750=await(0x0,openai_1[_0x3a38f6(0x13b)])(_0x4b39ea,{'apiKey':_0x63c3f2,'model':_0xcb9efc,'temperature':_0x5bc8c0,'proxyUrl':_0x2ccf1e,'onProgress':null,'prompt':_0x1bcf9d});}let _0x38b1f5=null,_0xdac2f2=null;_0x11162f[_0x3a38f6(0x1a0)]('dall')?_0x38b1f5=((_0x28b7ea=_0x5d5750[_0x3a38f6(0x14b)])===null||_0x28b7ea===void 0x0?void 0x0:_0x28b7ea['usage'])||{'prompt_tokens':0x1,'completion_tokens':0x1,'total_tokens':0x2}:_0xdac2f2=await(0x0,helper_1[_0x3a38f6(0x127)])(_0x3fe850,_0x5d5750,_0x104830);const {prompt_tokens:_0x42eb05,completion_tokens:_0x310c16,total_tokens:_0x5abb63}=_0x11162f[_0x3a38f6(0x1a0)](_0x3a38f6(0x118))?_0x38b1f5:_0xdac2f2['usage'];let _0x11fe58=_0x4ec9d4;_0x160446===!![]&&(_0x11fe58=Math['ceil'](_0x4ec9d4*_0x5abb63/_0x14fcdc));await this[_0x3a38f6(0x103)][_0x3a38f6(0x18d)](_0x5e695b[_0x3a38f6(0x171)]['id'],_0x3a38f6(0x144)+(_0x58e628===0x1?0x3:0x4),_0x11fe58,_0x5abb63),await this[_0x3a38f6(0x124)][_0x3a38f6(0x179)](_0x4d4c62,_0x5abb63);const _0x2420f3=(0x0,utils_1[_0x3a38f6(0x16a)])(_0x5e695b);await this['chatLogService'][_0x3a38f6(0x14f)]({'appId':_0x1581d0,'curIp':_0x2420f3,'userId':_0x5e695b[_0x3a38f6(0x171)]['id'],'type':balance_constant_1[_0x3a38f6(0x1be)]['CHAT_TYPE'],'prompt':_0x1bcf9d,'imageUrl':_0x323c7a,'activeModel':_0x5b7241,'answer':'','promptTokens':_0x42eb05,'completionTokens':0x0,'totalTokens':_0x5abb63,'model':_0x11162f,'role':_0x3a38f6(0x171),'groupId':_0x38e778,'requestOptions':JSON[_0x3a38f6(0x19c)]({'options':null,'prompt':_0x1bcf9d})}),await this[_0x3a38f6(0x1bd)][_0x3a38f6(0x14f)]({'appId':_0x1581d0,'curIp':_0x2420f3,'userId':_0x5e695b['user']['id'],'type':balance_constant_1[_0x3a38f6(0x1be)][_0x3a38f6(0x19f)],'prompt':_0x1bcf9d,'imageUrl':_0x5d5750===null||_0x5d5750===void 0x0?void 0x0:_0x5d5750[_0x3a38f6(0x14d)],'answer':_0x5d5750[_0x3a38f6(0x19d)],'promptTokens':_0x42eb05,'completionTokens':_0x310c16,'totalTokens':_0x5abb63,'model':_0x11162f,'role':_0x3a38f6(0x1b9),'groupId':_0x38e778,'requestOptions':JSON['stringify']({'options':{'model':_0x11162f,'temperature':_0x3c56dc},'prompt':_0x1bcf9d}),'conversationOptions':JSON[_0x3a38f6(0x19c)]({'conversationId':_0x5d5750[_0x3a38f6(0x156)],'model':_0x11162f,'parentMessageId':_0x5d5750['id'],'temperature':_0x3c56dc})}),common_1[_0x3a38f6(0x136)]['debug']('用户ID:\x20'+_0x5e695b[_0x3a38f6(0x171)]['id']+'\x20模型名称:\x20'+_0x2e1d99+'-'+_0x5b7241+',\x20消耗token:\x20'+_0x5abb63+_0x3a38f6(0x15a)+_0x11fe58,_0x3a38f6(0x1f5));const _0x1bc88a=await this['userBalanceService']['queryUserBalance'](_0x5e695b[_0x3a38f6(0x171)]['id']);return _0x5d5750['userBanance']=Object[_0x3a38f6(0x1f7)]({},_0x1bc88a),_0x5d5750['result']&&(_0x5d5750[_0x3a38f6(0x1c5)]=''),_0x5d5750[_0x3a38f6(0x16f)]=!![],_0x313bbb?_0x313bbb[_0x3a38f6(0x1e5)]('\x0a'+JSON['stringify'](_0x5d5750)):_0x5d5750[_0x3a38f6(0x19d)];}catch(_0x39f4ed){console[_0x3a38f6(0x169)](_0x3a38f6(0x1cc),_0x63c3f2,_0x39f4ed);const _0x269c22=(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1d6)])||0x190,_0x34775a=((_0x49f877=_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x167)])===null||_0x49f877===void 0x0?void 0x0:_0x49f877['status'])||(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1d6)])||0x190;console[_0x3a38f6(0x169)]('chat-error-detail\x20\x20<----------------------------------------->',_0x3a38f6(0x1c8),_0x269c22,'message',_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1b3)],_0x3a38f6(0x180),(_0x14cf7d=_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x167)])===null||_0x14cf7d===void 0x0?void 0x0:_0x14cf7d['statusText'],'status',(_0x3447d9=_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x167)])===null||_0x3447d9===void 0x0?void 0x0:_0x3447d9[_0x3a38f6(0x17d)]);if(_0x39f4ed[_0x3a38f6(0x17d)]&&_0x39f4ed[_0x3a38f6(0x17d)]===0x192){const _0x584b99={'message':_0x3a38f6(0x126)+_0x39f4ed[_0x3a38f6(0x1b3)],'code':0x192};if(_0x313bbb)return _0x313bbb[_0x3a38f6(0x1e5)](JSON['stringify'](_0x584b99));else throw new common_1[(_0x3a38f6(0x135))](_0x39f4ed['message'],common_1[_0x3a38f6(0x1f6)][_0x3a38f6(0x17e)]);}if(!_0x34775a){if(_0x313bbb)return _0x313bbb[_0x3a38f6(0x1e5)](JSON[_0x3a38f6(0x19c)]({'message':_0x39f4ed[_0x3a38f6(0x1b3)],'code':0x1f4}));else throw new common_1[(_0x3a38f6(0x135))](_0x39f4ed[_0x3a38f6(0x1b3)],common_1[_0x3a38f6(0x1f6)][_0x3a38f6(0x1c3)]);}let _0x174247=errorMessage_constant_1[_0x3a38f6(0x19a)][_0x34775a]?errorMessage_constant_1[_0x3a38f6(0x19a)][_0x34775a]:_0x3a38f6(0x191);(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed['message'][_0x3a38f6(0x1a0)](_0x3a38f6(0x173)))&&Number(_0x3fe850)===0x1&&(await this[_0x3a38f6(0x124)]['lockKey'](_0x4d4c62,_0x3a38f6(0x1da),-0x1),_0x174247=_0x3a38f6(0x154));(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1d6)])===0x1ad&&_0x39f4ed[_0x3a38f6(0x1b3)][_0x3a38f6(0x1a0)](_0x3a38f6(0x184))&&Number(_0x3fe850)===0x1&&(await this['modelsService'][_0x3a38f6(0x1e7)](_0x4d4c62,'当前模型key余额已耗尽、已冻结当前调用Key、尝试重新对话试试吧',-0x3),_0x174247='当前模型key余额已耗尽');(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1d6)])===0x1ad&&(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed['statusText'])==='Too\x20Many\x20Requests'&&(_0x174247=_0x3a38f6(0x1dc));(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed['statusCode'])===0x191&&_0x39f4ed['message'][_0x3a38f6(0x1a0)](_0x3a38f6(0x1e1))&&Number(_0x3fe850)===0x1&&(await this[_0x3a38f6(0x124)][_0x3a38f6(0x1e7)](_0x4d4c62,'提供了错误的模型秘钥',-0x2),_0x174247=_0x3a38f6(0x10d));(_0x39f4ed===null||_0x39f4ed===void 0x0?void 0x0:_0x39f4ed[_0x3a38f6(0x1d6)])===0x194&&_0x39f4ed['message'][_0x3a38f6(0x1a0)](_0x3a38f6(0x13d))&&Number(_0x3fe850)===0x1&&(await this[_0x3a38f6(0x124)][_0x3a38f6(0x1e7)](_0x4d4c62,_0x3a38f6(0x15b),-0x4),_0x174247=_0x3a38f6(0x190));_0x269c22===0x190&&console[_0x3a38f6(0x169)](_0x3a38f6(0x1cf),_0x39f4ed,_0x39f4ed[_0x3a38f6(0x1b3)]);const _0x3ab05a={'message':_0x174247||_0x3a38f6(0x12c),'code':_0x269c22===0x191?0x190:_0x269c22||0x1f4};if(_0x313bbb)return _0x313bbb[_0x3a38f6(0x1e5)](JSON[_0x3a38f6(0x19c)](_0x3ab05a));else throw new common_1[(_0x3a38f6(0x135))](_0x3ab05a[_0x3a38f6(0x1b3)],common_1['HttpStatus']['BAD_REQUEST']);}finally{_0x313bbb&&_0x313bbb[_0x3a38f6(0x102)]();}}async[_0x21f677(0x1b2)](_0x46a1e5,_0x41e8d7){const _0x559403=_0x21f677;var _0x2dd19a,_0x331b55,_0x345d3a,_0x40621d;await this['badwordsService'][_0x559403(0x1fb)](_0x46a1e5[_0x559403(0x174)],_0x41e8d7['user']['id']),await this['userService'][_0x559403(0x101)](_0x41e8d7[_0x559403(0x171)]);const _0x11d5e4=(_0x46a1e5===null||_0x46a1e5===void 0x0?void 0x0:_0x46a1e5[_0x559403(0x138)])==='hd'?0x4:0x2;await this['userBalanceService'][_0x559403(0x10f)](_0x41e8d7,_0x559403(0x113),_0x11d5e4);let _0x4964c0=[];const _0x14120e=await this[_0x559403(0x124)][_0x559403(0x1b8)](_0x559403(0x1fd)),_0x59f479=_0x14120e===null||_0x14120e===void 0x0?void 0x0:_0x14120e['id'],{key:_0x328311,proxyResUrl:_0x34f606}=await this[_0x559403(0x18f)](_0x14120e);common_1[_0x559403(0x136)][_0x559403(0x169)](_0x559403(0x140)+_0x46a1e5[_0x559403(0x174)]+_0x559403(0x194)+_0x328311,'DrawService');try{const _0x3dd757=_0x34f606+_0x559403(0x104),_0x395b5b=Object[_0x559403(0x1f7)](Object[_0x559403(0x1f7)]({},_0x46a1e5),{'model':'dall-e-3'});console['log']('dall-e\x20draw\x20params:\x20',_0x395b5b);const _0x2280b4=await axios_1[_0x559403(0x123)][_0x559403(0x189)](_0x3dd757,Object[_0x559403(0x1f7)](Object['assign']({},_0x395b5b),{'response_format':'b64_json'}),{'headers':{'Authorization':_0x559403(0x1fa)+_0x328311}});_0x4964c0=_0x2280b4[_0x559403(0x1c2)][_0x559403(0x1c2)];const _0x55301d=[];for(const _0x4cbed8 of _0x4964c0){const _0x417071=uuid['v4']()[_0x559403(0x18c)](0x0,0xa)+'.png',_0x2ec84e=Buffer[_0x559403(0x1f3)](_0x4cbed8['b64_json'],_0x559403(0x1e4));_0x55301d[_0x559403(0x196)](this[_0x559403(0x145)][_0x559403(0x1b1)]({'filename':_0x417071,'buffer':_0x2ec84e}));}const _0x5bf299=await Promise['all'](_0x55301d);await this[_0x559403(0x103)]['deductFromBalance'](_0x41e8d7[_0x559403(0x171)]['id'],'mjDraw',(_0x395b5b===null||_0x395b5b===void 0x0?void 0x0:_0x395b5b['quality'])===_0x559403(0x134)?0x2:0x4,_0x11d5e4);const _0x58dceb=(0x0,utils_1['getClientIp'])(_0x41e8d7),_0x3ff742=[],_0x12224e=await this[_0x559403(0x145)][_0x559403(0x17a)](),[_0x42adc5,_0x5e3d8c]=_0x46a1e5[_0x559403(0x1d4)][_0x559403(0x12b)]('x');return _0x5bf299[_0x559403(0x175)](_0x147443=>{const _0x11c309=_0x559403;_0x3ff742['push'](this[_0x11c309(0x1bd)][_0x11c309(0x14f)]({'curIp':_0x58dceb,'userId':_0x41e8d7[_0x11c309(0x171)]['id'],'type':balance_constant_1[_0x11c309(0x1be)][_0x11c309(0x153)],'prompt':_0x46a1e5[_0x11c309(0x174)],'answer':_0x147443,'fileInfo':JSON[_0x11c309(0x19c)]({'cosType':_0x12224e,'width':_0x42adc5,'height':_0x5e3d8c,'cosUrl':_0x147443}),'promptTokens':0x0,'completionTokens':0x0,'totalTokens':0x0,'model':_0x11c309(0x1fd)}));}),await Promise[_0x559403(0x12a)](_0x3ff742),_0x5bf299;}catch(_0x1dc332){const _0x38c04d=((_0x2dd19a=_0x1dc332===null||_0x1dc332===void 0x0?void 0x0:_0x1dc332['response'])===null||_0x2dd19a===void 0x0?void 0x0:_0x2dd19a['status'])||0x1f4;console[_0x559403(0x169)]('openai-draw\x20error:\x20',JSON[_0x559403(0x19c)](_0x1dc332),_0x328311,_0x38c04d);const _0x372562=(_0x40621d=(_0x345d3a=(_0x331b55=_0x1dc332===null||_0x1dc332===void 0x0?void 0x0:_0x1dc332[_0x559403(0x167)])===null||_0x331b55===void 0x0?void 0x0:_0x331b55['data'])===null||_0x345d3a===void 0x0?void 0x0:_0x345d3a[_0x559403(0x1fe)])===null||_0x40621d===void 0x0?void 0x0:_0x40621d[_0x559403(0x1b3)];if(_0x38c04d===0x1ad)throw new common_1[(_0x559403(0x135))](_0x559403(0x1d0),common_1[_0x559403(0x1f6)][_0x559403(0x1c3)]);if(_0x38c04d===0x190&&_0x372562[_0x559403(0x1a0)](_0x559403(0x157)))throw new common_1[(_0x559403(0x135))](_0x559403(0x1a7),common_1[_0x559403(0x1f6)][_0x559403(0x1c3)]);if(_0x38c04d===0x190&&_0x372562[_0x559403(0x1a0)](_0x559403(0x109))){await this[_0x559403(0x124)][_0x559403(0x1e7)](_0x59f479,_0x559403(0x1da),-0x1);throw new common_1['HttpException'](_0x559403(0x164),common_1[_0x559403(0x1f6)][_0x559403(0x1c3)]);}if(_0x38c04d===0x1f4)throw new common_1[(_0x559403(0x135))]('绘制图片失败,请检查你的提示词是否有非法描述!',common_1[_0x559403(0x1f6)][_0x559403(0x1c3)]);if(_0x38c04d===0x191)throw new common_1['HttpException']('绘制图片失败,此次绘画被拒绝了!',common_1[_0x559403(0x1f6)][_0x559403(0x1c3)]);throw new common_1[(_0x559403(0x135))](_0x559403(0x1e0),common_1['HttpStatus'][_0x559403(0x1c3)]);}}async[_0x21f677(0x114)](){const _0x5ee257=_0x21f677,_0x24c833=await this[_0x5ee257(0x148)][_0x5ee257(0x16e)]({'where':{'status':0x1},'select':['id',_0x5ee257(0x14a),'weight','model',_0x5ee257(0x192),_0x5ee257(0x1ea),_0x5ee257(0x162),_0x5ee257(0x112)]}),_0x73a1f4=_0x24c833[_0x5ee257(0x1d5)](_0x4d5058=>_0x4d5058['model'][_0x5ee257(0x1a0)](_0x5ee257(0x12d))),_0x18759f=_0x24c833[_0x5ee257(0x1d5)](_0x4ed5ef=>_0x4ed5ef[_0x5ee257(0x144)]['includes']('gpt-4'));this[_0x5ee257(0x100)]={'list3':_0x73a1f4,'list4':_0x18759f};}async[_0x21f677(0x1f1)](_0x554f74){const _0x503316=_0x21f677,_0x3a4361=await this[_0x503316(0x15c)][_0x503316(0x1b4)]([_0x503316(0x15d)]);return(_0x554f74===null||_0x554f74===void 0x0?void 0x0:_0x554f74[_0x503316(0x11d)])||_0x3a4361||'https://api.openai.com';}async[_0x21f677(0x18f)](_0x5c88be){const _0x6d3219=_0x21f677,{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'][_0x6d3219(0x1b4)]([_0x6d3219(0x176),_0x6d3219(0x160),_0x6d3219(0x1ed),_0x6d3219(0x152),_0x6d3219(0x165),_0x6d3219(0x198),_0x6d3219(0x125),_0x6d3219(0x1e2),_0x6d3219(0x15d)]);let _0x5a6ab9=null,_0x1cb337=null,_0xc2549c=null,{model:_0x3ec070,maxModelTokens:maxModelTokens=0x0,maxResponseTokens:maxResponseTokens=0x0,proxyUrl:proxyUrl='',key:_0x5afc2e}=_0x5c88be;return _0x3ec070[_0x6d3219(0x11e)]()[_0x6d3219(0x1a0)]('gpt-4')&&(maxModelTokens>=0x2000&&(maxModelTokens=0x2000),_0x1cb337>=0x1000&&(maxModelTokens=0x1000),_0x5a6ab9=maxModelTokens||openaiModel4MaxTokens||0x2000,_0x1cb337=maxResponseTokens||openaiModel4MaxTokensRes||0x1000,_0x3ec070[_0x6d3219(0x11e)]()['includes']('32k')&&(maxModelTokens>=0x8000&&(maxModelTokens=0x8000),_0x1cb337>=0x4000&&(maxModelTokens=0x4000),_0x5a6ab9=maxModelTokens||openaiModel4MaxTokens32k||0x8000,_0x1cb337=maxResponseTokens||openaiModel4MaxTokens32kRes||0x4000),_0x3ec070['toLowerCase']()['includes'](_0x6d3219(0x133))&&(maxModelTokens>=0x3ffc&&(maxModelTokens=0x3ffc),_0x1cb337>=0x1000&&(maxModelTokens=0x1000),_0x5a6ab9=maxModelTokens||0x3ffc,_0x1cb337=maxResponseTokens||0x1000)),_0x3ec070[_0x6d3219(0x11e)]()[_0x6d3219(0x1a0)](_0x6d3219(0x12d))&&(maxModelTokens>=0x1000&&(maxModelTokens=0x1000),_0x1cb337>=0x7d0&&(maxModelTokens=0x7d0),_0x5a6ab9=maxModelTokens||openaiModel3MaxTokens||0x1000,_0x1cb337=maxResponseTokens||openaiModel3MaxTokensRes||0x7d0,_0x3ec070[_0x6d3219(0x11e)]()[_0x6d3219(0x1a0)](_0x6d3219(0x16c))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x1cb337>=0x2000&&(maxModelTokens=0x2000),_0x5a6ab9=maxModelTokens||openaiModel3MaxTokens16k||0x4000,_0x1cb337=maxResponseTokens||openaiModel3MaxTokens16kRes||0x2000),_0x3ec070['toLowerCase']()[_0x6d3219(0x1a0)](_0x6d3219(0x133))&&(maxModelTokens>=0x4000&&(maxModelTokens=0x4000),_0x1cb337>=0x1000&&(maxModelTokens=0x1000),_0x5a6ab9=maxModelTokens||0x4000,_0x1cb337=maxResponseTokens||0x1000)),_0xc2549c=proxyUrl||openaiBaseUrl||_0x6d3219(0x19b),_0x1cb337>=_0x5a6ab9&&(_0x1cb337=Math[_0x6d3219(0x151)](_0x5a6ab9/0x2)),{'key':_0x5afc2e,'maxToken':_0x5a6ab9,'maxTokenRes':_0x1cb337,'proxyResUrl':_0xc2549c};}async['setChatBoxType'](_0x481d3b,_0x51c7ec){const _0x4dc6e6=_0x21f677;try{const {name:_0x50f4db,icon:_0x171ce7,order:_0x5d071e,id:_0x531901,status:_0x45aabd}=_0x51c7ec;return _0x531901?await this[_0x4dc6e6(0x146)][_0x4dc6e6(0x111)]({'id':_0x531901},{'name':_0x50f4db,'icon':_0x171ce7,'order':_0x5d071e,'status':_0x45aabd}):await this[_0x4dc6e6(0x146)][_0x4dc6e6(0x183)]({'name':_0x50f4db,'icon':_0x171ce7,'order':_0x5d071e,'status':_0x45aabd});}catch(_0x5d56d5){console[_0x4dc6e6(0x169)]('error:\x20',_0x5d56d5);}}async[_0x21f677(0x1ba)](_0xa3296b,_0x529973){const _0x190780=_0x21f677,{id:_0x4f09b0}=_0x529973;if(!_0x4f09b0)throw new common_1[(_0x190780(0x135))](_0x190780(0x130),common_1[_0x190780(0x1f6)][_0x190780(0x1c3)]);const _0x2f1c74=await this[_0x190780(0x14e)][_0x190780(0x206)]({'where':{'typeId':_0x4f09b0}});if(_0x2f1c74)throw new common_1['HttpException']('当前分类下有未处理数据不可移除!',common_1[_0x190780(0x1f6)][_0x190780(0x1c3)]);return await this[_0x190780(0x146)][_0x190780(0x205)]({'id':_0x4f09b0});}async['queryChatBoxType'](){const _0x8b1c6b=_0x21f677;return await this['chatBoxTypeEntity'][_0x8b1c6b(0x16e)]({'order':{'order':'DESC'}});}async[_0x21f677(0x1ad)](_0x17edb0,_0x303624){const _0x4a355d=_0x21f677,{title:_0x3f2e00,prompt:_0x185ade,appId:_0x18706d,order:_0x525f27,status:_0xa933d9,typeId:_0x3e6812,id:_0x819924,url:_0x2b2040}=_0x303624;if(!_0x3e6812)throw new common_1[(_0x4a355d(0x135))](_0x4a355d(0x107),common_1[_0x4a355d(0x1f6)]['BAD_REQUEST']);try{const _0x3e3b7a={'title':_0x3f2e00,'order':_0x525f27,'status':_0xa933d9,'typeId':_0x3e6812,'url':_0x2b2040};return _0x3e3b7a[_0x4a355d(0x1ee)]=_0x18706d||0x0,_0x3e3b7a['prompt']=_0x185ade||'',_0x819924?await this[_0x4a355d(0x14e)][_0x4a355d(0x111)]({'id':_0x819924},_0x3e3b7a):await this['chatBoxEntity'][_0x4a355d(0x183)](_0x3e3b7a);}catch(_0x15d197){console[_0x4a355d(0x169)]('error:\x20',_0x15d197);}}async[_0x21f677(0x15e)](_0x38dffb,_0x3968fa){const _0x123fd4=_0x21f677,{id:_0x4e8b22}=_0x3968fa;if(!_0x4e8b22)throw new common_1[(_0x123fd4(0x135))]('非法操作!',common_1[_0x123fd4(0x1f6)][_0x123fd4(0x1c3)]);return await this[_0x123fd4(0x14e)][_0x123fd4(0x205)]({'id':_0x4e8b22});}async[_0x21f677(0x12e)](){const _0x2eee34=_0x21f677,_0x46319e=await this[_0x2eee34(0x14e)][_0x2eee34(0x16e)]({'order':{'order':_0x2eee34(0x1dd)}}),_0x36f8ee=[...new Set(_0x46319e[_0x2eee34(0x17f)](_0x181b1f=>_0x181b1f[_0x2eee34(0x1e9)]))],_0x4fff90=[...new Set(_0x46319e[_0x2eee34(0x17f)](_0x1f1a66=>_0x1f1a66[_0x2eee34(0x1ee)]))],_0x4341e4=await this[_0x2eee34(0x146)][_0x2eee34(0x16e)]({'where':{'id':(0x0,typeorm_1['In'])(_0x36f8ee)}}),_0x4400e1=await this[_0x2eee34(0x1b6)][_0x2eee34(0x16e)]({'where':{'id':(0x0,typeorm_1['In'])(_0x4fff90)}});return _0x46319e[_0x2eee34(0x17f)](_0x51de11=>{const _0x131497=_0x2eee34,{typeId:_0x2eb9e5,appId:_0x1814bb}=_0x51de11;return _0x51de11[_0x131497(0x1bf)]=_0x4341e4['find'](_0x512138=>_0x512138['id']===_0x2eb9e5),_0x51de11['appInfo']=_0x4400e1['find'](_0x2adb7b=>_0x2adb7b['id']===_0x1814bb),_0x51de11;});}async[_0x21f677(0x15f)](){const _0x3ef076=_0x21f677,_0x5760ac=await this[_0x3ef076(0x146)]['find']({'order':{'order':'DESC'},'where':{'status':!![]}}),_0x4e363e=await this[_0x3ef076(0x14e)]['find']({'where':{'status':!![]}}),_0x1f6194=[...new Set(_0x4e363e[_0x3ef076(0x17f)](_0x29cf96=>_0x29cf96['appId']))],_0x15af45=await this['appEntity'][_0x3ef076(0x16e)]({'where':{'id':(0x0,typeorm_1['In'])(_0x1f6194)}});return _0x4e363e[_0x3ef076(0x175)](_0x581030=>{const _0x234570=_0x3ef076,_0x2a4271=_0x15af45['find'](_0x1cd944=>_0x1cd944['id']===_0x581030[_0x234570(0x1ee)]);return _0x581030[_0x234570(0x137)]=_0x2a4271===null||_0x2a4271===void 0x0?void 0x0:_0x2a4271[_0x234570(0x137)],_0x581030;}),_0x5760ac['map'](_0x3f8087=>{const _0x42b702=_0x3ef076;return _0x3f8087['childList']=_0x4e363e['filter'](_0x68b5fd=>_0x68b5fd['typeId']===_0x3f8087['id']&&_0x68b5fd[_0x42b702(0x17d)]),_0x3f8087;});}async[_0x21f677(0x199)](_0x24acdf,_0x1fc077){const _0xd84f8f=_0x21f677;try{const {name:_0x3a6eef,icon:_0x594c39,order:_0x5d35a8,id:_0x4da6cc,status:_0x5ab884}=_0x1fc077;return _0x4da6cc?await this[_0xd84f8f(0x168)]['update']({'id':_0x4da6cc},{'name':_0x3a6eef,'icon':_0x594c39,'order':_0x5d35a8,'status':_0x5ab884}):await this[_0xd84f8f(0x168)]['save']({'name':_0x3a6eef,'icon':_0x594c39,'order':_0x5d35a8,'status':_0x5ab884});}catch(_0x254da0){console[_0xd84f8f(0x169)](_0xd84f8f(0x1a6),_0x254da0);}}async[_0x21f677(0x1a8)](_0x530377,_0x26857b){const _0x29ea82=_0x21f677,{id:_0x5d34f9}=_0x26857b;if(!_0x5d34f9)throw new common_1[(_0x29ea82(0x135))](_0x29ea82(0x130),common_1['HttpStatus'][_0x29ea82(0x1c3)]);const _0x39695a=await this[_0x29ea82(0x14e)]['count']({'where':{'typeId':_0x5d34f9}});if(_0x39695a)throw new common_1[(_0x29ea82(0x135))](_0x29ea82(0x1fc),common_1[_0x29ea82(0x1f6)][_0x29ea82(0x1c3)]);return await this['chatPreTypeEntity']['delete']({'id':_0x5d34f9});}async[_0x21f677(0x177)](){const _0x4c9ea7=_0x21f677;return await this[_0x4c9ea7(0x168)][_0x4c9ea7(0x16e)]({'order':{'order':_0x4c9ea7(0x1dd)}});}async[_0x21f677(0x193)](_0x54f822,_0x3f9798){const _0x174de4=_0x21f677,{title:_0x390338,prompt:_0x18e571,appId:_0x48d1a6,order:_0x3fb790,status:_0x59b17a,typeId:_0x3dd27a,id:_0x2d50c8,url:_0x6b9995}=_0x3f9798;if(!_0x3dd27a)throw new common_1['HttpException'](_0x174de4(0x107),common_1[_0x174de4(0x1f6)]['BAD_REQUEST']);try{const _0x495c8b={'title':_0x390338,'prompt':_0x18e571,'order':_0x3fb790,'status':_0x59b17a,'typeId':_0x3dd27a,'url':_0x6b9995};return _0x2d50c8?await this['chatPreEntity'][_0x174de4(0x111)]({'id':_0x2d50c8},_0x495c8b):await this[_0x174de4(0x1d9)][_0x174de4(0x183)](_0x495c8b);}catch(_0x121109){console[_0x174de4(0x169)]('error:\x20',_0x121109);}}async[_0x21f677(0x1ff)](_0x10e36e,_0x4a45e2){const _0x5e4007=_0x21f677,{id:_0x2c94f1}=_0x4a45e2;if(!_0x2c94f1)throw new common_1[(_0x5e4007(0x135))](_0x5e4007(0x130),common_1[_0x5e4007(0x1f6)][_0x5e4007(0x1c3)]);return await this[_0x5e4007(0x1d9)][_0x5e4007(0x205)]({'id':_0x2c94f1});}async[_0x21f677(0x115)](){const _0xd9d121=_0x21f677,_0x9378c=await this[_0xd9d121(0x1d9)]['find']({'order':{'order':_0xd9d121(0x1dd)}}),_0xa1d928=[...new Set(_0x9378c[_0xd9d121(0x17f)](_0x5ce62c=>_0x5ce62c[_0xd9d121(0x1e9)]))],_0x197a13=await this['chatPreTypeEntity'][_0xd9d121(0x16e)]({'where':{'id':(0x0,typeorm_1['In'])(_0xa1d928)}});return _0x9378c[_0xd9d121(0x17f)](_0x15270a=>{const _0x110858=_0xd9d121,{typeId:_0x14b340,appId:_0x3f1ad9}=_0x15270a;return _0x15270a[_0x110858(0x1bf)]=_0x197a13[_0x110858(0x16e)](_0x589077=>_0x589077['id']===_0x14b340),_0x15270a;});}async[_0x21f677(0x185)](){const _0x123808=_0x21f677,_0x2f0db2=await this[_0x123808(0x168)]['find']({'order':{'order':_0x123808(0x1dd)},'where':{'status':!![]}}),_0x21c17b=await this['chatPreEntity']['find']({'where':{'status':!![]}});return _0x2f0db2['map'](_0x57d264=>{const _0x3cf269=_0x123808;return _0x57d264[_0x3cf269(0x18a)]=_0x21c17b['filter'](_0x51c3fd=>_0x51c3fd[_0x3cf269(0x1e9)]===_0x57d264['id']&&_0x51c3fd[_0x3cf269(0x17d)]),_0x57d264;});}async[_0x21f677(0x1b0)](_0x2c3b65,_0x1bed92,_0x4ef474){const _0x24e4e7=_0x21f677;let _0x3e7f63=0x1000,_0x5070e3=0x800;return _0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)]('gpt-4')&&(_0x3e7f63=_0x1bed92>=0x2004?0x2004:_0x1bed92,_0x5070e3=_0x4ef474>=0x1000?0x1000:_0x4ef474,_0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)](_0x24e4e7(0x1ec))&&(_0x3e7f63=_0x1bed92>=0x8000?0x8000:_0x1bed92,_0x5070e3=_0x4ef474>=0x3e80?0x3e80:_0x4ef474),(_0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)]('gpt-4-1106')||_0x2c3b65[_0x24e4e7(0x11e)]()['includes']('gpt-4-vision-preview'))&&(_0x3e7f63=_0x1bed92>=0x1f400?0x1f400:_0x1bed92,_0x5070e3=_0x4ef474>=0x1000?0x1000:_0x4ef474)),_0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)](_0x24e4e7(0x12d))&&(_0x3e7f63=_0x1bed92>=0x1000?0x1000:_0x1bed92,_0x5070e3=_0x4ef474>=0x800?0x800:_0x4ef474,_0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)](_0x24e4e7(0x16c))&&(_0x3e7f63=_0x1bed92>=0x4000?0x4000:_0x1bed92,_0x5070e3=_0x4ef474>=0x1f40?0x1f40:_0x4ef474),_0x2c3b65[_0x24e4e7(0x11e)]()[_0x24e4e7(0x1a0)](_0x24e4e7(0x133))&&(_0x3e7f63=_0x1bed92>=0x4000?0x4000:_0x1bed92,_0x5070e3=_0x4ef474>=0x1f40?0x1f40:_0x4ef474)),{'maxToken':_0x3e7f63,'maxRes':_0x5070e3};}};ChatgptService=__decorate([(0x0,common_1[_0x21f677(0x143)])(),__param(0x0,(0x0,typeorm_2[_0x21f677(0x1bb)])(gptkeys_entity_1[_0x21f677(0x121)])),__param(0x1,(0x0,typeorm_2[_0x21f677(0x1bb)])(config_entity_1[_0x21f677(0x1c0)])),__param(0x2,(0x0,typeorm_2['InjectRepository'])(chatBoxType_entity_1['ChatBoxTypeEntity'])),__param(0x3,(0x0,typeorm_2['InjectRepository'])(chatBox_entity_1[_0x21f677(0xff)])),__param(0x4,(0x0,typeorm_2[_0x21f677(0x1bb)])(app_entity_1[_0x21f677(0x11a)])),__param(0x5,(0x0,typeorm_2[_0x21f677(0x1bb)])(chatPreType_entity_1['ChatPreTypeEntity'])),__param(0x6,(0x0,typeorm_2['InjectRepository'])(chatPre_entity_1[_0x21f677(0x10e)])),__metadata(_0x21f677(0x1f0),[typeorm_1['Repository'],typeorm_1[_0x21f677(0x1c6)],typeorm_1[_0x21f677(0x1c6)],typeorm_1['Repository'],typeorm_1[_0x21f677(0x1c6)],typeorm_1[_0x21f677(0x1c6)],typeorm_1[_0x21f677(0x1c6)],nestjs_config_1[_0x21f677(0x1cd)],userBalance_service_1[_0x21f677(0x195)],chatLog_service_1[_0x21f677(0x106)],user_service_1[_0x21f677(0x13c)],upload_service_1['UploadService'],badwords_service_1['BadwordsService'],autoreply_service_1[_0x21f677(0x18e)],globalConfig_service_1[_0x21f677(0x188)],fanyi_service_1['FanyiService'],chatGroup_service_1[_0x21f677(0x172)],models_service_1[_0x21f677(0x16b)]])],ChatgptService),exports[_0x21f677(0x1f5)]=ChatgptService;