Skip to content

Commit

Permalink
feat: support conversationID for ChatGPTAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
189 committed Mar 28, 2023
1 parent 9932fca commit fa53d86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/chatgpt-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class ChatGPTAPI {
*
* @param message - The prompt message to send
* @param opts.parentMessageId - Optional ID of the previous message in the conversation (defaults to `undefined`)
* @param opts.conversationId - Optional ID of the conversation (defaults to `undefined`)
* @param opts.messageId - Optional ID of the message to send (defaults to a random UUID)
* @param opts.systemMessage - Optional override for the chat "system message" which acts as instructions to the model (defaults to the ChatGPT system message)
* @param opts.timeoutMs - Optional timeout in milliseconds (defaults to no timeout)
Expand All @@ -139,7 +140,8 @@ export class ChatGPTAPI {
timeoutMs,
onProgress,
stream = onProgress ? true : false,
completionParams
completionParams,
conversationId = ''
} = opts

let { abortSignal } = opts
Expand All @@ -154,7 +156,8 @@ export class ChatGPTAPI {
role: 'user',
id: messageId,
parentMessageId,
text
text,
conversationId
}
await this._upsertMessage(message)

Expand All @@ -167,7 +170,8 @@ export class ChatGPTAPI {
role: 'assistant',
id: uuidv4(),
parentMessageId: messageId,
text: ''
text: '',
conversationId
}

const responseP = new Promise<types.ChatMessage>(
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type SendMessageOptions = {
/** The name of a user in a multi-user chat. */
name?: string
parentMessageId?: string
conversationId?: string
messageId?: string
stream?: boolean
systemMessage?: string
Expand Down

0 comments on commit fa53d86

Please sign in to comment.