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

1 line
8.1 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 _0x4cea59=_0x1a4b;(function(_0x45970a,_0x1349c2){const _0x1cfde4=_0x1a4b,_0x3d6efb=_0x45970a();while(!![]){try{const _0x506e38=-parseInt(_0x1cfde4(0xea))/0x1+parseInt(_0x1cfde4(0xe2))/0x2*(-parseInt(_0x1cfde4(0xf1))/0x3)+parseInt(_0x1cfde4(0xb0))/0x4+parseInt(_0x1cfde4(0xcf))/0x5*(parseInt(_0x1cfde4(0xd4))/0x6)+parseInt(_0x1cfde4(0xb9))/0x7*(-parseInt(_0x1cfde4(0xe1))/0x8)+parseInt(_0x1cfde4(0xc5))/0x9+parseInt(_0x1cfde4(0xc7))/0xa;if(_0x506e38===_0x1349c2)break;else _0x3d6efb['push'](_0x3d6efb['shift']());}catch(_0x425c42){_0x3d6efb['push'](_0x3d6efb['shift']());}}}(_0xcf79,0x6ff4d));function _0x1a4b(_0x31af1c,_0x4302bb){const _0xcf7966=_0xcf79();return _0x1a4b=function(_0x1a4b13,_0x422cec){_0x1a4b13=_0x1a4b13-0xad;let _0x650da7=_0xcf7966[_0x1a4b13];return _0x650da7;},_0x1a4b(_0x31af1c,_0x4302bb);}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports[_0x4cea59(0xc2)]=exports[_0x4cea59(0xeb)]=void 0x0;const axios_1=require(_0x4cea59(0xec)),tiktoken_1=require(_0x4cea59(0xe4)),common_1=require(_0x4cea59(0xf7)),uuid=require(_0x4cea59(0xe0)),tokenizer=(0x0,tiktoken_1[_0x4cea59(0xd7)])('cl100k_base');function getFullUrl(_0x1f87b3){const _0x493d3d=_0x1f87b3['endsWith']('/')?_0x1f87b3['slice'](0x0,-0x1):_0x1f87b3,_0x235364=_0x493d3d||'https://api.openai.com';return _0x235364+'/v1/chat/completions';}async function sendMessageFromOpenAi(_0x1c7a11,_0x5a65f2,_0xff45df){const _0x10f379=_0x4cea59;var _0x55872a,_0x57d7d4,_0xd2f6bc,_0x1c6788;const {onProgress:_0x2c27c8,maxToken:_0x5c4480,apiKey:_0x1545df,model:_0x3902d9,temperature:temperature=0.8,proxyUrl:_0x2786b5,prompt:_0x5c2be5}=_0x5a65f2;if(_0x3902d9[_0x10f379(0xd1)](_0x10f379(0xb7))){let _0x424306={'text':'','imageUrl':''};try{const _0x58c25a={'method':'POST','url':_0x2786b5+_0x10f379(0xb3),'headers':{'Content-Type':_0x10f379(0xd0),'Authorization':'Bearer\x20'+_0x1545df},'data':{'prompt':_0x5c2be5,'model':_0x3902d9,'response_format':_0x10f379(0xe8)}},_0x10692e=await(0x0,axios_1[_0x10f379(0xae)])(_0x58c25a),{b64_json:_0x354ab2,revised_prompt:_0x541f85}=_0x10692e['data'][_0x10f379(0xaf)][0x0],_0x2d2e64=Buffer[_0x10f379(0xf0)](_0x354ab2,_0x10f379(0xe9));let _0x37c684='';try{const _0x133ab4=uuid['v4']()[_0x10f379(0xcc)](0x0,0xa)+_0x10f379(0xbb);common_1[_0x10f379(0xb2)][_0x10f379(0xd2)](_0x10f379(0xdf),_0x10f379(0xbc));const _0x140a41=Buffer[_0x10f379(0xf0)](_0x354ab2,_0x10f379(0xe9));_0x37c684=await _0xff45df[_0x10f379(0xe5)]({'filename':_0x133ab4,'buffer':_0x140a41}),common_1['Logger'][_0x10f379(0xd2)](_0x10f379(0xc3)+_0x37c684,_0x10f379(0xbc));}catch(_0x457351){common_1[_0x10f379(0xb2)][_0x10f379(0xca)](_0x10f379(0xd3)+_0x457351,_0x10f379(0xbc));}return _0x424306['imageUrl']=_0x37c684,_0x424306[_0x10f379(0xf2)]=_0x541f85,_0x2c27c8&&_0x2c27c8({'text':_0x424306[_0x10f379(0xf2)]}),_0x424306;}catch(_0x2f5e8b){const _0x3b18bd=((_0x55872a=_0x2f5e8b===null||_0x2f5e8b===void 0x0?void 0x0:_0x2f5e8b['response'])===null||_0x55872a===void 0x0?void 0x0:_0x55872a[_0x10f379(0xf6)])||0x1f4;console['log'](_0x10f379(0xda),JSON[_0x10f379(0xe3)](_0x2f5e8b),_0x3b18bd);const _0x456bb0=(_0x1c6788=(_0xd2f6bc=(_0x57d7d4=_0x2f5e8b===null||_0x2f5e8b===void 0x0?void 0x0:_0x2f5e8b[_0x10f379(0xdc)])===null||_0x57d7d4===void 0x0?void 0x0:_0x57d7d4[_0x10f379(0xaf)])===null||_0xd2f6bc===void 0x0?void 0x0:_0xd2f6bc[_0x10f379(0xca)])===null||_0x1c6788===void 0x0?void 0x0:_0x1c6788[_0x10f379(0xee)];if(_0x3b18bd===0x1ad)return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xc4),_0x424306;if(_0x3b18bd===0x190&&_0x456bb0[_0x10f379(0xd1)](_0x10f379(0xef)))return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xba),_0x424306;if(_0x3b18bd===0x190&&_0x456bb0[_0x10f379(0xd1)]('Billing\x20hard\x20limit\x20has\x20been\x20reached'))return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xce),_0x424306;if(_0x3b18bd===0x1f4)return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xde),_0x424306;if(_0x3b18bd===0x191)return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xc8),_0x424306;return _0x424306[_0x10f379(0xf2)]=_0x10f379(0xb5),_0x424306;}}else{let _0x4898e6={'text':''};const _0x25b818={'method':_0x10f379(0xc9),'url':getFullUrl(_0x2786b5),'responseType':_0x10f379(0xad),'headers':{'Content-Type':_0x10f379(0xd0),'Accept':_0x10f379(0xd0),'Authorization':_0x10f379(0xbd)+_0x1545df},'data':{'stream':!![],'temperature':temperature,'model':_0x3902d9,'messages':_0x1c7a11}};return _0x3902d9===_0x10f379(0xbe)&&(_0x25b818[_0x10f379(0xaf)][_0x10f379(0xb4)]=0x800),new Promise(async(_0x5aeb3f,_0x175122)=>{const _0x2a43a5=_0x10f379;try{const _0xe1b404=await(0x0,axios_1[_0x2a43a5(0xae)])(_0x25b818),_0xad514=_0xe1b404[_0x2a43a5(0xaf)];_0xad514['on'](_0x2a43a5(0xaf),_0x1a4493=>{const _0x1ad685=_0x2a43a5;var _0x339bb3;const _0x114d80=_0x1a4493[_0x1ad685(0xd9)]()['split']('\x0a\x0a')[_0x1ad685(0xd5)](_0x20ff4a=>_0x20ff4a[_0x1ad685(0xc0)]()!=='');for(const _0x27ddb9 of _0x114d80){const _0x4b9405=_0x27ddb9[_0x1ad685(0xcb)](_0x1ad685(0xcd),'');let _0x51f735=![];try{_0x51f735=JSON[_0x1ad685(0xd6)](_0x4b9405)[_0x1ad685(0xe6)][0x0][_0x1ad685(0xc6)]===_0x1ad685(0xf3);}catch(_0x2ac78d){_0x51f735=![];}if(_0x51f735)return _0x4898e6[_0x1ad685(0xf2)]=_0x4898e6[_0x1ad685(0xf2)][_0x1ad685(0xc0)](),_0x4898e6;try{if(_0x4b9405!=='\x20[DONE]'&&_0x4b9405!==_0x1ad685(0xf4)&&_0x4b9405!=_0x1ad685(0xe7)){const _0x116001=JSON['parse'](_0x4b9405);_0x116001['id']&&(_0x4898e6['id']=_0x116001['id']);if((_0x339bb3=_0x116001['choices'])===null||_0x339bb3===void 0x0?void 0x0:_0x339bb3[_0x1ad685(0xdb)]){const _0x1d63f7=_0x116001['choices'][0x0][_0x1ad685(0xb1)];_0x4898e6['delta']=_0x1d63f7[_0x1ad685(0xb6)];if(_0x1d63f7===null||_0x1d63f7===void 0x0?void 0x0:_0x1d63f7['content'])_0x4898e6[_0x1ad685(0xf2)]+=_0x1d63f7[_0x1ad685(0xb6)];_0x1d63f7[_0x1ad685(0xc1)]&&(_0x4898e6[_0x1ad685(0xc1)]=_0x1d63f7[_0x1ad685(0xc1)]),_0x4898e6[_0x1ad685(0xd8)]=_0x116001;}_0x2c27c8&&_0x2c27c8({'text':_0x4898e6[_0x1ad685(0xf2)]});}}catch(_0x425035){console['log']('parse\x20Error',_0x4b9405);}}});let _0x5ce22f='';_0x1c7a11[_0x2a43a5(0xed)](_0x2eafa4=>{const _0x18946e=_0x2a43a5;_0x5ce22f+=_0x2eafa4[_0x18946e(0xb6)]+'\x20';}),_0xad514['on'](_0x2a43a5(0xdd),()=>{const _0x2a9dde=_0x2a43a5;if(_0x4898e6['detail']&&_0x4898e6[_0x2a9dde(0xf2)]){const _0x5f4435=getTokenCount(_0x5ce22f),_0x409eca=getTokenCount(_0x4898e6[_0x2a9dde(0xf2)]);_0x4898e6['detail'][_0x2a9dde(0xb8)]={'prompt_tokens':_0x5f4435,'completion_tokens':_0x409eca,'total_tokens':_0x5f4435+_0x409eca,'estimated':!![]};}return _0x5aeb3f(_0x4898e6);});}catch(_0x164754){_0x175122(_0x164754);}});}}exports[_0x4cea59(0xeb)]=sendMessageFromOpenAi;function getTokenCount(_0xd4c632){const _0x19cfea=_0x4cea59;if(!_0xd4c632)return 0x0;return typeof _0xd4c632!==_0x19cfea(0xbf)&&(_0xd4c632=String(_0xd4c632)),_0xd4c632=_0xd4c632[_0x19cfea(0xcb)](/<\|endoftext\|>/g,''),tokenizer[_0x19cfea(0xf5)](_0xd4c632)[_0x19cfea(0xdb)];}function _0xcf79(){const _0x297e14=['727352pMKbLH','delta','Logger','/v1/images/generations','max_tokens','绘制图片失败,请稍后试试吧!','content','dall','usage','1347878FUwSoe','您的请求已被系统拒绝。您的提示可能存在一些非法的文本。','.png','MidjourneyService','Bearer\x20','gpt-4-vision-preview','string','trim','role','getTokenCount','图片上传成功URL:\x20','当前请求已过载、请稍等会儿再试试吧!','5574087FYrWnq','finish_reason','1431600TFqxUF','绘制图片失败,此次绘画被拒绝了!','POST','error','replace','slice','data:','当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧','33875PRHaHC','application/json','includes','debug','上传图片过程中出现错误:\x20','786HOjuvm','filter','parse','get_encoding','detail','toString','openai-draw\x20error:\x20','length','response','end','绘制图片失败,请检查你的提示词是否有非法描述!','------>\x20开始上传图片','uuid','32MOPVuk','12QGcRNj','stringify','@dqbd/tiktoken','uploadFile','choices','[DONE]\x20','b64_json','base64','110819YjWhTi','sendMessageFromOpenAi','axios','forEach','message','This\x20request\x20has\x20been\x20blocked\x20by\x20our\x20content\x20filters','from','246129GIqrLF','text','stop','[DONE]','encode','status','@nestjs/common','stream','default','data'];_0xcf79=function(){return _0x297e14;};return _0xcf79();}exports[_0x4cea59(0xc2)]=getTokenCount;