Files
ST-Amily2-Chat-Optimisation…/core/utils/googleAdapter.js
2025-08-13 09:29:27 +08:00

2 lines
5.3 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.
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'];}