Commit 0758a89d authored by Travis Fischer's avatar Travis Fischer Committed by GitHub

Merge pull request #94 from yunyu950908/feat/assign-accessToken-on-initialization

parents 67fd5e16 37bf84bd
...@@ -52,6 +52,8 @@ export class ChatGPTAPI { ...@@ -52,6 +52,8 @@ export class ChatGPTAPI {
/** @defaultValue 60000 (60 seconds) */ /** @defaultValue 60000 (60 seconds) */
accessTokenTTL?: number accessTokenTTL?: number
accessToken?: string
}) { }) {
const { const {
sessionToken, sessionToken,
...@@ -59,7 +61,8 @@ export class ChatGPTAPI { ...@@ -59,7 +61,8 @@ export class ChatGPTAPI {
apiBaseUrl = 'https://chat.openai.com/api', apiBaseUrl = 'https://chat.openai.com/api',
backendApiBaseUrl = 'https://chat.openai.com/backend-api', backendApiBaseUrl = 'https://chat.openai.com/backend-api',
userAgent = USER_AGENT, userAgent = USER_AGENT,
accessTokenTTL = 60000 // 60 seconds accessTokenTTL = 60000, // 60 seconds
accessToken
} = opts } = opts
this._sessionToken = sessionToken this._sessionToken = sessionToken
...@@ -76,6 +79,7 @@ export class ChatGPTAPI { ...@@ -76,6 +79,7 @@ export class ChatGPTAPI {
} }
this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL) this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL)
this._accessTokenCache.set(KEY_ACCESS_TOKEN, accessToken ?? '')
if (!this._sessionToken) { if (!this._sessionToken) {
throw new types.ChatGPTError('ChatGPT invalid session token') throw new types.ChatGPTError('ChatGPT invalid session token')
......
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