17 KiB
chatgpt / Exports
chatgpt
Table of contents
Classes
Type Aliases
- AvailableModerationModels
- ChatError
- ChatResponse
- ContentType
- ConversationJSONBody
- ConversationResponseEvent
- Message
- MessageActionType
- MessageContent
- MessageFeedbackJSONBody
- MessageFeedbackRating
- MessageFeedbackResult
- MessageFeedbackTags
- MessageMetadata
- Model
- ModelsResult
- ModerationsJSONBody
- ModerationsJSONResult
- OpenAIAuth
- Prompt
- PromptContent
- Role
- SendConversationMessageOptions
- SendMessageOptions
- SessionResult
- User
Functions
- browserPostEventStream
- defaultChromeExecutablePath
- getBrowser
- getOpenAIAuth
- initializeNopechaExtension
- isRelevantRequest
- markdownToText
- maximizePage
- minimizePage
Type Aliases
AvailableModerationModels
Ƭ AvailableModerationModels: "text-moderation-playground"
Defined in
ChatError
Ƭ ChatError: Object
Type declaration
Name | Type |
---|---|
conversationId? |
string |
error |
{ message : string ; statusCode? : number ; statusText? : string } |
error.message |
string |
error.statusCode? |
number |
error.statusText? |
string |
messageId? |
string |
Defined in
ChatResponse
Ƭ ChatResponse: Object
Type declaration
Name | Type |
---|---|
conversationId |
string |
messageId |
string |
response |
string |
Defined in
ContentType
Ƭ ContentType: "text"
Defined in
ConversationJSONBody
Ƭ ConversationJSONBody: Object
https://chat.openapi.com/backend-api/conversation
Type declaration
Name | Type | Description |
---|---|---|
action |
string |
The action to take |
conversation_id? |
string |
The ID of the conversation |
messages |
Prompt [] |
Prompts to provide |
model |
string |
The model to use |
parent_message_id |
string |
The parent message ID |
Defined in
ConversationResponseEvent
Ƭ ConversationResponseEvent: Object
Type declaration
Name | Type |
---|---|
conversation_id? |
string |
error? |
string | null |
message? |
Message |
Defined in
Message
Ƭ Message: Object
Type declaration
Name | Type |
---|---|
content |
MessageContent |
create_time |
string | null |
end_turn |
null |
id |
string |
metadata |
MessageMetadata |
recipient |
string |
role |
string |
update_time |
string | null |
user |
string | null |
weight |
number |
Defined in
MessageActionType
Ƭ MessageActionType: "next"
| "variant"
Defined in
MessageContent
Ƭ MessageContent: Object
Type declaration
Name | Type |
---|---|
content_type |
string |
parts |
string [] |
Defined in
MessageFeedbackJSONBody
Ƭ MessageFeedbackJSONBody: Object
https://chat.openapi.com/backend-api/conversation/message_feedback
Type declaration
Name | Type | Description |
---|---|---|
conversation_id |
string |
The ID of the conversation |
message_id |
string |
The message ID |
rating |
MessageFeedbackRating |
The rating |
tags? |
MessageFeedbackTags [] |
Tags to give the rating |
text? |
string |
The text to include |
Defined in
MessageFeedbackRating
Ƭ MessageFeedbackRating: "thumbsUp"
| "thumbsDown"
Defined in
MessageFeedbackResult
Ƭ MessageFeedbackResult: Object
Type declaration
Name | Type | Description |
---|---|---|
conversation_id |
string |
The ID of the conversation |
message_id |
string |
The message ID |
rating |
MessageFeedbackRating |
The rating |
text? |
string |
The text the server received, including tags |
user_id |
string |
The ID of the user |
Defined in
MessageFeedbackTags
Ƭ MessageFeedbackTags: "harmful"
| "false"
| "not-helpful"
Defined in
MessageMetadata
Ƭ MessageMetadata: any
Defined in
Model
Ƭ Model: Object
Type declaration
Name | Type | Description |
---|---|---|
is_special |
boolean |
Whether or not the model is special |
max_tokens |
number |
Max tokens of the model |
slug |
string |
Name of the model |
Defined in
ModelsResult
Ƭ ModelsResult: Object
https://chat.openapi.com/backend-api/models
Type declaration
Name | Type | Description |
---|---|---|
models |
Model [] |
Array of models |
Defined in
ModerationsJSONBody
Ƭ ModerationsJSONBody: Object
https://chat.openapi.com/backend-api/moderations
Type declaration
Name | Type | Description |
---|---|---|
input |
string |
Input for the moderation decision |
model |
AvailableModerationModels |
The model to use in the decision |
Defined in
ModerationsJSONResult
Ƭ ModerationsJSONResult: Object
https://chat.openapi.com/backend-api/moderations
Type declaration
Name | Type | Description |
---|---|---|
blocked |
boolean |
Whether or not the input is blocked |
flagged |
boolean |
Whether or not the input is flagged |
moderation_id |
string |
The ID of the decision |
Defined in
OpenAIAuth
Ƭ OpenAIAuth: Object
Represents everything that's required to pass into ChatGPTAPI
in order
to authenticate with the unofficial ChatGPT API.
Type declaration
Name | Type |
---|---|
clearanceToken |
string |
cookies? |
Record <string , Protocol.Network.Cookie > |
sessionToken |
string |
userAgent |
string |
Defined in
Prompt
Ƭ Prompt: Object
Type declaration
Name | Type | Description |
---|---|---|
content |
PromptContent |
The content of the prompt |
id |
string |
The ID of the prompt |
role |
Role |
The role played in the prompt |
Defined in
PromptContent
Ƭ PromptContent: Object
Type declaration
Name | Type | Description |
---|---|---|
content_type |
ContentType |
The content type of the prompt |
parts |
string [] |
The parts to the prompt |
Defined in
Role
Ƭ Role: "user"
| "assistant"
Defined in
SendConversationMessageOptions
Ƭ SendConversationMessageOptions: Omit
<SendMessageOptions
, "conversationId"
| "parentMessageId"
>
Defined in
SendMessageOptions
Ƭ SendMessageOptions: Object
Type declaration
Name | Type |
---|---|
abortSignal? |
AbortSignal |
action? |
MessageActionType |
conversationId? |
string |
messageId? |
string |
onProgress? |
(partialResponse : ChatResponse ) => void |
parentMessageId? |
string |
timeoutMs? |
number |
Defined in
SessionResult
Ƭ SessionResult: Object
https://chat.openapi.com/api/auth/session
Type declaration
Name | Type | Description |
---|---|---|
accessToken |
string |
The access token |
error? |
string | null |
If there was an error associated with this request |
expires |
string |
ISO date of the expiration date of the access token |
user |
User |
Authenticated user |
Defined in
User
Ƭ User: Object
Type declaration
Name | Type | Description |
---|---|---|
email? |
string |
Email of the user |
features |
string [] |
Features the user is in |
groups |
string [] |
Groups the user is in |
id |
string |
ID of the user |
image |
string |
Image of the user |
name |
string |
Name of the user |
picture |
string |
Picture of the user |
Defined in
Functions
browserPostEventStream
▸ browserPostEventStream(url
, accessToken
, body
, timeoutMs?
): Promise
<ChatError
| ChatResponse
>
This function is injected into the ChatGPT webapp page using puppeteer. It has to be fully self-contained, so we copied a few third-party sources and included them in here.
Parameters
Name | Type |
---|---|
url |
string |
accessToken |
string |
body |
ConversationJSONBody |
timeoutMs? |
number |
Returns
Promise
<ChatError
| ChatResponse
>
Defined in
defaultChromeExecutablePath
▸ defaultChromeExecutablePath(): string
Gets the default path to chrome's executable for the current platform.
Returns
string
Defined in
getBrowser
▸ getBrowser(opts?
): Promise
<Browser
>
Launches a non-puppeteer instance of Chrome. Note that in my testing, I wasn't
able to use the built-in puppeteer
version of Chromium because Cloudflare
recognizes it and blocks access.
Parameters
Name | Type |
---|---|
opts |
PuppeteerLaunchOptions & { captchaToken? : string ; minimize? : boolean ; nopechaKey? : string ; proxyServer? : string ; timeoutMs? : number } |
Returns
Promise
<Browser
>
Defined in
getOpenAIAuth
▸ getOpenAIAuth(__namedParameters
): Promise
<OpenAIAuth
>
Bypasses OpenAI's use of Cloudflare to get the cookies required to use ChatGPT. Uses Puppeteer with a stealth plugin under the hood.
If you pass email
and password
, then it will log into the account and
include a sessionToken
in the response.
If you don't pass email
and password
, then it will just return a valid
clearanceToken
.
This can be useful because clearanceToken
expires after ~2 hours, whereas
sessionToken
generally lasts much longer. We recommend renewing your
clearanceToken
every hour or so and creating a new instance of ChatGPTAPI
with your updated credentials.
Parameters
Name | Type |
---|---|
__namedParameters |
Object |
__namedParameters.browser? |
Browser |
__namedParameters.captchaToken? |
string |
__namedParameters.email? |
string |
__namedParameters.executablePath? |
string |
__namedParameters.isGoogleLogin? |
boolean |
__namedParameters.isMicrosoftLogin? |
boolean |
__namedParameters.minimize? |
boolean |
__namedParameters.nopechaKey? |
string |
__namedParameters.page? |
Page |
__namedParameters.password? |
string |
__namedParameters.proxyServer? |
string |
__namedParameters.timeoutMs? |
number |
Returns
Promise
<OpenAIAuth
>
Defined in
initializeNopechaExtension
▸ initializeNopechaExtension(browser
, opts
): Promise
<void
>
Parameters
Name | Type |
---|---|
browser |
Browser |
opts |
Object |
opts.minimize? |
boolean |
opts.nopechaKey? |
string |
opts.timeoutMs? |
number |
Returns
Promise
<void
>
Defined in
isRelevantRequest
▸ isRelevantRequest(url
): boolean
Parameters
Name | Type |
---|---|
url |
string |
Returns
boolean
Defined in
markdownToText
▸ markdownToText(markdown?
): string
Parameters
Name | Type |
---|---|
markdown? |
string |
Returns
string
Defined in
maximizePage
▸ maximizePage(page
): Promise
<void
>
Parameters
Name | Type |
---|---|
page |
Page |
Returns
Promise
<void
>
Defined in
minimizePage
▸ minimizePage(page
): Promise
<void
>
Parameters
Name | Type |
---|---|
page |
Page |
Returns
Promise
<void
>