YiAi/YiAiQuickDeploy/dist/modules/chatgpt/openai.js
2024-07-02 16:38:26 +08:00

1 line
8.0 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 _0x2dbc96=_0x21f8;function _0x21f8(_0x2367cf,_0x53e336){const _0x28213d=_0x2821();return _0x21f8=function(_0x21f82d,_0x18786d){_0x21f82d=_0x21f82d-0xb0;let _0x3b84ab=_0x28213d[_0x21f82d];return _0x3b84ab;},_0x21f8(_0x2367cf,_0x53e336);}(function(_0x58204b,_0xc4bcaf){const _0x3e570f=_0x21f8,_0x4fd654=_0x58204b();while(!![]){try{const _0x39ed2a=parseInt(_0x3e570f(0xc6))/0x1*(parseInt(_0x3e570f(0xc0))/0x2)+-parseInt(_0x3e570f(0xf5))/0x3+parseInt(_0x3e570f(0xd6))/0x4+parseInt(_0x3e570f(0xc8))/0x5+parseInt(_0x3e570f(0xe5))/0x6*(parseInt(_0x3e570f(0xf2))/0x7)+parseInt(_0x3e570f(0xb4))/0x8*(parseInt(_0x3e570f(0xd3))/0x9)+-parseInt(_0x3e570f(0xe6))/0xa;if(_0x39ed2a===_0xc4bcaf)break;else _0x4fd654['push'](_0x4fd654['shift']());}catch(_0x31bc07){_0x4fd654['push'](_0x4fd654['shift']());}}}(_0x2821,0x38ff3));Object[_0x2dbc96(0xe8)](exports,_0x2dbc96(0xb3),{'value':!![]}),exports[_0x2dbc96(0xce)]=exports[_0x2dbc96(0xdb)]=void 0x0;const axios_1=require(_0x2dbc96(0xca)),tiktoken_1=require(_0x2dbc96(0xcd)),common_1=require(_0x2dbc96(0xed)),uuid=require(_0x2dbc96(0xbc)),tokenizer=(0x0,tiktoken_1['get_encoding'])(_0x2dbc96(0xd9));function getFullUrl(_0x600f76){const _0x3913af=_0x2dbc96,_0x1ee837=_0x600f76['endsWith']('/')?_0x600f76['slice'](0x0,-0x1):_0x600f76,_0x1c2d71=_0x1ee837||_0x3913af(0xb6);return _0x1c2d71+'/v1/chat/completions';}async function sendMessageFromOpenAi(_0x4581ff,_0x3b187f,_0x22dc39){const _0xb00fcb=_0x2dbc96;var _0x2ab712,_0xdbeb4c,_0x3a4634,_0x39e9bd;const {onProgress:_0x9cb672,maxToken:_0x27ac91,apiKey:_0x2c360c,model:_0x36aab0,temperature:temperature=0.8,proxyUrl:_0x9dfb1c,prompt:_0x3bc368}=_0x3b187f;if(_0x36aab0['includes'](_0xb00fcb(0xda))){let _0x5e269f={'text':'','imageUrl':''};try{const _0x3a41d2={'method':'POST','url':_0x9dfb1c+_0xb00fcb(0xba),'headers':{'Content-Type':_0xb00fcb(0xc9),'Authorization':_0xb00fcb(0xf3)+_0x2c360c},'data':{'prompt':_0x3bc368,'model':_0x36aab0,'response_format':_0xb00fcb(0xf0)}},_0x81210=await(0x0,axios_1[_0xb00fcb(0xb5)])(_0x3a41d2),{b64_json:_0x5bb7f9,revised_prompt:_0x2119d6}=_0x81210['data']['data'][0x0],_0x341778=Buffer['from'](_0x5bb7f9,_0xb00fcb(0xdd));let _0x1899b6='';try{const _0xeb01c0=uuid['v4']()['slice'](0x0,0xa)+_0xb00fcb(0xc4);common_1[_0xb00fcb(0xf1)][_0xb00fcb(0xeb)](_0xb00fcb(0xc5),_0xb00fcb(0xc2));const _0x455ca0=Buffer['from'](_0x5bb7f9,_0xb00fcb(0xdd));_0x1899b6=await _0x22dc39[_0xb00fcb(0xd5)]({'filename':_0xeb01c0,'buffer':_0x455ca0}),common_1[_0xb00fcb(0xf1)]['debug'](_0xb00fcb(0xcc)+_0x1899b6,'MidjourneyService');}catch(_0x204eda){common_1[_0xb00fcb(0xf1)]['error'](_0xb00fcb(0xee)+_0x204eda,_0xb00fcb(0xc2));}return _0x5e269f[_0xb00fcb(0xf7)]=_0x1899b6,_0x5e269f[_0xb00fcb(0xbf)]=_0x2119d6,_0x9cb672&&_0x9cb672({'text':_0x5e269f[_0xb00fcb(0xbf)]}),_0x5e269f;}catch(_0x328a8d){const _0x322e03=((_0x2ab712=_0x328a8d===null||_0x328a8d===void 0x0?void 0x0:_0x328a8d[_0xb00fcb(0xea)])===null||_0x2ab712===void 0x0?void 0x0:_0x2ab712[_0xb00fcb(0xcb)])||0x1f4;console[_0xb00fcb(0xec)]('openai-draw\x20error:\x20',JSON[_0xb00fcb(0xb2)](_0x328a8d),_0x322e03);const _0x2a69ce=(_0x39e9bd=(_0x3a4634=(_0xdbeb4c=_0x328a8d===null||_0x328a8d===void 0x0?void 0x0:_0x328a8d[_0xb00fcb(0xea)])===null||_0xdbeb4c===void 0x0?void 0x0:_0xdbeb4c['data'])===null||_0x3a4634===void 0x0?void 0x0:_0x3a4634[_0xb00fcb(0xdf)])===null||_0x39e9bd===void 0x0?void 0x0:_0x39e9bd[_0xb00fcb(0xc7)];if(_0x322e03===0x1ad)return _0x5e269f[_0xb00fcb(0xbf)]=_0xb00fcb(0xf6),_0x5e269f;if(_0x322e03===0x190&&_0x2a69ce[_0xb00fcb(0xd2)](_0xb00fcb(0xb8)))return _0x5e269f['text']=_0xb00fcb(0xe9),_0x5e269f;if(_0x322e03===0x190&&_0x2a69ce[_0xb00fcb(0xd2)](_0xb00fcb(0xe7)))return _0x5e269f[_0xb00fcb(0xbf)]=_0xb00fcb(0xd0),_0x5e269f;if(_0x322e03===0x1f4)return _0x5e269f['text']='绘制图片失败,请检查你的提示词是否有非法描述!',_0x5e269f;if(_0x322e03===0x191)return _0x5e269f[_0xb00fcb(0xbf)]=_0xb00fcb(0xcf),_0x5e269f;return _0x5e269f['text']='绘制图片失败,请稍后试试吧!',_0x5e269f;}}else{let _0x1f201f={'text':''};const _0x25f98d={'method':'POST','url':getFullUrl(_0x9dfb1c),'responseType':_0xb00fcb(0xef),'headers':{'Content-Type':_0xb00fcb(0xc9),'Accept':_0xb00fcb(0xc9),'Authorization':_0xb00fcb(0xf3)+_0x2c360c},'data':{'stream':!![],'temperature':temperature,'model':_0x36aab0,'messages':_0x4581ff}};return _0x36aab0==='gpt-4-vision-preview'&&(_0x25f98d['data'][_0xb00fcb(0xe1)]=0x800),new Promise(async(_0x6471e6,_0x2a98c3)=>{const _0x5ca27d=_0xb00fcb;try{const _0x1ab719=await(0x0,axios_1[_0x5ca27d(0xb5)])(_0x25f98d),_0x2dfbaa=_0x1ab719[_0x5ca27d(0xc3)];_0x2dfbaa['on'](_0x5ca27d(0xc3),_0x475eb3=>{const _0x38b941=_0x5ca27d;var _0x1ccda3;const _0x2f3280=_0x475eb3[_0x38b941(0xdc)]()[_0x38b941(0xe0)]('\x0a\x0a')[_0x38b941(0xd7)](_0x3dbd52=>_0x3dbd52[_0x38b941(0xb0)]()!=='');for(const _0x456eda of _0x2f3280){const _0x2a5668=_0x456eda[_0x38b941(0xd8)]('data:','');let _0x4e434d=![];try{_0x4e434d=JSON[_0x38b941(0xbe)](_0x2a5668)[_0x38b941(0xbd)][0x0][_0x38b941(0xbb)]===_0x38b941(0xb9);}catch(_0x1bd568){_0x4e434d=![];}if(_0x4e434d)return _0x1f201f['text']=_0x1f201f[_0x38b941(0xbf)][_0x38b941(0xb0)](),_0x1f201f;try{if(_0x2a5668!=='\x20[DONE]'&&_0x2a5668!==_0x38b941(0xe3)&&_0x2a5668!=_0x38b941(0xd4)){const _0xfef5d4=JSON['parse'](_0x2a5668);_0xfef5d4['id']&&(_0x1f201f['id']=_0xfef5d4['id']);if((_0x1ccda3=_0xfef5d4['choices'])===null||_0x1ccda3===void 0x0?void 0x0:_0x1ccda3['length']){const _0x2cd177=_0xfef5d4[_0x38b941(0xbd)][0x0][_0x38b941(0xde)];_0x1f201f[_0x38b941(0xde)]=_0x2cd177[_0x38b941(0xc1)];if(_0x2cd177===null||_0x2cd177===void 0x0?void 0x0:_0x2cd177[_0x38b941(0xc1)])_0x1f201f[_0x38b941(0xbf)]+=_0x2cd177[_0x38b941(0xc1)];_0x2cd177['role']&&(_0x1f201f[_0x38b941(0xd1)]=_0x2cd177[_0x38b941(0xd1)]),_0x1f201f['detail']=_0xfef5d4;}_0x9cb672&&_0x9cb672({'text':_0x1f201f['text']});}}catch(_0x48bd8c){console['log'](_0x38b941(0xe2),_0x2a5668);}}});let _0x48d12a='';_0x4581ff['forEach'](_0x2038ee=>{const _0x5ec8b8=_0x5ca27d;_0x48d12a+=_0x2038ee[_0x5ec8b8(0xc1)]+'\x20';}),_0x2dfbaa['on'](_0x5ca27d(0xb7),()=>{const _0x42e08d=_0x5ca27d;if(_0x1f201f['detail']&&_0x1f201f['text']){const _0x2a5dba=getTokenCount(_0x48d12a),_0x379e59=getTokenCount(_0x1f201f[_0x42e08d(0xbf)]);_0x1f201f['detail'][_0x42e08d(0xb1)]={'prompt_tokens':_0x2a5dba,'completion_tokens':_0x379e59,'total_tokens':_0x2a5dba+_0x379e59,'estimated':!![]};}return _0x6471e6(_0x1f201f);});}catch(_0x3fee55){_0x2a98c3(_0x3fee55);}});}}exports['sendMessageFromOpenAi']=sendMessageFromOpenAi;function getTokenCount(_0x48006c){const _0x36253f=_0x2dbc96;if(!_0x48006c)return 0x0;return typeof _0x48006c!==_0x36253f(0xe4)&&(_0x48006c=String(_0x48006c)),_0x48006c=_0x48006c['replace'](/<\|endoftext\|>/g,''),tokenizer['encode'](_0x48006c)[_0x36253f(0xf4)];}exports[_0x2dbc96(0xce)]=getTokenCount;function _0x2821(){const _0x4bd19d=['stop','/v1/images/generations','finish_reason','uuid','choices','parse','text','6XsZtEw','content','MidjourneyService','data','.png','------>\x20开始上传图片','96059TJpaMG','message','1514160escsDQ','application/json','axios','status','图片上传成功URL:\x20','@dqbd/tiktoken','getTokenCount','绘制图片失败,此次绘画被拒绝了!','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧','role','includes','54SKowNZ','[DONE]\x20','uploadFile','1164316OMSvYX','filter','replace','cl100k_base','dall','sendMessageFromOpenAi','toString','base64','delta','error','split','max_tokens','parse\x20Error','[DONE]','string','342BMFTzZ','6525720MBfRSI','Billing\x20hard\x20limit\x20has\x20been\x20reached','defineProperty','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','response','debug','log','@nestjs/common','上传图片过程中出现错误:\x20','stream','b64_json','Logger','22428UDinjq','Bearer\x20','length','1022361uXYbtv','当前请求已过载、请稍等会儿再试试吧!','imageUrl','trim','usage','stringify','__esModule','216136DlBFoh','default','https://api.openai.com','end','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters'];_0x2821=function(){return _0x4bd19d;};return _0x2821();}