Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 4.37.0 #777

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.36.0"
".": "4.37.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 55
configured_endpoints: 62
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 4.37.0 (2024-04-17)

Full Changelog: [v4.36.0...v4.37.0](https://github.com/openai/openai-node/compare/v4.36.0...v4.37.0)

### Features

* **api:** add vector stores ([#776](https://github.com/openai/openai-node/issues/776)) ([8bb929b](https://github.com/openai/openai-node/commit/8bb929b2ee91c1bec0a00347bf4f7628652d1be3))

## 4.36.0 (2024-04-16)

Full Changelog: [v4.35.0...v4.36.0](https://github.com/openai/openai-node/compare/v4.35.0...v4.36.0)
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can import in Deno via:
<!-- x-release-please-start-version -->

```ts
import OpenAI from 'https://deno.land/x/openai@v4.36.0/mod.ts';
import OpenAI from 'https://deno.land/x/openai@v4.37.0/mod.ts';
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -102,7 +102,7 @@ Documentation for each method, request param, and response field are available i

### Polling Helpers

When interacting with the API some actions such as starting a Run may take time to complete. The SDK includes
When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete. The SDK includes
helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
If an API method results in an action which could benefit from polling there will be a corresponding version of the
method ending in 'AndPoll'.
Expand All @@ -117,6 +117,20 @@ const run = await openai.beta.threads.runs.createAndPoll(thread.id, {

More information on the lifecycle of a Run can be found in the [Run Lifecycle Documentation](https://platform.openai.com/docs/assistants/how-it-works/run-lifecycle)

### Bulk Upload Helpers

When creating an interacting with vector stores, you can use the polling helpers to monitor the status of operations.
For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.

```ts
const fileList = [
createReadStream('/home/data/example.pdf'),
...
];

const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, fileList);
```

### Streaming Helpers

The SDK also includes helpers to process streams and handle the incoming events.
Expand Down
156 changes: 90 additions & 66 deletions api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build-deno
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is a build produced from https://github.com/openai/openai-node – please g
Usage:

\`\`\`ts
import OpenAI from "https://deno.land/x/openai@v4.36.0/mod.ts";
import OpenAI from "https://deno.land/x/openai@v4.37.0/mod.ts";

const client = new OpenAI();
\`\`\`
Expand Down
23 changes: 22 additions & 1 deletion helpers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Streaming Helpers
# Helpers

OpenAI supports streaming responses when interacting with the [Chat](#chat-streaming) or [Assistant](#assistant-streaming-api) APIs.

Expand Down Expand Up @@ -449,3 +449,24 @@ See an example of a Next.JS integration here [`examples/stream-to-client-next.ts
#### Proxy Streaming to a Browser

See an example of using express to stream to a browser here [`examples/stream-to-client-express.ts`](examples/stream-to-client-express.ts).

# Polling Helpers

When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete.
The SDK includes helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
If an API method results in an action which could benefit from polling there will be a corresponding version of the
method ending in `_AndPoll`.

All methods also allow you to set the polling frequency, how often the API is checked for an update, via a function argument (`pollIntervalMs`).

The polling methods are:

```ts
client.beta.threads.createAndRunPoll(...)
client.beta.threads.runs.createAndPoll((...)
client.beta.threads.runs.submitToolOutputsAndPoll((...)
client.beta.vectorStores.files.uploadAndPoll((...)
client.beta.vectorStores.files.createAndPoll((...)
client.beta.vectorStores.fileBatches.createAndPoll((...)
client.beta.vectorStores.fileBatches.uploadAndPoll((...)
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openai",
"version": "4.36.0",
"version": "4.37.0",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/AssistantStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ImageFile,
TextDelta,
Messages,
} from 'openai/resources/beta/threads/messages/messages';
} from 'openai/resources/beta/threads/messages';
import * as Core from 'openai/core';
import { RequestOptions } from 'openai/core';
import {
Expand All @@ -30,7 +30,7 @@ import {
MessageStreamEvent,
RunStepStreamEvent,
RunStreamEvent,
} from 'openai/resources/beta/assistants/assistants';
} from 'openai/resources/beta/assistants';
import { RunStep, RunStepDelta, ToolCall, ToolCallDelta } from 'openai/resources/beta/threads/runs/steps';
import { ThreadCreateAndRunParamsBase, Threads } from 'openai/resources/beta/threads/threads';
import MessageDelta = Messages.MessageDelta;
Expand Down
23 changes: 23 additions & 0 deletions src/lib/Util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Like `Promise.allSettled()` but throws an error if any promises are rejected.
*/
export const allSettledWithThrow = async <R>(promises: Promise<R>[]): Promise<R[]> => {
const results = await Promise.allSettled(promises);
const rejected = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');
if (rejected.length) {
for (const result of rejected) {
console.error(result.reason);
}

throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
}

// Note: TS was complaining about using `.filter().map()` here for some reason
const values: R[] = [];
for (const result of results) {
if (result.status === 'fulfilled') {
values.push(result.value);
}
}
return values;
};
Loading