YiAi/YiAiQuickDeploy/dist/modules/chatgpt/baidu.js
2024-02-05 23:18:50 +08:00

1 line
3.9 KiB
JavaScript

'use strict';const _0x57224e=_0x2bad;(function(_0x38974c,_0xe55496){const _0x54b3e7=_0x2bad,_0x12206e=_0x38974c();while(!![]){try{const _0x10a94f=-parseInt(_0x54b3e7(0x141))/0x1+-parseInt(_0x54b3e7(0x135))/0x2+parseInt(_0x54b3e7(0x134))/0x3+parseInt(_0x54b3e7(0x14a))/0x4+parseInt(_0x54b3e7(0x13b))/0x5+-parseInt(_0x54b3e7(0x139))/0x6+-parseInt(_0x54b3e7(0x152))/0x7*(parseInt(_0x54b3e7(0x146))/0x8);if(_0x10a94f===_0xe55496)break;else _0x12206e['push'](_0x12206e['shift']());}catch(_0x43e1b9){_0x12206e['push'](_0x12206e['shift']());}}}(_0x184e,0x4e1d9));function _0x2bad(_0x3ca330,_0x528fe5){const _0x184e05=_0x184e();return _0x2bad=function(_0x2badac,_0x501740){_0x2badac=_0x2badac-0x133;let _0x10753d=_0x184e05[_0x2badac];return _0x10753d;},_0x2bad(_0x3ca330,_0x528fe5);}function _0x184e(){const _0x28c8b7=['qianfan_chinese_llama_2_7b','toString','sendMessageFromBaidu','end','234440quiGqF','llama_2_7b','POST','defineProperty','1787760RIEQKJ','chatglm2_6b_32k','split','then','toLowerCase','post','replace','data','49soelqy','access_token','completions_pro','trim','1917489XMrZuw','277340rbWMKb','keys','llama_2_13b','catch','1297158RnRdQa','getAccessToken','1497465CAtiIJ','parse','data:\x20','application/json','map','?access_token=','505637zjqcYy'];_0x184e=function(){return _0x28c8b7;};return _0x184e();}Object[_0x57224e(0x149)](exports,'__esModule',{'value':!![]}),exports[_0x57224e(0x144)]=exports[_0x57224e(0x13a)]=void 0x0;const axios=require('axios'),getApiModelMaps=()=>{const _0x121680=_0x57224e;let _0x76586f={};const _0x363493={'ERNIE-Bot':'completions','ERNIE-Bot-turbo':'eb-instant','BLOOMZ-7B':'bloomz_7b1','ERNIE-Bot-4':_0x121680(0x154),'Llama-2-7b-chat':_0x121680(0x147),'Llama-2-13b-chat':_0x121680(0x137),'ChatGLM2-6B-32K':_0x121680(0x14b),'Qianfan-Chinese-Llama-2-7B':_0x121680(0x142)};return Object[_0x121680(0x136)](_0x363493)[_0x121680(0x13f)](_0x7e2527=>{const _0x394796=_0x121680;_0x76586f[''+_0x7e2527[_0x394796(0x14e)]()]=_0x363493[_0x7e2527];}),_0x76586f;};function getAccessToken(_0x18f129,_0x2877e9){let _0x1b7fbc='https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+_0x18f129+'&client_secret='+_0x2877e9;return new Promise((_0x513a43,_0x497a97)=>{const _0x124f2f=_0x2bad;axios[_0x124f2f(0x14f)](_0x1b7fbc)['then'](_0x37fa61=>{const _0x4fee65=_0x124f2f;_0x513a43(_0x37fa61['data'][_0x4fee65(0x153)]);})[_0x124f2f(0x138)](_0x4b0927=>{_0x497a97(_0x4b0927);});});}exports['getAccessToken']=getAccessToken;function sendMessageFromBaidu(_0x357a0c,{onProgress:_0x5c693a,accessToken:_0x338c7f,model:_0x2dc25d,temperature:temperature=0.95}){const _0x515b3b=_0x57224e,_0x39fb4a=getApiModelMaps()[_0x2dc25d[_0x515b3b(0x133)]()['toLowerCase']()];return new Promise((_0x352cf5,_0x5364ea)=>{const _0x3dfb45=_0x515b3b,_0x122fde='https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/'+_0x39fb4a+_0x3dfb45(0x140)+_0x338c7f;var _0x40a1bf={'method':_0x3dfb45(0x148),'url':_0x122fde,'responseType':'stream','headers':{'Content-Type':_0x3dfb45(0x13e)},'data':{'stream':!![],'messages':_0x357a0c}};axios(_0x40a1bf)[_0x3dfb45(0x14d)](_0x39c0d3=>{const _0x4aaa2c=_0x3dfb45,_0xc6bf22=_0x39c0d3[_0x4aaa2c(0x151)];let _0x20f382={},_0x2d7ca1='',_0x1bbae0='';_0xc6bf22['on'](_0x4aaa2c(0x151),_0x1b17eb=>{const _0x397f68=_0x4aaa2c,_0x1929aa=_0x1b17eb[_0x397f68(0x143)]()[_0x397f68(0x14c)]('\x0a\x0a')['filter'](_0x48fa03=>_0x48fa03[_0x397f68(0x133)]()!=='');for(const _0x316b84 of _0x1929aa){const _0x3c895f=_0x316b84[_0x397f68(0x150)](_0x397f68(0x13d),'');try{const _0x1afa95=_0x2d7ca1+_0x3c895f,_0x50a5e9=JSON[_0x397f68(0x13c)](_0x1afa95);_0x2d7ca1='';const {is_end:_0x4d3f7d,result:_0x556d00}=_0x50a5e9;_0x556d00&&(_0x1bbae0+=_0x556d00),_0x4d3f7d&&(_0x20f382=_0x50a5e9,_0x20f382['text']=_0x1bbae0),_0x5c693a(_0x50a5e9);}catch(_0x1f6694){_0x2d7ca1=_0x3c895f;}}}),_0xc6bf22['on'](_0x4aaa2c(0x145),()=>{_0x1bbae0='',_0x2d7ca1='',_0x352cf5(_0x20f382);});})[_0x3dfb45(0x138)](_0x55ea70=>{_0x5364ea(new Error(_0x55ea70));});});}exports['sendMessageFromBaidu']=sendMessageFromBaidu;