Commit 74a9b928 authored by Travis Fischer's avatar Travis Fischer

feat: allow for adding extra headers

parent f9fe5b5b
...@@ -55,6 +55,8 @@ export class ChatGPTAPI { ...@@ -55,6 +55,8 @@ export class ChatGPTAPI {
accessTokenTTL?: number accessTokenTTL?: number
accessToken?: string accessToken?: string
headers?: Record<string, string>
}) { }) {
const { const {
sessionToken, sessionToken,
...@@ -64,7 +66,8 @@ export class ChatGPTAPI { ...@@ -64,7 +66,8 @@ export class ChatGPTAPI {
backendApiBaseUrl = 'https://chat.openai.com/backend-api', backendApiBaseUrl = 'https://chat.openai.com/backend-api',
userAgent = USER_AGENT, userAgent = USER_AGENT,
accessTokenTTL = 60 * 60000, // 1 hour accessTokenTTL = 60 * 60000, // 1 hour
accessToken accessToken,
headers
} = opts } = opts
this._sessionToken = sessionToken this._sessionToken = sessionToken
...@@ -74,7 +77,7 @@ export class ChatGPTAPI { ...@@ -74,7 +77,7 @@ export class ChatGPTAPI {
this._backendApiBaseUrl = backendApiBaseUrl this._backendApiBaseUrl = backendApiBaseUrl
this._userAgent = userAgent this._userAgent = userAgent
this._headers = { this._headers = {
'User-Agent': this._userAgent, 'user-agent': this._userAgent,
'x-openai-assistant-app-id': '', 'x-openai-assistant-app-id': '',
'accept-language': 'en-US,en;q=0.9', 'accept-language': 'en-US,en;q=0.9',
origin: 'https://chat.openai.com', origin: 'https://chat.openai.com',
...@@ -84,7 +87,8 @@ export class ChatGPTAPI { ...@@ -84,7 +87,8 @@ export class ChatGPTAPI {
'sec-ch-ua-platform': '"macOS"', 'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty', 'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors', 'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin' 'sec-fetch-site': 'same-origin',
...headers
} }
this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL) this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment