Skip to content

Commit

Permalink
chore: send complete cookie (#25, #112, #127, #150)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Apr 5, 2023
1 parent 8f274c1 commit b185337
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/background/apis/chatgpt-web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fetchSSE } from '../../utils/fetch-sse'
import { isEmpty } from 'lodash-es'
import { chatgptWebModelKeys, getUserConfig, Models } from '../../config/index.mjs'
import { pushRecord, setAbortController } from './shared.mjs'
import Browser from 'webextension-polyfill'

async function request(token, method, path, data) {
const apiUrl = (await getUserConfig()).customChatGptWebApiUrl
Expand Down Expand Up @@ -67,13 +68,20 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
models && models.includes(selectedModel) ? selectedModel : Models[chatgptWebModelKeys[0]].value
console.debug('usedModel', usedModel)

const cookie = (await Browser.cookies.getAll({ url: 'https://chat.openai.com/' }))
.map((cookie) => {
return `${cookie.name}=${cookie.value}`
})
.join('; ')

let answer = ''
await fetchSSE(`${config.customChatGptWebApiUrl}${config.customChatGptWebApiPath}`, {
method: 'POST',
signal: controller.signal,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
Cookie: cookie,
},
body: JSON.stringify({
action: 'next',
Expand Down

0 comments on commit b185337

Please sign in to comment.