Skip to content

Commit 0758a89

Browse files
Merge pull request transitive-bullshit#94 from yunyu950908/feat/assign-accessToken-on-initialization
2 parents 67fd5e1 + 37bf84b commit 0758a89

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/chatgpt-api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ export class ChatGPTAPI {
5252

5353
/** @defaultValue 60000 (60 seconds) */
5454
accessTokenTTL?: number
55+
56+
accessToken?: string
5557
}) {
5658
const {
5759
sessionToken,
5860
markdown = true,
5961
apiBaseUrl = 'https://chat.openai.com/api',
6062
backendApiBaseUrl = 'https://chat.openai.com/backend-api',
6163
userAgent = USER_AGENT,
62-
accessTokenTTL = 60000 // 60 seconds
64+
accessTokenTTL = 60000, // 60 seconds
65+
accessToken
6366
} = opts
6467

6568
this._sessionToken = sessionToken
@@ -76,6 +79,7 @@ export class ChatGPTAPI {
7679
}
7780

7881
this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL)
82+
this._accessTokenCache.set(KEY_ACCESS_TOKEN, accessToken ?? '')
7983

8084
if (!this._sessionToken) {
8185
throw new types.ChatGPTError('ChatGPT invalid session token')

0 commit comments

Comments
 (0)