diff --git a/core/utils/googleAdapter.js b/core/utils/googleAdapter.js index 37262a6..cd2cbe6 100644 --- a/core/utils/googleAdapter.js +++ b/core/utils/googleAdapter.js @@ -1 +1 @@ -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)];} +const _0x2923df=_0x870e;(function(_0x55c8c5,_0x322d13){const _0x44e7ec=_0x870e,_0x397650=_0x55c8c5();while(!![]){try{const _0x4e14d7=-parseInt(_0x44e7ec(0x1a2))/0x1+-parseInt(_0x44e7ec(0x1b4))/0x2*(-parseInt(_0x44e7ec(0x189))/0x3)+-parseInt(_0x44e7ec(0x1b5))/0x4*(parseInt(_0x44e7ec(0x184))/0x5)+parseInt(_0x44e7ec(0x19c))/0x6+-parseInt(_0x44e7ec(0x1bd))/0x7*(parseInt(_0x44e7ec(0x1cd))/0x8)+parseInt(_0x44e7ec(0x1b8))/0x9+parseInt(_0x44e7ec(0x1aa))/0xa*(-parseInt(_0x44e7ec(0x195))/0xb);if(_0x4e14d7===_0x322d13)break;else _0x397650['push'](_0x397650['shift']());}catch(_0x310f0f){_0x397650['push'](_0x397650['shift']());}}}(_0x597a,0x731c6));const GOOGLE_DOMAINS=[_0x2923df(0x1d3),_0x2923df(0x19e),_0x2923df(0x1b2)];export function isGoogleEndpoint(_0x5dec1a){const _0x3e802e=_0x2923df;try{if(!_0x5dec1a||typeof _0x5dec1a!=='string')return![];const _0x2d3dcc=new URL(_0x5dec1a),_0x4e984f=_0x2d3dcc[_0x3e802e(0x1a6)][_0x3e802e(0x1c6)](),_0x42a06e=_0x2d3dcc[_0x3e802e(0x192)]['toLowerCase']();if(_0x42a06e[_0x3e802e(0x1ba)](_0x3e802e(0x1cc)))return![];return GOOGLE_DOMAINS[_0x3e802e(0x1a8)](_0x16d9ea=>_0x4e984f['includes'](_0x16d9ea));}catch(_0x2e87e8){return console[_0x3e802e(0x197)]('[GoogleAdapter]\x20URL解析错误:',_0x5dec1a,_0x2e87e8),![];}}function _0x870e(_0x39bcc0,_0x11db59){const _0x597a48=_0x597a();return _0x870e=function(_0x870e62,_0x249d22){_0x870e62=_0x870e62-0x184;let _0x150f93=_0x597a48[_0x870e62];return _0x150f93;},_0x870e(_0x39bcc0,_0x11db59);}export function convertToGoogleRequest(_0xc31358){const _0x5e43a2=_0x2923df,{model:_0x4f96ac,..._0x4223db}=_0xc31358,_0x5d4320=_0xc31358[_0x5e43a2(0x190)][_0x5e43a2(0x1cb)](_0x3f096c=>{const _0x446f63=_0x5e43a2;let _0x6cccf2;return _0x3f096c[_0x446f63(0x1c7)]==='assistant'?_0x6cccf2=_0x446f63(0x1bc):_0x6cccf2=_0x446f63(0x1ca),{'role':_0x6cccf2,'parts':[{'text':_0x3f096c[_0x446f63(0x1ab)]}]};});return{'contents':_0x5d4320,'generationConfig':{'maxOutputTokens':_0xc31358[_0x5e43a2(0x1c9)],'temperature':_0xc31358[_0x5e43a2(0x1bf)]||0.7,'topP':0.95},'safetySettings':[{'category':_0x5e43a2(0x1c0),'threshold':'BLOCK_NONE'},{'category':_0x5e43a2(0x18a),'threshold':'BLOCK_NONE'},{'category':_0x5e43a2(0x18f),'threshold':'BLOCK_NONE'},{'category':'HARM_CATEGORY_DANGEROUS_CONTENT','threshold':_0x5e43a2(0x1af)}]};}export function parseGoogleResponse(_0x5a146d){const _0x15edd8=_0x2923df;try{if(_0x5a146d[_0x15edd8(0x197)])throw new Error(_0x15edd8(0x188)+(_0x5a146d[_0x15edd8(0x197)]['message']||'未知错误')+_0x15edd8(0x186)+_0x5a146d[_0x15edd8(0x197)][_0x15edd8(0x1ae)]);const _0x3c0ae5=_0x5a146d[_0x15edd8(0x1d2)]?.[0x0];if(!_0x3c0ae5||!_0x3c0ae5[_0x15edd8(0x1ab)])throw new Error('无效的Google\x20API响应:\x20未找到候选内容');const _0x1ba684=_0x3c0ae5[_0x15edd8(0x1ab)]['parts']['map'](_0x5851ce=>_0x5851ce['text']||'')['join']('\x0a')[_0x15edd8(0x1b3)]();return{'choices':[{'index':0x0,'message':{'role':_0x15edd8(0x193),'content':_0x1ba684},'finish_reason':_0x3c0ae5[_0x15edd8(0x1c3)]||'stop'}]};}catch(_0x1801ad){console[_0x15edd8(0x197)](_0x15edd8(0x1d4),_0x1801ad),console[_0x15edd8(0x1ad)]('原始Google响应:',_0x5a146d);throw _0x1801ad;}}export function buildGoogleApiUrl(_0x5f09ce,_0x42bad5){const _0x5c0cce=_0x2923df;try{const _0x594385=new URL(_0x5f09ce),_0x182977=_0x594385[_0x5c0cce(0x192)][_0x5c0cce(0x19b)](/\/$/,'');if(_0x182977[_0x5c0cce(0x1a5)](_0x5c0cce(0x1a9))||_0x182977[_0x5c0cce(0x1a5)](_0x5c0cce(0x191))){if(!_0x42bad5)throw new Error(_0x5c0cce(0x1a1));const _0x2c2c8a=_0x182977[_0x5c0cce(0x1a5)](_0x5c0cce(0x1a9))?_0x5c0cce(0x18c):'v1';return _0x594385[_0x5c0cce(0x192)]='/'+_0x2c2c8a+_0x5c0cce(0x18e)+_0x42bad5+_0x5c0cce(0x19a),_0x594385[_0x5c0cce(0x1a7)];}return _0x594385[_0x5c0cce(0x1a7)];}catch(_0x33b49e){console[_0x5c0cce(0x197)](_0x5c0cce(0x1a0),_0x5f09ce,_0x42bad5,_0x33b49e);throw new Error(_0x5c0cce(0x185)+_0x5f09ce);}}export function buildGoogleEmbeddingRequest(_0x4d935c,_0x3307f9){const _0x55ba0e=_0x2923df,_0x25dd73=_0x4d935c[_0x55ba0e(0x1cb)](_0x2ceecd=>({'model':_0x55ba0e(0x1a4)+_0x3307f9,'content':{'parts':[{'text':_0x2ceecd}]}}));return{'requests':_0x25dd73};}export function parseGoogleEmbeddingResponse(_0x308125,_0x31970e){const _0x11f1a0=_0x2923df;if(!_0x308125||!Array[_0x11f1a0(0x1ac)](_0x308125['embeddings'])){console['error']('[GoogleAdapter]\x20Google向量API响应格式无效,缺少\x20\x22embeddings\x22\x20数组:',_0x308125);throw new Error(_0x11f1a0(0x1ce));}return _0x308125[_0x11f1a0(0x1a3)]['map'](_0x27ccf1=>_0x27ccf1[_0x11f1a0(0x1c5)]);}export function buildGoogleEmbeddingApiUrl(_0x3dfc7d,_0x19a25b){const _0x19979f=_0x2923df,_0x295dd2=new URL(_0x3dfc7d),_0x1d9044=_0x19a25b['includes'](_0x19979f(0x1b6))?_0x19979f(0x18c):'v1';return _0x295dd2[_0x19979f(0x192)]='/'+_0x1d9044+_0x19979f(0x18e)+_0x19a25b+_0x19979f(0x196),_0x295dd2[_0x19979f(0x1a7)];}function convertOaiToGoogleForPlotOptimization(_0x42e8bc){const _0x26ff00=_0x2923df,_0x3a1d0a=[];let _0x673c24=null,_0x1a9726='';for(const _0x7a7e5c of _0x42e8bc){if(_0x7a7e5c['role']===_0x26ff00(0x1ca)&&_0x1a9726==='user'){const _0x339949=_0x3a1d0a[_0x3a1d0a[_0x26ff00(0x1d0)]-0x1];_0x339949[_0x26ff00(0x1be)][_0x26ff00(0x1c4)]({'text':'\x0a\x0a'+_0x7a7e5c[_0x26ff00(0x1ab)]});continue;}_0x7a7e5c[_0x26ff00(0x1c7)]==='assistant'?(_0x3a1d0a[_0x26ff00(0x1c4)]({'role':'model','parts':[{'text':_0x7a7e5c[_0x26ff00(0x1ab)]}]}),_0x1a9726=_0x26ff00(0x1bc)):(_0x3a1d0a[_0x26ff00(0x1c4)]({'role':'user','parts':[{'text':_0x7a7e5c[_0x26ff00(0x1ab)]}]}),_0x1a9726=_0x26ff00(0x1ca));}return{'contents':_0x3a1d0a,'system_instruction':_0x673c24};}export function buildPlotOptimizationGoogleRequest(_0xa36e70,_0x2759a9){const _0x25cb2d=_0x2923df,{contents:_0x2c652f}=convertOaiToGoogleForPlotOptimization(_0xa36e70),_0x3e2a85={'temperature':_0x2759a9['temperature'],'topP':_0x2759a9[_0x25cb2d(0x19f)],'topK':_0x2759a9[_0x25cb2d(0x1d5)],'maxOutputTokens':_0x2759a9[_0x25cb2d(0x1c9)]};if(_0x3e2a85[_0x25cb2d(0x19d)])_0x3e2a85[_0x25cb2d(0x19d)]=Math[_0x25cb2d(0x1b1)](_0x3e2a85[_0x25cb2d(0x19d)]);Object['keys'](_0x3e2a85)[_0x25cb2d(0x1b0)](_0x7627b1=>{(_0x3e2a85[_0x7627b1]===undefined||_0x3e2a85[_0x7627b1]===null)&&delete _0x3e2a85[_0x7627b1];});_0x2c652f['length']===0x0&&_0x2c652f['push']({'role':_0x25cb2d(0x1ca),'parts':[{'text':'Hi'}]});const _0x424b73=[{'category':_0x25cb2d(0x1c0),'threshold':_0x25cb2d(0x1af)},{'category':_0x25cb2d(0x18a),'threshold':'BLOCK_NONE'},{'category':_0x25cb2d(0x18f),'threshold':_0x25cb2d(0x1af)},{'category':_0x25cb2d(0x1bb),'threshold':_0x25cb2d(0x1af)}],_0x4d35ca={'contents':_0x2c652f,'generationConfig':_0x3e2a85,'safetySettings':_0x424b73};return _0x4d35ca;}export function parsePlotOptimizationGoogleResponse(_0x6a0529){const _0x365ecb=_0x2923df;try{const _0x49249c=_0x6a0529?.['candidates'];if(!_0x49249c||_0x49249c['length']===0x0){let _0x179647='Google\x20API\x20returned\x20no\x20candidates.';return _0x6a0529?.[_0x365ecb(0x199)]?.[_0x365ecb(0x198)]&&(_0x179647+=_0x365ecb(0x1d1)+_0x6a0529[_0x365ecb(0x199)]['blockReason'],console[_0x365ecb(0x197)](_0x179647,_0x6a0529[_0x365ecb(0x199)][_0x365ecb(0x1b9)])),{'choices':[{'message':{'content':_0x365ecb(0x18d)+_0x179647}}]};}const _0xc6e478=_0x49249c[0x0][_0x365ecb(0x1ab)],_0x29f236=_0xc6e478?.['parts']?.[_0x365ecb(0x1cb)](_0x42139d=>_0x42139d[_0x365ecb(0x1c1)])[_0x365ecb(0x187)]('')||'';if(!_0x29f236){let _0x537224=_0x365ecb(0x1cf);return console[_0x365ecb(0x1b7)](_0x537224,_0x6a0529),{'choices':[{'message':{'content':_0x365ecb(0x1c2)}}]};}return{'choices':[{'message':{'content':_0x29f236}}]};}catch(_0xc6c5d7){return console[_0x365ecb(0x197)](_0x365ecb(0x18b),_0xc6c5d7,_0x6a0529),{'choices':[{'message':{'content':_0x365ecb(0x1c8)+_0xc6c5d7[_0x365ecb(0x194)]}}]};}}function _0x597a(){const _0x2ad756=['Error:\x20Received\x20an\x20empty\x20response\x20from\x20the\x20API.','finishReason','push','values','toLowerCase','role','Error:\x20Failed\x20to\x20parse\x20Google\x20API\x20response.\x20Details:\x20','max_tokens','user','map','/openai','137136iuLZtD','Google\x20API返回的向量数据格式不正确。','Google\x20API\x20response\x20text\x20is\x20empty.','length','\x0aPrompt\x20was\x20blocked\x20due\x20to:\x20','candidates','generativelanguage.googleapis.com','[GoogleAdapter]\x20响应解析错误:','top_k','185taCXoq','无效的API地址:\x20','\x0a代码:\x20','join','Google\x20API错误:\x20','24ZahhKQ','HARM_CATEGORY_HATE_SPEECH','Error\x20parsing\x20Google\x20response:','v1beta','Error:\x20','/models/','HARM_CATEGORY_SEXUALLY_EXPLICIT','messages','/v1','pathname','assistant','message','11apETjI',':batchEmbedContents','error','blockReason','promptFeedback',':generateContent','replace','3609582PRfkyG','topK','ai.google.dev','top_p','[GoogleAdapter]\x20URL构建错误:','Google\x20API需要模型名称','46463SAtDWr','embeddings','models/','endsWith','hostname','href','some','/v1beta','3743270lssfcm','content','isArray','log','code','BLOCK_NONE','forEach','round','us-central1-aiplatform.googleapis.com','trim','113758IZqZmZ','19332xjaTMJ','gemini','warn','6147126ASHbqN','safetyRatings','includes','HARM_CATEGORY_DANGEROUS_CONTENT','model','273BqNEmY','parts','temperature','HARM_CATEGORY_HARASSMENT','text'];_0x597a=function(){return _0x2ad756;};return _0x597a();}