From d77c13848ab25266e54beaf0bc509724c60e6514 Mon Sep 17 00:00:00 2001 From: ishan dutta Date: Sat, 11 May 2024 04:17:59 +0530 Subject: [PATCH] chatgpt_fix --- package-lock.json | 63 +++++++++++++++++++++++-- package.json | 1 + src/background/index.ts | 3 +- src/background/providers/chatgpt.ts | 12 ++--- src/background/providers/chatgpt_new.ts | 6 +-- src/content-script/ChatGPTQuery.tsx | 2 +- src/manifest.json | 5 +- src/manifest.v2.json | 8 +++- src/popup/App.tsx | 4 +- 9 files changed, 84 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index f6cf74f..6e083af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "expiry-map": "^2.0.0", "github-markdown-css": "^5.1.0", "inter-ui": "^3.19.3", + "llm-playground-chain": "^0.0.6", "lodash-es": "^4.17.21", "ofetch": "^1.0.1", "preact": "^10.11.3", @@ -1374,7 +1375,6 @@ "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "dev": true, "funding": [ { "type": "github", @@ -3498,7 +3498,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, "funding": [ { "type": "github", @@ -4203,6 +4202,58 @@ "node": ">=8" } }, + "node_modules/llm-playground-chain": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/llm-playground-chain/-/llm-playground-chain-0.0.6.tgz", + "integrity": "sha512-NqRv/0Io7A2Z+3AjjqJK3me9AKjzXngeXKklQDC97DtOanqmYrlGD4GyWvDloBi7Jpm8G99djuY3sMBbfDlLLA==", + "dependencies": { + "buffer": "^6.0.3", + "dayjs": "^1.11.9", + "eventsource-parser": "^1.0.0", + "expiry-map": "^2.0.0", + "lodash-es": "^4.17.21", + "rollup-plugin-includepaths": "^0.2.4", + "uuid": "^9.0.0", + "webextension-polyfill": "^0.10.0", + "websocket-as-promised": "^2.0.1" + }, + "engines": { + "node": ">=18.17.1 <19.0.0", + "npm": ">=9.6.7 <10.0.0", + "pnpm": ">=8.15.5" + } + }, + "node_modules/llm-playground-chain/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/llm-playground-chain/node_modules/eventsource-parser": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-1.1.2.tgz", + "integrity": "sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==", + "engines": { + "node": ">=14.18" + } + }, "node_modules/loader-utils": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-3.2.1.tgz", @@ -6185,6 +6236,11 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup-plugin-includepaths": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/rollup-plugin-includepaths/-/rollup-plugin-includepaths-0.2.4.tgz", + "integrity": "sha512-iZen+XKVExeCzk7jeSZPJKL7B67slZNr8GXSC5ROBXtDGXDBH8wdjMfdNW5hf9kPt+tHyIvWh3wlE9bPrZL24g==" + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -7194,8 +7250,7 @@ "node_modules/webextension-polyfill": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz", - "integrity": "sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g==", - "dev": true + "integrity": "sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g==" }, "node_modules/webidl-conversions": { "version": "3.0.1", diff --git a/package.json b/package.json index 4676529..389e395 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "expiry-map": "^2.0.0", "github-markdown-css": "^5.1.0", "inter-ui": "^3.19.3", + "llm-playground-chain": "^0.0.6", "lodash-es": "^4.17.21", "ofetch": "^1.0.1", "preact": "^10.11.3", diff --git a/src/background/index.ts b/src/background/index.ts index f3b7c7d..b7f31b7 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,6 +1,7 @@ import Browser from 'webextension-polyfill' import { getProviderConfigs, ProviderType } from '../config' -import { ChatGPTProvider, getChatGPTAccessToken, sendMessageFeedback } from './providers/chatgpt' +// import { ChatGPTProvider, getChatGPTAccessToken, sendMessageFeedback } from './providers/chatgpt' +import { ChatGPTProvider, getChatGPTAccessToken, sendMessageFeedback } from 'llm-playground-chain' import { OpenAIProvider } from './providers/openai' import { Provider } from './types' diff --git a/src/background/providers/chatgpt.ts b/src/background/providers/chatgpt.ts index f2ed289..8b8fba6 100644 --- a/src/background/providers/chatgpt.ts +++ b/src/background/providers/chatgpt.ts @@ -12,7 +12,7 @@ import { GenerateAnswerParams, Provider } from '../types' dayjs().format() async function request(token: string, method: string, path: string, data?: unknown) { - return fetch(`https://chat.openai.com/backend-api${path}`, { + return fetch(`https://chatgpt.com/backend-api${path}`, { method, headers: { 'Content-Type': 'application/json', @@ -56,7 +56,7 @@ async function request_new( data?: unknown, callback?: unknown, ) { - return fetch(`https://chat.openai.com/backend-api${path}`, { + return fetch(`https://chatgpt.com/backend-api${path}`, { method, headers: { 'Content-Type': 'application/json', @@ -152,7 +152,7 @@ export async function getChatGPTAccessToken(): Promise { if (cache.get(KEY_ACCESS_TOKEN)) { return cache.get(KEY_ACCESS_TOKEN) } - const resp = await fetch('https://chat.openai.com/api/auth/session') + const resp = await fetch('https://chatgpt.com/api/auth/session') if (resp.status === 403) { throw new Error('CLOUDFLARE') } @@ -201,7 +201,7 @@ export class ChatGPTProvider implements Provider { } async getChatRequirementsToken(params: SendMessageParams) { - const resp = await fetch('https://chat.openai.com/backend-api/sentinel/chat-requirements', { + const resp = await fetch('https://chatgpt.com/backend-api/sentinel/chat-requirements', { method: 'POST', signal: params.signal, headers: { @@ -224,7 +224,7 @@ export class ChatGPTProvider implements Provider { } async registerWSS(params: GenerateAnswerParams) { - const resp = await fetch('https://chat.openai.com/backend-api/register-websocket', { + const resp = await fetch('https://chatgpt.com/backend-api/register-websocket', { method: 'POST', signal: params.signal, headers: { @@ -397,7 +397,7 @@ export class ChatGPTProvider implements Provider { const chatRequirementsToken = await this.getChatRequirementsToken(params) console.debug('Using model:', modelName) - await fetchSSE('https://chat.openai.com/backend-api/conversation', { + await fetchSSE('https://chatgpt.com/backend-api/conversation', { method: 'POST', signal: params.signal, headers: { diff --git a/src/background/providers/chatgpt_new.ts b/src/background/providers/chatgpt_new.ts index 208c193..249d95b 100644 --- a/src/background/providers/chatgpt_new.ts +++ b/src/background/providers/chatgpt_new.ts @@ -4,7 +4,7 @@ // import { GenerateAnswerParams, Provider } from '../types' // async function request(token: string, method: string, path: string, data?: unknown) { -// return fetch(`https://chat.openai.com/backend-api${path}`, { +// return fetch(`https://chatgpt.com/backend-api${path}`, { // method, // headers: { // 'Content-Type': 'application/json', @@ -34,7 +34,7 @@ // if (cache.get(KEY_ACCESS_TOKEN)) { // return cache.get(KEY_ACCESS_TOKEN) // } -// const resp = await fetch('https://chat.openai.com/api/auth/session') +// const resp = await fetch('https://chatgpt.com/api/auth/session') // if (resp.status === 403) { // throw new Error('CLOUDFLARE') // } @@ -80,7 +80,7 @@ // const modelName = await this.getModelName() // console.log('Using model:', modelName, params.conversationId, params.parentMessageId) -// await fetchSSE('https://chat.openai.com/backend-api/conversation', { +// await fetchSSE('https://chatgpt.com/backend-api/conversation', { // method: 'POST', // signal: params.signal, // headers: { diff --git a/src/content-script/ChatGPTQuery.tsx b/src/content-script/ChatGPTQuery.tsx index 6c9a0a5..cd1a22e 100644 --- a/src/content-script/ChatGPTQuery.tsx +++ b/src/content-script/ChatGPTQuery.tsx @@ -229,7 +229,7 @@ function ChatGPTQuery(props: Props) { return (

