diff --git a/dist/gpt4js.min.js b/dist/gpt4js.min.js index 597b60b..4c3485e 100644 --- a/dist/gpt4js.min.js +++ b/dist/gpt4js.min.js @@ -1 +1 @@ -(()=>{"use strict";const e=class{async chatCompletion(e,t){throw new Error("Method 'chatCompletion()' must be implemented.")}},t=class extends e{async chatCompletion(e,t){try{const a=await fetch("https://nexra.aryahcr.cc/api/chat/gpt",{method:"POST",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({messages:e,model:t.model||"gpt-4",temperature:t.temperature||.5,stream:t.stream||!1})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const r=await a.json();if(r.status&&r.gpt)return r.gpt;throw new Error("Unexpected response format")}catch(e){throw console.error("Error:",e),e}}},a=class extends e{async chatCompletion(e,t={}){const a={messages:e,id:()=>[...Array(7)].map((()=>"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())])).join(""),previewToken:null,userId:Math.random().toString(16).substring(2,8)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,12),codeModelMode:t.codeModelMode||!0,agentMode:{},trendingAgentMode:{},isMicMode:!1,isChromeExt:t.isChromeExt||!1,githubToken:null,clickedAnswer2:!1,clickedAnswer3:!1,clickedForceWebSearch:t.webSearch||!1,visitFromDelta:t.visitFromDelta||null};let r;r="undefined"!=typeof window?"https://proxy.zachey.space/?url=http://www.blackbox.ai/api/chat":"https://www.blackbox.ai/api/chat";const o=await fetch(r,{headers:{accept:"*/*","content-type":"application/json","sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"cross-site"},body:JSON.stringify(a),method:"POST",mode:"cors",credentials:"omit"});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const s=await o.text();let n=s.lastIndexOf("$");return s.slice(n+1)}},r=class extends e{async chatCompletion(e,t){const a=await fetch("https://chat.eqing.tech/api/openai/v1/chat/completions",{headers:{accept:"text/event-stream","content-type":"application/json",usesearch:"false"},body:JSON.stringify({messages:e,stream:t.stream,model:t.model||"gpt-4o-free",temperature:t.temperature,captchaToken:"P1_"+btoa(JSON.stringify({typ:"JWT",alg:"HS256"}))+"."+btoa("hashedkey")+"."+btoa("signature")}),method:"POST"});if(a.ok)try{const e=await a.json();if(e.choices&&e.choices.length>0&&e.choices[0].message&&e.choices[0].message.content)return e.choices[0].message.content.trim()}catch(e){console.error("Failed to parse JSON:",e)}else console.error("Network response was not ok")}},o=class extends e{async chatCompletion(e){let t=e[0].content;const a=ai.createTextSession(),r=await a;return await r.prompt(t)}},s=class extends e{async chatCompletion(e,t){try{const a=await fetch(`${t.ollama_url||"http://localhost:11434"}/api/chat`,{headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({messages:e,stream:t.stream||!1,model:t.model}),method:"POST"});if(!a.ok)throw new Error("Network response was not ok");return(await a.json()).message.content}catch(e){console.error("Error fetching data:",e.message)}}},n=class extends e{async chatCompletion(e,t){try{const a=await fetch("https://chat.chatgpt.org.uk/api/openai/v1/chat/completions",{headers:{accept:"application/json, text/event-stream","accept-language":"ru,en;q=0.9","content-type":"application/json",priority:"u=1, i","sec-ch-ua":'"Chromium";v="124", "YaBrowser";v="24.6", "Not-A.Brand";v="99", "Yowser";v="2.5"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin",Referer:"https://chat.chatgpt.org.uk/","Referrer-Policy":"strict-origin-when-cross-origin"},body:JSON.stringify({messages:e,stream:t.stream||!1,model:t.model||"gpt-3.5-turbo",temperature:t.temperature||.5,presence_penalty:t.presence_penalty||0,frequency_penalty:t.frequency_penalty||0,top_p:t.top_p||1}),method:"POST"});return(await a.json()).choices[0].message.content}catch(e){throw console.error("Error:",e),e}}},c=class{async imageGeneration(e,t){throw new Error("Method 'imageGeneration()' must be implemented.")}},i=class extends c{async imageGeneration(e){try{const t=await fetch("https://nexra.aryahcr.cc/api/image/complements",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,model:"dalle"})});if(!t.ok)throw new Error("Failed to fetch data.");const a=(await t.text()).trim().replace(/^_+/,""),r=JSON.parse(a);if(200===r.code&&r.status)return r.images;throw new Error("Server returned unsuccessful response.")}catch(e){throw console.error("Error fetching data:",e),new Error("Failed to fetch data. Please try again later.")}}},p=class extends c{async imageGeneration(e,t){try{const a=await fetch("https://nexra.aryahcr.cc/api/image/complements",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,model:"stablediffusion-2.1",data:{prompt_negative:t.prompt_negative||"",width:t.width||512,height:t.height||512,sampling_method:t.sampling_method||"default",sampling_steps:t.sampling_steps||1,cfg_scale:t.cfg_scale||1}})});if(!a.ok)throw new Error("Failed to fetch data.");const r=(await a.text()).trim().replace(/^_+/,""),o=JSON.parse(r);if(200===o.code&&o.status)return o.images;throw new Error("Server returned unsuccessful response.")}catch(e){throw console.error("Error fetching data:",e),new Error("Failed to fetch data. Please try again later.")}}};"undefined"!=typeof window&&(window.GPT4js=class{static createProvider(e){switch(e){case"Aryahcr":return new t;case"BlackBox":return new a;case"Nextway":return new r;case"Chrome":return new o;case"Ollama":return new s;case"Alibaba":return new n;case"DALLE2":return new i;case"StableDiffusion":return new p;default:throw new Error(`Provider ${e} is not supported.`)}}})})(); \ No newline at end of file +(()=>{"use strict";const e=class{async chatCompletion(e,t){throw new Error("Method 'chatCompletion()' must be implemented.")}},t=class extends e{async chatCompletion(e,t){try{const a=await fetch("https://nexra.aryahcr.cc/api/chat/gpt",{method:"POST",headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({messages:e,model:t.model||"gpt-4",temperature:t.temperature||.5,stream:t.stream||!1})});if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const r=await a.json();if(r.status&&r.gpt)return r.gpt;throw new Error("Unexpected response format")}catch(e){throw console.error("Error:",e),e}}},a=class extends e{async chatCompletion(e,t={}){const a={messages:e,id:()=>[...Array(7)].map((()=>"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[Math.floor(36*Math.random())])).join(""),previewToken:null,userId:Math.random().toString(16).substring(2,8)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,4)+"-"+Math.random().toString(16).substring(2,12),codeModelMode:t.codeModelMode||!0,agentMode:{},trendingAgentMode:{},isMicMode:!1,isChromeExt:t.isChromeExt||!1,githubToken:null,clickedAnswer2:!1,clickedAnswer3:!1,clickedForceWebSearch:t.webSearch||!1,visitFromDelta:t.visitFromDelta||null};let r;r="undefined"!=typeof window?"https://proxy.zachey.space/?url=http://www.blackbox.ai/api/chat":"https://www.blackbox.ai/api/chat";const o=await fetch(r,{headers:{accept:"*/*","content-type":"application/json","sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"cross-site"},body:JSON.stringify(a),method:"POST",mode:"cors",credentials:"omit"});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const s=await o.text();let n=s.lastIndexOf("$");return s.slice(n+1)}},r=class extends e{async chatCompletion(e,t){const a=t.use_proxy?"https://proxy.zachey.space/?url=https://chat.eqing.tech/api/openai/v1/chat/completions":"https://chat.eqing.tech/api/openai/v1/chat/completions",r=await fetch(a,{headers:{accept:"text/event-stream","content-type":"application/json",usesearch:"false"},body:JSON.stringify({messages:e,stream:t.stream,model:t.model||"gpt-4o-free",temperature:t.temperature,captchaToken:"P1_"+btoa(JSON.stringify({typ:"JWT",alg:"HS256"}))+"."+btoa("hashedkey")+"."+btoa("signature")}),method:"POST"});if(r.ok)try{const e=await r.json();if(e.choices&&e.choices.length>0&&e.choices[0].message&&e.choices[0].message.content)return e.choices[0].message.content.trim()}catch(e){console.error("Failed to parse JSON:",e)}else console.error("Network response was not ok")}},o=class extends e{async chatCompletion(e){let t=e[0].content;const a=ai.createTextSession(),r=await a;return await r.prompt(t)}},s=class extends e{async chatCompletion(e,t){try{const a=await fetch(`${t.ollama_url||"http://localhost:11434"}/api/chat`,{headers:{accept:"application/json","content-type":"application/json"},body:JSON.stringify({messages:e,stream:t.stream||!1,model:t.model}),method:"POST"});if(!a.ok)throw new Error("Network response was not ok");return(await a.json()).message.content}catch(e){console.error("Error fetching data:",e.message)}}},n=class extends e{async chatCompletion(e,t){try{const a=await fetch("https://chat.chatgpt.org.uk/api/openai/v1/chat/completions",{headers:{accept:"application/json, text/event-stream","accept-language":"ru,en;q=0.9","content-type":"application/json",priority:"u=1, i","sec-ch-ua":'"Chromium";v="124", "YaBrowser";v="24.6", "Not-A.Brand";v="99", "Yowser";v="2.5"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-origin",Referer:"https://chat.chatgpt.org.uk/","Referrer-Policy":"strict-origin-when-cross-origin"},body:JSON.stringify({messages:e,stream:t.stream||!1,model:t.model||"gpt-3.5-turbo",temperature:t.temperature||.5,presence_penalty:t.presence_penalty||0,frequency_penalty:t.frequency_penalty||0,top_p:t.top_p||1}),method:"POST"});return(await a.json()).choices[0].message.content}catch(e){throw console.error("Error:",e),e}}},c=class{async imageGeneration(e,t){throw new Error("Method 'imageGeneration()' must be implemented.")}},i=class extends c{async imageGeneration(e){try{const t=await fetch("https://nexra.aryahcr.cc/api/image/complements",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,model:"dalle"})});if(!t.ok)throw new Error("Failed to fetch data.");const a=(await t.text()).trim().replace(/^_+/,""),r=JSON.parse(a);if(200===r.code&&r.status)return r.images;throw new Error("Server returned unsuccessful response.")}catch(e){throw console.error("Error fetching data:",e),new Error("Failed to fetch data. Please try again later.")}}},p=class extends c{async imageGeneration(e,t){try{const a=await fetch("https://nexra.aryahcr.cc/api/image/complements",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,model:"stablediffusion-2.1",data:{prompt_negative:t.prompt_negative||"",width:t.width||512,height:t.height||512,sampling_method:t.sampling_method||"default",sampling_steps:t.sampling_steps||1,cfg_scale:t.cfg_scale||1}})});if(!a.ok)throw new Error("Failed to fetch data.");const r=(await a.text()).trim().replace(/^_+/,""),o=JSON.parse(r);if(200===o.code&&o.status)return o.images;throw new Error("Server returned unsuccessful response.")}catch(e){throw console.error("Error fetching data:",e),new Error("Failed to fetch data. Please try again later.")}}};"undefined"!=typeof window&&(window.GPT4js=class{static createProvider(e){switch(e){case"Aryahcr":return new t;case"BlackBox":return new a;case"Nextway":return new r;case"Chrome":return new o;case"Ollama":return new s;case"Alibaba":return new n;case"DALLE2":return new i;case"StableDiffusion":return new p;default:throw new Error(`Provider ${e} is not supported.`)}}})})(); \ No newline at end of file