mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 11:15:50 +00:00
2 lines
4.3 KiB
JavaScript
2 lines
4.3 KiB
JavaScript
const _0x37c83d=_0x3fde;(function(_0x246fe1,_0x20c8b1){const _0x1b501b=_0x3fde,_0x3bd7ef=_0x246fe1();while(!![]){try{const _0x335185=-parseInt(_0x1b501b(0x1b0))/0x1*(-parseInt(_0x1b501b(0x194))/0x2)+parseInt(_0x1b501b(0x1be))/0x3+parseInt(_0x1b501b(0x1ad))/0x4+-parseInt(_0x1b501b(0x1bd))/0x5+-parseInt(_0x1b501b(0x1a8))/0x6+parseInt(_0x1b501b(0x19f))/0x7*(parseInt(_0x1b501b(0x1a2))/0x8)+-parseInt(_0x1b501b(0x1ab))/0x9;if(_0x335185===_0x20c8b1)break;else _0x3bd7ef['push'](_0x3bd7ef['shift']());}catch(_0x18dc4a){_0x3bd7ef['push'](_0x3bd7ef['shift']());}}}(_0x33c1,0x2bada));function _0x33c1(){const _0x2ad785=['us-central1-aiplatform.googleapis.com','href','HARM_CATEGORY_DANGEROUS_CONTENT','error','message','endsWith','7LPCSFJ','/v1beta',':generateContent','1675376wWMhPS','HARM_CATEGORY_HATE_SPEECH','无效的API地址:\x20','includes','string','BLOCK_NONE','2111928cTBiqf','HARM_CATEGORY_HARASSMENT','some','64467BQPeQF','candidates','878008ZwQnHH','user','[GoogleAdapter]\x20URL解析错误:','1gqxOIs','text','finishReason','map','join','pathname','toLowerCase','temperature','Google\x20API需要模型名称','content','hostname','[GoogleAdapter]\x20URL构建错误:','v1beta/models/','1266035FJedwT','743754elRShm','max_tokens','ai.google.dev','assistant','stop','role','228844xmswfw','trim','原始Google响应:','generativelanguage.googleapis.com','code'];_0x33c1=function(){return _0x2ad785;};return _0x33c1();}function _0x3fde(_0x4a4ad4,_0x2ab59d){const _0x33c16c=_0x33c1();return _0x3fde=function(_0x3fdec8,_0x45a6ce){_0x3fdec8=_0x3fdec8-0x194;let _0x2c387b=_0x33c16c[_0x3fdec8];return _0x2c387b;},_0x3fde(_0x4a4ad4,_0x2ab59d);}const GOOGLE_DOMAINS=[_0x37c83d(0x197),_0x37c83d(0x1c0),_0x37c83d(0x199)];export function isGoogleEndpoint(_0x5a4beb){const _0x332235=_0x37c83d;try{if(!_0x5a4beb||typeof _0x5a4beb!==_0x332235(0x1a6))return![];const _0x1a2e0a=new URL(_0x5a4beb),_0x328f3a=_0x1a2e0a[_0x332235(0x1ba)][_0x332235(0x1b6)](),_0x427a05=_0x1a2e0a[_0x332235(0x1b5)]['toLowerCase']();if(_0x427a05[_0x332235(0x1a5)]('/openai'))return![];return GOOGLE_DOMAINS[_0x332235(0x1aa)](_0x8b9884=>_0x328f3a[_0x332235(0x1a5)](_0x8b9884));}catch(_0x4f6eb3){return console[_0x332235(0x19c)](_0x332235(0x1af),_0x5a4beb,_0x4f6eb3),![];}}export function convertToGoogleRequest(_0x52d7b0){const _0x52af62=_0x37c83d,{model:_0x3df384,..._0x153539}=_0x52d7b0,_0x2bace0=_0x52d7b0['messages'][_0x52af62(0x1b3)](_0x37bc23=>({'role':_0x37bc23[_0x52af62(0x1c3)]==='system'?_0x52af62(0x1ae):_0x37bc23['role'],'parts':[{'text':_0x37bc23[_0x52af62(0x1b9)]}]}));return{'contents':_0x2bace0,'generationConfig':{'maxOutputTokens':_0x52d7b0[_0x52af62(0x1bf)],'temperature':_0x52d7b0[_0x52af62(0x1b7)]||0.7,'topP':0.95},'safetySettings':[{'category':_0x52af62(0x1a9),'threshold':_0x52af62(0x1a7)},{'category':_0x52af62(0x1a3),'threshold':'BLOCK_NONE'},{'category':'HARM_CATEGORY_SEXUALLY_EXPLICIT','threshold':_0x52af62(0x1a7)},{'category':_0x52af62(0x19b),'threshold':_0x52af62(0x1a7)}]};}export function parseGoogleResponse(_0x298877){const _0x282875=_0x37c83d;try{if(_0x298877[_0x282875(0x19c)])throw new Error('Google\x20API错误:\x20'+(_0x298877['error'][_0x282875(0x19d)]||'未知错误')+'\x0a代码:\x20'+_0x298877['error'][_0x282875(0x198)]);const _0x4f55f6=_0x298877[_0x282875(0x1ac)]?.[0x0];if(!_0x4f55f6||!_0x4f55f6['content'])throw new Error('无效的Google\x20API响应:\x20未找到候选内容');const _0x3935cc=_0x4f55f6[_0x282875(0x1b9)]['parts'][_0x282875(0x1b3)](_0x541deb=>_0x541deb[_0x282875(0x1b1)]||'')[_0x282875(0x1b4)]('\x0a')[_0x282875(0x195)]();return{'choices':[{'index':0x0,'message':{'role':_0x282875(0x1c1),'content':_0x3935cc},'finish_reason':_0x4f55f6[_0x282875(0x1b2)]||_0x282875(0x1c2)}]};}catch(_0xc0f79b){console['error']('[GoogleAdapter]\x20响应解析错误:',_0xc0f79b),console['log'](_0x282875(0x196),_0x298877);throw _0xc0f79b;}}export function buildGoogleApiUrl(_0x32feb0,_0xedb6e8){const _0x810c5f=_0x37c83d;try{const _0x343071=new URL(_0x32feb0);if(_0x343071[_0x810c5f(0x1b5)][_0x810c5f(0x19e)](_0x810c5f(0x1a0))||_0x343071[_0x810c5f(0x1b5)]['endsWith']('/v1beta/')){if(!_0xedb6e8)throw new Error(_0x810c5f(0x1b8));return _0x343071[_0x810c5f(0x1b5)]=_0x810c5f(0x1bc)+_0xedb6e8+_0x810c5f(0x1a1),_0x343071[_0x810c5f(0x19a)];}return _0x343071['href'];}catch(_0x3c7835){console[_0x810c5f(0x19c)](_0x810c5f(0x1bb),_0x32feb0,_0xedb6e8,_0x3c7835);throw new Error(_0x810c5f(0x1a4)+_0x32feb0);}}
|