Please login and pass Cloudflare check at{' '} - + chat.openai.com {retry > 0 && diff --git a/src/manifest.json b/src/manifest.json index 4fe11b1..145c6f0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -10,7 +10,10 @@ "48": "logo.png", "128": "logo.png" }, - "host_permissions": ["https://*.openai.com/"], + "host_permissions": [ + "https://*.openai.com/", + "https://*.chatgpt.com/" + ], "permissions": [ "storage" ], "background": { "service_worker": "background.js" diff --git a/src/manifest.v2.json b/src/manifest.v2.json index c606b80..dec8afd 100644 --- a/src/manifest.v2.json +++ b/src/manifest.v2.json @@ -10,7 +10,11 @@ "48": "logo.png", "128": "logo.png" }, - "permissions": ["storage", "https://*.openai.com/"], + "permissions": [ + "storage", + "https://*.openai.com/", + "https://*.chatgpt.com/" + ], "background": { "scripts": ["background.js"] }, @@ -81,7 +85,7 @@ // }, // { // "matches": [ - // "https://chat.openai.com/*", + // "https://chatgpt.com/*", // "https://google.com/*" // ], // "resources": [ diff --git a/src/popup/App.tsx b/src/popup/App.tsx index b0f2f75..a889875 100644 --- a/src/popup/App.tsx +++ b/src/popup/App.tsx @@ -55,13 +55,13 @@ function App() { ) } if (accessTokenQuery.data) { - return