From fa53d8606d1fa515f01324ce783ef5bed5369a2a Mon Sep 17 00:00:00 2001 From: wangshangwen Date: Tue, 28 Mar 2023 14:19:20 +0800 Subject: [PATCH] feat: support conversationID for ChatGPTAPI --- src/chatgpt-api.ts | 10 +++++++--- src/types.ts | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/chatgpt-api.ts b/src/chatgpt-api.ts index b44cce2d..d6ced412 100644 --- a/src/chatgpt-api.ts +++ b/src/chatgpt-api.ts @@ -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) @@ -139,7 +140,8 @@ export class ChatGPTAPI { timeoutMs, onProgress, stream = onProgress ? true : false, - completionParams + completionParams, + conversationId = '' } = opts let { abortSignal } = opts @@ -154,7 +156,8 @@ export class ChatGPTAPI { role: 'user', id: messageId, parentMessageId, - text + text, + conversationId } await this._upsertMessage(message) @@ -167,7 +170,8 @@ export class ChatGPTAPI { role: 'assistant', id: uuidv4(), parentMessageId: messageId, - text: '' + text: '', + conversationId } const responseP = new Promise( diff --git a/src/types.ts b/src/types.ts index fd23cf7b..c9eaf1b5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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