mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 16:15:50 +00:00
2 lines
5.6 KiB
JavaScript
2 lines
5.6 KiB
JavaScript
const _0x343a5b=_0x57c0;(function(_0x55a9d2,_0x38d782){const _0x3e39e8=_0x57c0,_0x556ca3=_0x55a9d2();while(!![]){try{const _0x5b91b7=-parseInt(_0x3e39e8(0x1a1))/0x1+parseInt(_0x3e39e8(0x1ce))/0x2+parseInt(_0x3e39e8(0x1cc))/0x3*(-parseInt(_0x3e39e8(0x19f))/0x4)+parseInt(_0x3e39e8(0x1a4))/0x5*(-parseInt(_0x3e39e8(0x1dc))/0x6)+-parseInt(_0x3e39e8(0x1d7))/0x7*(-parseInt(_0x3e39e8(0x1a2))/0x8)+parseInt(_0x3e39e8(0x1d2))/0x9+-parseInt(_0x3e39e8(0x1c0))/0xa*(parseInt(_0x3e39e8(0x1ac))/0xb);if(_0x5b91b7===_0x38d782)break;else _0x556ca3['push'](_0x556ca3['shift']());}catch(_0x578cd8){_0x556ca3['push'](_0x556ca3['shift']());}}}(_0x55b3,0xac7aa));const GOOGLE_DOMAINS=[_0x343a5b(0x1bb),_0x343a5b(0x1ba),_0x343a5b(0x1cb)];export function isGoogleEndpoint(_0x5f2a0b){const _0x1b9be3=_0x343a5b;try{if(!_0x5f2a0b||typeof _0x5f2a0b!==_0x1b9be3(0x1bc))return![];const _0x242621=new URL(_0x5f2a0b),_0x2f77f4=_0x242621[_0x1b9be3(0x1ad)]['toLowerCase'](),_0x5c0e0d=_0x242621[_0x1b9be3(0x1bf)][_0x1b9be3(0x19e)]();if(_0x5c0e0d['includes'](_0x1b9be3(0x1b9)))return![];return GOOGLE_DOMAINS['some'](_0x1449b8=>_0x2f77f4[_0x1b9be3(0x1ae)](_0x1449b8));}catch(_0x1d118f){return console[_0x1b9be3(0x1d8)](_0x1b9be3(0x1b1),_0x5f2a0b,_0x1d118f),![];}}export function convertToGoogleRequest(_0x440d12){const _0x26b1fa=_0x343a5b,{model:_0x1de9b5,..._0xa329f}=_0x440d12,_0x5ba7d3=_0x440d12[_0x26b1fa(0x1d3)][_0x26b1fa(0x1da)](_0x34fd8f=>({'role':_0x34fd8f[_0x26b1fa(0x1bd)]===_0x26b1fa(0x1d0)?'user':_0x34fd8f[_0x26b1fa(0x1bd)],'parts':[{'text':_0x34fd8f[_0x26b1fa(0x1cf)]}]}));return{'contents':_0x5ba7d3,'generationConfig':{'maxOutputTokens':_0x440d12[_0x26b1fa(0x1c9)],'temperature':_0x440d12[_0x26b1fa(0x1db)]||0.7,'topP':0.95},'safetySettings':[{'category':_0x26b1fa(0x1b7),'threshold':'BLOCK_NONE'},{'category':_0x26b1fa(0x1d4),'threshold':_0x26b1fa(0x1b8)},{'category':_0x26b1fa(0x1c4),'threshold':'BLOCK_NONE'},{'category':_0x26b1fa(0x1d1),'threshold':_0x26b1fa(0x1b8)}]};}export function parseGoogleResponse(_0x1d7813){const _0x6cc288=_0x343a5b;try{if(_0x1d7813[_0x6cc288(0x1d8)])throw new Error('Google\x20API错误:\x20'+(_0x1d7813['error'][_0x6cc288(0x1a6)]||_0x6cc288(0x1d6))+_0x6cc288(0x1b4)+_0x1d7813[_0x6cc288(0x1d8)][_0x6cc288(0x1a9)]);const _0x156ad0=_0x1d7813[_0x6cc288(0x1a7)]?.[0x0];if(!_0x156ad0||!_0x156ad0['content'])throw new Error(_0x6cc288(0x1c2));const _0x39dc06=_0x156ad0[_0x6cc288(0x1cf)][_0x6cc288(0x1ca)][_0x6cc288(0x1da)](_0x2788cb=>_0x2788cb[_0x6cc288(0x1c6)]||'')[_0x6cc288(0x19d)]('\x0a')[_0x6cc288(0x1b6)]();return{'choices':[{'index':0x0,'message':{'role':'assistant','content':_0x39dc06},'finish_reason':_0x156ad0[_0x6cc288(0x1a8)]||'stop'}]};}catch(_0x26602e){console[_0x6cc288(0x1d8)](_0x6cc288(0x1c7),_0x26602e),console[_0x6cc288(0x1af)](_0x6cc288(0x1aa),_0x1d7813);throw _0x26602e;}}export function buildGoogleApiUrl(_0x2f50ed,_0x127fb0){const _0xd7a1dc=_0x343a5b;try{const _0x1061fb=new URL(_0x2f50ed);if(_0x1061fb[_0xd7a1dc(0x1bf)]['endsWith'](_0xd7a1dc(0x1be))||_0x1061fb[_0xd7a1dc(0x1bf)][_0xd7a1dc(0x1d9)]('/v1beta/')){if(!_0x127fb0)throw new Error(_0xd7a1dc(0x1c8));return _0x1061fb[_0xd7a1dc(0x1bf)]=_0xd7a1dc(0x1ab)+_0x127fb0+_0xd7a1dc(0x1a0),_0x1061fb[_0xd7a1dc(0x1a3)];}return _0x1061fb[_0xd7a1dc(0x1a3)];}catch(_0x5e23fa){console['error'](_0xd7a1dc(0x1b0),_0x2f50ed,_0x127fb0,_0x5e23fa);throw new Error(_0xd7a1dc(0x1a5)+_0x2f50ed);}}export function buildGoogleEmbeddingRequest(_0x39893c,_0x90cd00){const _0x4f3be4=_0x343a5b,_0x27f602=_0x39893c[_0x4f3be4(0x1da)](_0x36f9a1=>({'model':_0x4f3be4(0x1c1)+_0x90cd00,'content':{'parts':[{'text':_0x36f9a1}]}}));return{'requests':_0x27f602};}function _0x55b3(){const _0x4ffdba=['Google\x20API返回的向量数据格式不正确。','HARM_CATEGORY_SEXUALLY_EXPLICIT',':batchEmbedContents','text','[GoogleAdapter]\x20响应解析错误:','Google\x20API需要模型名称','max_tokens','parts','us-central1-aiplatform.googleapis.com','7131YzQZxR','embeddings','1932060MQHWml','content','system','HARM_CATEGORY_DANGEROUS_CONTENT','9244683AIJfwN','messages','HARM_CATEGORY_HATE_SPEECH','isArray','未知错误','22316RyfkMD','error','endsWith','map','temperature','6nOoxjy','join','toLowerCase','1528uckbBN',':generateContent','172256yvEoCd','2584EngcDY','href','3359995ukvOgn','无效的API地址:\x20','message','candidates','finishReason','code','原始Google响应:','v1beta/models/','6206178GhBPZq','hostname','includes','log','[GoogleAdapter]\x20URL构建错误:','[GoogleAdapter]\x20URL解析错误:','v1beta','gemini','\x0a代码:\x20','values','trim','HARM_CATEGORY_HARASSMENT','BLOCK_NONE','/openai','ai.google.dev','generativelanguage.googleapis.com','string','role','/v1beta','pathname','10yMMUEG','models/','无效的Google\x20API响应:\x20未找到候选内容'];_0x55b3=function(){return _0x4ffdba;};return _0x55b3();}export function parseGoogleEmbeddingResponse(_0x330f41,_0x53a351){const _0x151389=_0x343a5b;if(!_0x330f41||!Array[_0x151389(0x1d5)](_0x330f41[_0x151389(0x1cd)])){console[_0x151389(0x1d8)]('[GoogleAdapter]\x20Google向量API响应格式无效,缺少\x20\x22embeddings\x22\x20数组:',_0x330f41);throw new Error(_0x151389(0x1c3));}return _0x330f41[_0x151389(0x1cd)][_0x151389(0x1da)](_0x3e7b96=>_0x3e7b96[_0x151389(0x1b5)]);}function _0x57c0(_0x860d9d,_0x6fc6ee){const _0x55b322=_0x55b3();return _0x57c0=function(_0x57c0ff,_0x506c76){_0x57c0ff=_0x57c0ff-0x19d;let _0x20b27f=_0x55b322[_0x57c0ff];return _0x20b27f;},_0x57c0(_0x860d9d,_0x6fc6ee);}export function buildGoogleEmbeddingApiUrl(_0x418854,_0x2329d9){const _0x2a0a4a=_0x343a5b,_0x58a495=new URL(_0x418854),_0x5dbfe1=_0x2329d9[_0x2a0a4a(0x1ae)](_0x2a0a4a(0x1b3))?_0x2a0a4a(0x1b2):'v1';return _0x58a495['pathname']='/'+_0x5dbfe1+'/models/'+_0x2329d9+_0x2a0a4a(0x1c5),_0x58a495[_0x2a0a4a(0x1a3)];}
|