forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redesign main sendMessage, initSession, closeSession API
- Loading branch information
1 parent
24f51ac
commit 1af5db2
Showing
10 changed files
with
282 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as types from './types' | ||
|
||
export abstract class AChatGPTAPI { | ||
/** | ||
* Performs any async initialization work required to ensure that this API is | ||
* properly authenticated. | ||
* | ||
* @throws An error if the session failed to initialize properly. | ||
*/ | ||
abstract initSession(): Promise<void> | ||
|
||
/** | ||
* Sends a message to ChatGPT, waits for the response to resolve, and returns | ||
* the response. | ||
* | ||
* If you want to receive a stream of partial responses, use `opts.onProgress`. | ||
* | ||
* @param message - The prompt message to send | ||
* @param opts.conversationId - Optional ID of a conversation to continue | ||
* @param opts.parentMessageId - Optional ID of the previous message in the conversation | ||
* @param opts.messageId - Optional ID of the message to send (defaults to a random UUID) | ||
* @param opts.action - Optional ChatGPT `action` (either `next` or `variant`) | ||
* @param opts.timeoutMs - Optional timeout in milliseconds (defaults to no timeout) | ||
* @param opts.onProgress - Optional callback which will be invoked every time the partial response is updated | ||
* @param opts.abortSignal - Optional callback used to abort the underlying `fetch` call using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) | ||
* | ||
* @returns The response from ChatGPT, including `conversationId`, `messageId`, and | ||
* the `response` text. | ||
*/ | ||
abstract sendMessage( | ||
message: string, | ||
opts?: types.SendMessageOptions | ||
): Promise<types.ChatResponse> | ||
|
||
/** | ||
* @returns `true` if the client is authenticated with a valid session or `false` | ||
* otherwise. | ||
*/ | ||
abstract getIsAuthenticated(): Promise<boolean> | ||
|
||
/** | ||
* Refreshes the current ChatGPT session. | ||
* | ||
* @returns Access credentials for the new session. | ||
* @throws An error if it fails. | ||
*/ | ||
abstract refreshSession(): Promise<any> | ||
|
||
/** | ||
* Closes the current ChatGPT session and starts a new one. | ||
* | ||
* @returns Access credentials for the new session. | ||
* @throws An error if it fails. | ||
*/ | ||
async resetSession(): Promise<any> { | ||
await this.closeSession() | ||
return this.initSession() | ||
} | ||
|
||
/** | ||
* Closes the active session. | ||
* | ||
* @throws An error if it fails. | ||
*/ | ||
abstract closeSession(): Promise<void> | ||
} |
Oops, something went wrong.