diff --git a/core/utils/googleAdapter.js b/core/utils/googleAdapter.js index 792916b..37262a6 100644 --- a/core/utils/googleAdapter.js +++ b/core/utils/googleAdapter.js @@ -1 +1 @@ -const _0xa4d2b3=_0xfcf6;(function(_0x258600,_0x5858fd){const _0x1963a1=_0xfcf6,_0x4ec149=_0x258600();while(!![]){try{const _0x653f50=parseInt(_0x1963a1(0xc1))/0x1*(-parseInt(_0x1963a1(0xbb))/0x2)+-parseInt(_0x1963a1(0xb2))/0x3+parseInt(_0x1963a1(0xc6))/0x4*(-parseInt(_0x1963a1(0x99))/0x5)+parseInt(_0x1963a1(0xb4))/0x6+-parseInt(_0x1963a1(0x8f))/0x7*(parseInt(_0x1963a1(0x9b))/0x8)+-parseInt(_0x1963a1(0xba))/0x9*(parseInt(_0x1963a1(0xaf))/0xa)+parseInt(_0x1963a1(0xa7))/0xb*(parseInt(_0x1963a1(0xc3))/0xc);if(_0x653f50===_0x5858fd)break;else _0x4ec149['push'](_0x4ec149['shift']());}catch(_0x1c38a9){_0x4ec149['push'](_0x4ec149['shift']());}}}(_0xe0b5,0x5f18d));const GOOGLE_DOMAINS=[_0xa4d2b3(0x92),_0xa4d2b3(0x9d),_0xa4d2b3(0x94)];export function isGoogleEndpoint(_0x2c039b){const _0x2b84cb=_0xa4d2b3;try{if(!_0x2c039b||typeof _0x2c039b!=='string')return![];const _0x212257=new URL(_0x2c039b),_0x463cb8=_0x212257['hostname'][_0x2b84cb(0xbd)](),_0x28852c=_0x212257['pathname'][_0x2b84cb(0xbd)]();if(_0x28852c[_0x2b84cb(0x96)]('/openai'))return![];return GOOGLE_DOMAINS[_0x2b84cb(0xb5)](_0x47c97b=>_0x463cb8['includes'](_0x47c97b));}catch(_0x4b2de7){return console[_0x2b84cb(0xaa)](_0x2b84cb(0x97),_0x2c039b,_0x4b2de7),![];}}function _0xfcf6(_0x3bba17,_0x27a13e){const _0xe0b5a=_0xe0b5();return _0xfcf6=function(_0xfcf6d5,_0x1a0468){_0xfcf6d5=_0xfcf6d5-0x8f;let _0xa1b592=_0xe0b5a[_0xfcf6d5];return _0xa1b592;},_0xfcf6(_0x3bba17,_0x27a13e);}export function convertToGoogleRequest(_0x3239e2){const _0x10a05d=_0xa4d2b3,{model:_0xb36bad,..._0x231413}=_0x3239e2,_0x3c91a5=_0x3239e2[_0x10a05d(0xac)][_0x10a05d(0xbe)](_0x18e6f3=>({'role':_0x18e6f3[_0x10a05d(0xb6)]==='system'?_0x10a05d(0xa0):_0x18e6f3[_0x10a05d(0xb6)],'parts':[{'text':_0x18e6f3['content']}]}));return{'contents':_0x3c91a5,'generationConfig':{'maxOutputTokens':_0x3239e2[_0x10a05d(0xa6)],'temperature':_0x3239e2[_0x10a05d(0xb0)]||0.7,'topP':0.95},'safetySettings':[{'category':_0x10a05d(0xa8),'threshold':_0x10a05d(0xb8)},{'category':_0x10a05d(0x9c),'threshold':'BLOCK_NONE'},{'category':_0x10a05d(0x9f),'threshold':_0x10a05d(0xb8)},{'category':_0x10a05d(0xb7),'threshold':_0x10a05d(0xb8)}]};}function _0xe0b5(){const _0x16031c=['[GoogleAdapter]\x20响应解析错误:','us-central1-aiplatform.googleapis.com','text','includes','[GoogleAdapter]\x20URL解析错误:','message','2435460xhJXPD','stop','24KBpnpf','HARM_CATEGORY_HATE_SPEECH','ai.google.dev','href','HARM_CATEGORY_SEXUALLY_EXPLICIT','user','join','无效的Google\x20API响应:\x20未找到候选内容',':batchEmbedContents','v1beta/models/','content','max_tokens','2071883ILydVW','HARM_CATEGORY_HARASSMENT','未知错误','error','value','messages','pathname','\x0a代码:\x20','67380EzNFeT','temperature','embeddings','1538514WPnVBx','/v1beta','298410hizsHG','some','role','HARM_CATEGORY_DANGEROUS_CONTENT','BLOCK_NONE','Google\x20API错误:\x20','774fHFoTZ','1042UgLmev','endsWith','toLowerCase','map','candidates','/v1beta/models/','15itNFwK','[GoogleAdapter]\x20URL构建错误:','168sImTIl',':generateContent','无效的API地址:\x20','4cZbUZs','1656543rMGWCc','models/','log','generativelanguage.googleapis.com'];_0xe0b5=function(){return _0x16031c;};return _0xe0b5();}export function parseGoogleResponse(_0x56178e){const _0x4611b6=_0xa4d2b3;try{if(_0x56178e[_0x4611b6(0xaa)])throw new Error(_0x4611b6(0xb9)+(_0x56178e[_0x4611b6(0xaa)][_0x4611b6(0x98)]||_0x4611b6(0xa9))+_0x4611b6(0xae)+_0x56178e['error']['code']);const _0x32cf68=_0x56178e[_0x4611b6(0xbf)]?.[0x0];if(!_0x32cf68||!_0x32cf68[_0x4611b6(0xa5)])throw new Error(_0x4611b6(0xa2));const _0x1fe196=_0x32cf68[_0x4611b6(0xa5)]['parts'][_0x4611b6(0xbe)](_0x4f41a4=>_0x4f41a4[_0x4611b6(0x95)]||'')[_0x4611b6(0xa1)]('\x0a')['trim']();return{'choices':[{'index':0x0,'message':{'role':'assistant','content':_0x1fe196},'finish_reason':_0x32cf68['finishReason']||_0x4611b6(0x9a)}]};}catch(_0x248ca2){console[_0x4611b6(0xaa)](_0x4611b6(0x93),_0x248ca2),console[_0x4611b6(0x91)]('原始Google响应:',_0x56178e);throw _0x248ca2;}}export function buildGoogleApiUrl(_0x2b9be8,_0x5ac8cf){const _0x52bd37=_0xa4d2b3;try{const _0x326690=new URL(_0x2b9be8);if(_0x326690[_0x52bd37(0xad)][_0x52bd37(0xbc)](_0x52bd37(0xb3))||_0x326690[_0x52bd37(0xad)]['endsWith']('/v1beta/')){if(!_0x5ac8cf)throw new Error('Google\x20API需要模型名称');return _0x326690[_0x52bd37(0xad)]=_0x52bd37(0xa4)+_0x5ac8cf+_0x52bd37(0xc4),_0x326690[_0x52bd37(0x9e)];}return _0x326690[_0x52bd37(0x9e)];}catch(_0x3cab9b){console[_0x52bd37(0xaa)](_0x52bd37(0xc2),_0x2b9be8,_0x5ac8cf,_0x3cab9b);throw new Error(_0x52bd37(0xc5)+_0x2b9be8);}}export function buildGoogleEmbeddingRequest(_0x56263e,_0x4c6a6d){const _0x2d0553=_0xa4d2b3,_0x302751=_0x56263e[_0x2d0553(0xbe)](_0x448f0c=>({'model':_0x2d0553(0x90)+_0x4c6a6d,'content':{'parts':[{'text':_0x448f0c}]}}));return{'requests':_0x302751};}export function parseGoogleEmbeddingResponse(_0x3c8d69){const _0x3e1063=_0xa4d2b3;if(!_0x3c8d69||!Array['isArray'](_0x3c8d69[_0x3e1063(0xb1)])){console['error']('[GoogleAdapter]\x20Google向量API响应格式无效,缺少\x20\x22embeddings\x22\x20数组:',_0x3c8d69);throw new Error('Google\x20API返回的向量数据格式不正确。');}return _0x3c8d69[_0x3e1063(0xb1)]['map'](_0x1d31eb=>_0x1d31eb[_0x3e1063(0xab)]);}export function buildGoogleEmbeddingApiUrl(_0x501411,_0x29dbea){const _0x4aa6d7=_0xa4d2b3,_0x20dd38=new URL(_0x501411);return _0x20dd38[_0x4aa6d7(0xad)]=_0x4aa6d7(0xc0)+_0x29dbea+_0x4aa6d7(0xa3),_0x20dd38['href'];} +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)];}