Skip to content

Commit

Permalink
feat: partial PollOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaczan committed Feb 26, 2024
1 parent 56a6ab4 commit d6c9e83
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenAI.Beta.Threads.Runs.Run>
### poll(openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, runId: OpenAI.Beta.Threads.Runs.Run, options?: Partial<PollOptions>): Promise<OpenAI.Beta.Threads.Runs.Run>

#### openai

Expand All @@ -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<OpenAI.Beta.Threads.Runs.Run>`

### PollOptions

```
export interface PollOptions {
maxAttempts: number;
intervalInMilliseconds: number;
showLogs: boolean;
}
```

## License

MIT License
Expand Down
13 changes: 4 additions & 9 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<OpenAI.Beta.Threads.Runs.Run>;
export declare function poll(openai: OpenAI, thread: OpenAI.Beta.Threads.Thread, run: OpenAI.Beta.Threads.Runs.Run, options: Partial<PollOptions>): Promise<OpenAI.Beta.Threads.Runs.Run>;
export interface PollOptions {
maxAttempts: number;
intervalInMilliseconds: number;
showLogs: boolean;
maxAttempts: number;
intervalInMilliseconds: number;
showLogs: boolean;
}
export declare const defaultPollOptions: PollOptions;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PollOptions>
): Promise<OpenAI.Beta.Threads.Runs.Run> {
const mergedOptions: PollOptions = { ...defaultPollOptions, ...options };
const maxAttempts = mergedOptions.maxAttempts;
Expand Down

0 comments on commit d6c9e83

Please sign in to comment.