diff --git a/README.md b/README.md index 3928cbc..35c0018 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ await poll(openai, thread, run); ## API -### poll(openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, runId: OpenAI.Beta.Threads.Runs.Run): Promise +### poll(openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, runId: OpenAI.Beta.Threads.Runs.Run, options?: Partial): Promise #### openai @@ -53,14 +53,40 @@ Type: `OpenAI` Type: `OpenAI.Beta.Threads.Thread` -##### runId +#### runId Type: `OpenAI.Beta.Threads.Runs.Run` +##### (optional) options: PollOptions + +Type: `PollOptions` + +Default: + +``` +{ + maxAttempts: 60, + intervalInMilliseconds: 4000, + showLogs: false, +}; +``` + +You might pass only some of the parameters and they will be merged with defaults + #### returns Type: `Promise` +### PollOptions + +``` +export interface PollOptions { + maxAttempts: number; + intervalInMilliseconds: number; + showLogs: boolean; +} +``` + ## License MIT License diff --git a/lib/index.d.ts b/lib/index.d.ts index 5a5b8db..b62a073 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,13 +1,8 @@ import OpenAI from 'openai'; -export declare function poll( - openai: OpenAI, - thread: OpenAI.Beta.Threads.Thread, - run: OpenAI.Beta.Threads.Runs.Run, - options?: PollOptions -): Promise; +export declare function poll(openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, run: OpenAI.Beta.Threads.Runs.Run, options: Partial): Promise; export interface PollOptions { - maxAttempts: number; - intervalInMilliseconds: number; - showLogs: boolean; + maxAttempts: number; + intervalInMilliseconds: number; + showLogs: boolean; } export declare const defaultPollOptions: PollOptions; diff --git a/package.json b/package.json index e1f25eb..e2448a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tmlc/openai-polling", - "version": "0.0.2", + "version": "0.0.3", "description": "Polling library for OpenAI Threads API", "main": "./lib/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index c3c9228..d3d4fbd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ export async function poll( openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, run: OpenAI.Beta.Threads.Runs.Run, - options?: PollOptions + options: Partial ): Promise { const mergedOptions: PollOptions = { ...defaultPollOptions, ...options }; const maxAttempts = mergedOptions.maxAttempts;