diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc853348..c9b8f5c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v3 - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node with: node-version: ${{ matrix.node-version }} diff --git a/src/chatgpt-api.ts b/src/chatgpt-api.ts index 3d5ba277..b44cce2d 100644 --- a/src/chatgpt-api.ts +++ b/src/chatgpt-api.ts @@ -125,6 +125,7 @@ export class ChatGPTAPI { * @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) + * @param completionParams - Optional overrides to send to the [OpenAI chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant. * * @returns The response from ChatGPT */ @@ -137,7 +138,8 @@ export class ChatGPTAPI { messageId = uuidv4(), timeoutMs, onProgress, - stream = onProgress ? true : false + stream = onProgress ? true : false, + completionParams } = opts let { abortSignal } = opts @@ -178,6 +180,7 @@ export class ChatGPTAPI { const body = { max_tokens: maxTokens, ...this._completionParams, + ...completionParams, messages, stream } diff --git a/src/types.ts b/src/types.ts index f37223a4..fd23cf7b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,7 @@ export type ChatGPTAPIOptions = { debug?: boolean completionParams?: Partial< - Omit + Omit > systemMessage?: string @@ -42,6 +42,9 @@ export type SendMessageOptions = { timeoutMs?: number onProgress?: (partialResponse: ChatMessage) => void abortSignal?: AbortSignal + completionParams?: Partial< + Omit + > } export type MessageActionType = 'next' | 'variant'