Skip to content

Commit

Permalink
Update headers
Browse files Browse the repository at this point in the history
  • Loading branch information
zachey01 committed Jul 12, 2024
1 parent 5bf35d4 commit 5d287bf
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 51 deletions.
2 changes: 1 addition & 1 deletion dist/gpt4js.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions src/Providers/ChatCompletion/AlibabaProvider.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class AlibabaProvider extends Provider {
async chatCompletion(messages, options) {
try {
const response = 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",
},
headers: baseHeaders(
"https://chat.chatgpt.org.uk/api/openai/v1/chat/completions"
),
body: JSON.stringify({
messages: messages,
stream: options.stream || false,
Expand Down
6 changes: 2 additions & 4 deletions src/Providers/ChatCompletion/Aryahcr.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class AryahcrProvider extends Provider {
async chatCompletion(messages, options) {
try {
const response = await fetch("https://nexra.aryahcr.cc/api/chat/gpt", {
method: "POST",
headers: {
accept: "application/json",
"content-type": "application/json",
},
headers: baseHeaders("https://nexra.aryahcr.cc/api/chat/gpt"),
body: JSON.stringify({
messages: messages,
model: options.model || "gpt-4",
Expand Down
9 changes: 2 additions & 7 deletions src/Providers/ChatCompletion/BlackBox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class BlackBoxProvider extends Provider {
async chatCompletion(messages, options = {}) {
Expand Down Expand Up @@ -49,13 +50,7 @@ class BlackBoxProvider extends Provider {
}

const response = await fetch(url, {
headers: {
accept: "*/*",
"content-type": "application/json",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
},
headers: baseHeaders("https://www.blackbox.ai/api/chat"),
body: JSON.stringify(body),
method: "POST",
mode: "cors",
Expand Down
19 changes: 4 additions & 15 deletions src/Providers/ChatCompletion/ChatBotRu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class ChatBotRuProvider extends Provider {
async chatCompletion(messages, options) {
Expand All @@ -15,21 +16,9 @@ class ChatBotRuProvider extends Provider {
const response = await fetch(
"https://gpt-chatbotru-chat-main.ru/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://gpt-chatbotru-chat-main.ru/",
"Referrer-Policy": "strict-origin-when-cross-origin",
},
headers: baseHeaders(
"https://gpt-chatbotru-chat-main.ru/api/openai/v1/chat/completions"
),
body: JSON.stringify({
messages: messages,
stream: options.stream || false,
Expand Down
9 changes: 4 additions & 5 deletions src/Providers/ChatCompletion/Nextway.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class NextwayProvider extends Provider {
async chatCompletion(messages, options) {
Expand All @@ -8,11 +9,9 @@ class NextwayProvider extends Provider {
: "https://chat.eqing.tech/api/openai/v1/chat/completions";

const response = await fetch(proxyUrl, {
headers: {
accept: "text/event-stream",
"content-type": "application/json",
usesearch: "false",
},
headers: baseHeaders(
"https://chat.eqing.tech/api/openai/v1/chat/completions"
),
body: JSON.stringify({
messages: messages,
stream: options.stream,
Expand Down
8 changes: 4 additions & 4 deletions src/Providers/ChatCompletion/Ollama.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use strict";
import Provider from "./provider.js";
import baseHeaders from "../../Utils/baseHeaders.js";

class OllamaProvider extends Provider {
async chatCompletion(messages, options) {
try {
const response = await fetch(
`${options.ollama_url || "http://localhost:11434"}/api/chat`,
{
headers: {
accept: "application/json",
"content-type": "application/json",
},
headers: baseHeaders(
`${options.ollama_url || "http://localhost:11434"}`
),
body: JSON.stringify({
messages: messages,
stream: options.stream || false,
Expand Down
19 changes: 19 additions & 0 deletions src/Utils/baseHeaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function baseHeaders(url) {
return {
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: url,
"Referrer-Policy": "strict-origin-when-cross-origin",
usesearch: "false",
};
}
export default baseHeaders;

0 comments on commit 5d287bf

Please sign in to comment.