mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 15:55:50 +00:00
Update googleAdapter.js
This commit is contained in:
@@ -1 +1 @@
|
||||
const _0x3f4ada=_0x2937;(function(_0x2cc17,_0x33dd5d){const _0x482709=_0x2937,_0x4520d3=_0x2cc17();while(!![]){try{const _0x1e32d7=parseInt(_0x482709(0x1cf))/0x1*(parseInt(_0x482709(0x1d3))/0x2)+-parseInt(_0x482709(0x1b6))/0x3+-parseInt(_0x482709(0x1d6))/0x4+parseInt(_0x482709(0x1db))/0x5+-parseInt(_0x482709(0x1bc))/0x6+-parseInt(_0x482709(0x1d2))/0x7+parseInt(_0x482709(0x1c9))/0x8*(parseInt(_0x482709(0x1cb))/0x9);if(_0x1e32d7===_0x33dd5d)break;else _0x4520d3['push'](_0x4520d3['shift']());}catch(_0x400ae8){_0x4520d3['push'](_0x4520d3['shift']());}}}(_0x2cba,0xdfa13));const GOOGLE_DOMAINS=['generativelanguage.googleapis.com',_0x3f4ada(0x1b5),_0x3f4ada(0x1d4)];export function isGoogleEndpoint(_0x174bd1){const _0x4a3c85=_0x3f4ada;try{if(!_0x174bd1||typeof _0x174bd1!=='string')return![];const _0xa2ba49=new URL(_0x174bd1)['hostname'][_0x4a3c85(0x1b7)]();return GOOGLE_DOMAINS[_0x4a3c85(0x1ca)](_0x4ab2f6=>_0xa2ba49[_0x4a3c85(0x1bb)](_0x4ab2f6));}catch(_0x2ae0c3){return console[_0x4a3c85(0x1da)]('[GoogleAdapter]\x20URL解析错误:',_0x174bd1,_0x2ae0c3),![];}}export function convertToGoogleRequest(_0x5250f8){const _0x2440e2=_0x3f4ada,{model:_0x1825eb,..._0xcd8a14}=_0x5250f8,_0x15d7c6=_0x5250f8[_0x2440e2(0x1c1)][_0x2440e2(0x1be)](_0x4425f3=>({'role':_0x4425f3['role']==='system'?'user':_0x4425f3[_0x2440e2(0x1c5)],'parts':[{'text':_0x4425f3[_0x2440e2(0x1cc)]}]}));return{'contents':_0x15d7c6,'generationConfig':{'maxOutputTokens':_0x5250f8[_0x2440e2(0x1b0)],'temperature':_0x5250f8[_0x2440e2(0x1ae)]||0.7,'topP':0.95},'safetySettings':[{'category':_0x2440e2(0x1d7),'threshold':'BLOCK_NONE'},{'category':_0x2440e2(0x1dc),'threshold':_0x2440e2(0x1c2)},{'category':_0x2440e2(0x1c0),'threshold':_0x2440e2(0x1c2)},{'category':_0x2440e2(0x1d9),'threshold':_0x2440e2(0x1c2)}]};}function _0x2cba(){const _0x5d7058=['includes','4007268adSBQj','stop','map','\x0a代码:\x20','HARM_CATEGORY_SEXUALLY_EXPLICIT','messages','BLOCK_NONE','[GoogleAdapter]\x20URL构建错误:','code','role',':generateContent','/v1beta/','无效的API地址:\x20','8bHErUG','some','9753723Kjvfwk','content','join','endsWith','1HkJUgf','parts','未知错误','6622686XgFqsO','2673220eAqSuF','us-central1-aiplatform.googleapis.com','Google\x20API错误:\x20','890292KXBFpR','HARM_CATEGORY_HARASSMENT','candidates','HARM_CATEGORY_DANGEROUS_CONTENT','error','3381795KdJCve','HARM_CATEGORY_HATE_SPEECH','temperature','trim','max_tokens','/v1beta','log','[GoogleAdapter]\x20响应解析错误:','pathname','ai.google.dev','1032540NmZSnS','toLowerCase','text','原始Google响应:','href'];_0x2cba=function(){return _0x5d7058;};return _0x2cba();}function _0x2937(_0x3e17d5,_0xd1dd5c){const _0x2cba54=_0x2cba();return _0x2937=function(_0x293754,_0x348ab2){_0x293754=_0x293754-0x1ae;let _0x3cd183=_0x2cba54[_0x293754];return _0x3cd183;},_0x2937(_0x3e17d5,_0xd1dd5c);}export function parseGoogleResponse(_0x4d5bc2){const _0x3a0982=_0x3f4ada;try{if(_0x4d5bc2[_0x3a0982(0x1da)])throw new Error(_0x3a0982(0x1d5)+(_0x4d5bc2[_0x3a0982(0x1da)]['message']||_0x3a0982(0x1d1))+_0x3a0982(0x1bf)+_0x4d5bc2[_0x3a0982(0x1da)][_0x3a0982(0x1c4)]);const _0x1079f=_0x4d5bc2[_0x3a0982(0x1d8)]?.[0x0];if(!_0x1079f||!_0x1079f[_0x3a0982(0x1cc)])throw new Error('无效的Google\x20API响应:\x20未找到候选内容');const _0x23e015=_0x1079f[_0x3a0982(0x1cc)][_0x3a0982(0x1d0)][_0x3a0982(0x1be)](_0x1098fc=>_0x1098fc[_0x3a0982(0x1b8)]||'')[_0x3a0982(0x1cd)]('\x0a')[_0x3a0982(0x1af)]();return{'choices':[{'index':0x0,'message':{'role':'assistant','content':_0x23e015},'finish_reason':_0x1079f['finishReason']||_0x3a0982(0x1bd)}]};}catch(_0x36285f){console[_0x3a0982(0x1da)](_0x3a0982(0x1b3),_0x36285f),console[_0x3a0982(0x1b2)](_0x3a0982(0x1b9),_0x4d5bc2);throw _0x36285f;}}export function buildGoogleApiUrl(_0x476944,_0x1f5d10){const _0x447044=_0x3f4ada;try{const _0xf78d2f=new URL(_0x476944);if(_0xf78d2f[_0x447044(0x1b4)][_0x447044(0x1ce)](_0x447044(0x1b1))||_0xf78d2f[_0x447044(0x1b4)]['endsWith'](_0x447044(0x1c7))){if(!_0x1f5d10)throw new Error('Google\x20API需要模型名称');return _0xf78d2f[_0x447044(0x1b4)]='v1beta/models/'+_0x1f5d10+_0x447044(0x1c6),_0xf78d2f[_0x447044(0x1ba)];}return _0xf78d2f[_0x447044(0x1ba)];}catch(_0x30ccc6){console[_0x447044(0x1da)](_0x447044(0x1c3),_0x476944,_0x1f5d10,_0x30ccc6);throw new Error(_0x447044(0x1c8)+_0x476944);}}
|
||||
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);}}
|
||||
|
||||
Reference in New Issue
Block a user