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.32.0 #745

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.31.0"
".": "4.32.0"
}
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 4.32.0 (2024-04-01)

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

### Features

* **api:** add support for filtering messages by run_id ([#747](https://github.com/openai/openai-node/issues/747)) ([9a397ac](https://github.com/openai/openai-node/commit/9a397acffa9f10c3f48e86e3bdb3851770f87b42))
* **api:** run polling helpers ([#749](https://github.com/openai/openai-node/issues/749)) ([02920ae](https://github.com/openai/openai-node/commit/02920ae082480fc7a7ffe9fa583d053a40dc7120))


### Chores

* **deps:** remove unused dependency digest-fetch ([#748](https://github.com/openai/openai-node/issues/748)) ([5376837](https://github.com/openai/openai-node/commit/537683734d39dd956a7dcef4339c1167ce6fe13c))


### Documentation

* **readme:** change undocumented params wording ([#744](https://github.com/openai/openai-node/issues/744)) ([8796691](https://github.com/openai/openai-node/commit/87966911045275db86844dfdcde59653edaef264))


### Refactors

* rename createAndStream to stream ([02920ae](https://github.com/openai/openai-node/commit/02920ae082480fc7a7ffe9fa583d053a40dc7120))

## 4.31.0 (2024-03-30)

Full Changelog: [v4.30.0...v4.31.0](https://github.com/openai/openai-node/compare/v4.30.0...v4.31.0)
Expand Down
25 changes: 21 additions & 4 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.31.0/mod.ts';
import OpenAI from 'https://deno.land/x/openai@v4.32.0/mod.ts';
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -100,13 +100,30 @@ Documentation for each method, request param, and response field are available i
> [!IMPORTANT]
> Previous versions of this SDK used a `Configuration` class. See the [v3 to v4 migration guide](https://github.com/openai/openai-node/discussions/217).

### Polling Helpers

When interacting with the API some actions such as starting a Run may 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'.

For instance to create a Run and poll until it reaches a terminal state you can run:

```ts
const run = await openai.beta.threads.runs.createAndPoll(thread.id, {
assistant_id: assistantId,
});
```

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)

### Streaming Helpers

The SDK also includes helpers to process streams and handle the incoming events.

```ts
const run = openai.beta.threads.runs
.createAndStream(thread.id, {
.stream(thread.id, {
assistant_id: assistant.id,
})
.on('textCreated', (text) => process.stdout.write('\nassistant > '))
Expand Down Expand Up @@ -454,7 +471,7 @@ await client.post('/some/path', {
});
```

#### Undocumented params
#### Undocumented request params

To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
Expand All @@ -475,7 +492,7 @@ extra param in the body.
If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
options.

#### Undocumented properties
#### Undocumented response properties

To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
the response object, or cast the response object to the requisite type. Like the request params, we do not
Expand Down
5 changes: 5 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Methods:
- <code title="post /threads/{thread_id}">client.beta.threads.<a href="./src/resources/beta/threads/threads.ts">update</a>(threadId, { ...params }) -> Thread</code>
- <code title="delete /threads/{thread_id}">client.beta.threads.<a href="./src/resources/beta/threads/threads.ts">del</a>(threadId) -> ThreadDeleted</code>
- <code title="post /threads/runs">client.beta.threads.<a href="./src/resources/beta/threads/threads.ts">createAndRun</a>({ ...params }) -> Run</code>
- <code>client.beta.threads.<a href="./src/resources/beta/threads/threads.ts">createAndRunPoll</a>(body, options?) -> Promise&lt;Threads.Run&gt;</code>
- <code>client.beta.threads.<a href="./src/resources/beta/threads/threads.ts">createAndRunStream</a>(body, options?) -> AssistantStream</code>

### Runs
Expand All @@ -242,7 +243,11 @@ Methods:
- <code title="get /threads/{thread_id}/runs">client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">list</a>(threadId, { ...params }) -> RunsPage</code>
- <code title="post /threads/{thread_id}/runs/{run_id}/cancel">client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">cancel</a>(threadId, runId) -> Run</code>
- <code title="post /threads/{thread_id}/runs/{run_id}/submit_tool_outputs">client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">submitToolOutputs</a>(threadId, runId, { ...params }) -> Run</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">createAndPoll</a>(threadId, body, options?) -> Promise&lt;Run&gt;</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">createAndStream</a>(threadId, body, options?) -> AssistantStream</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">poll</a>(threadId, runId, options?) -> Promise&lt;Run&gt;</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">stream</a>(threadId, body, options?) -> AssistantStream</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">submitToolOutputsAndPoll</a>(threadId, runId, body, options?) -> Promise&lt;Run&gt;</code>
- <code>client.beta.threads.runs.<a href="./src/resources/beta/threads/runs/runs.ts">submitToolOutputsStream</a>(threadId, runId, body, options?) -> AssistantStream</code>

#### Steps
Expand Down
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.31.0/mod.ts";
import OpenAI from "https://deno.land/x/openai@v4.32.0/mod.ts";

const client = new OpenAI();
\`\`\`
Expand Down
Empty file modified examples/assistant-stream-raw.ts
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/assistant-stream.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {
console.log('Created thread with Id: ' + threadId);

const run = openai.beta.threads.runs
.createAndStream(threadId, {
.stream(threadId, {
assistant_id: assistantId,
})
//Subscribe to streaming events and log them
Expand Down
22 changes: 7 additions & 15 deletions examples/assistants.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env -S npm run tsn -T

import OpenAI from 'openai';
import { sleep } from 'openai/core';

/**
* Example of polling for a complete response from an assistant
Expand Down Expand Up @@ -32,24 +31,17 @@ async function main() {
let threadId = thread.id;
console.log('Created thread with Id: ' + threadId);

const run = await openai.beta.threads.runs.create(thread.id, {
const run = await openai.beta.threads.runs.createAndPoll(thread.id, {
assistant_id: assistantId,
additional_instructions: 'Please address the user as Jane Doe. The user has a premium account.',
});

console.log('Created run with Id: ' + run.id);

while (true) {
const result = await openai.beta.threads.runs.retrieve(thread.id, run.id);
if (result.status == 'completed') {
const messages = await openai.beta.threads.messages.list(thread.id);
for (const message of messages.getPaginatedItems()) {
console.log(message);
}
break;
} else {
console.log('Waiting for completion. Current status: ' + result.status);
await sleep(5000);
console.log('Run finished with status: ' + run.status);

if (run.status == 'completed') {
const messages = await openai.beta.threads.messages.list(thread.id);
for (const message of messages.getPaginatedItems()) {
console.log(message);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ More information can be found in the documentation: [Assistant Streaming](https:

```ts
const run = openai.beta.threads.runs
.createAndStream(thread.id, {
.stream(thread.id, {
assistant_id: assistant.id,
})
.on('textCreated', (text) => process.stdout.write('\nassistant > '))
Expand Down Expand Up @@ -41,7 +41,7 @@ const run = openai.beta.threads.runs
There are three helper methods for creating streams:

```ts
openai.beta.threads.runs.createAndStream();
openai.beta.threads.runs.stream();
```

This method can be used to start and stream the response to an existing run with an associated thread
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openai",
"version": "4.31.0",
"version": "4.32.0",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <support@openai.com>",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -29,7 +29,6 @@
"@types/node-fetch": "^2.6.4",
"abort-controller": "^3.0.0",
"agentkeepalive": "^4.2.1",
"digest-fetch": "^1.3.0",
"form-data-encoder": "1.7.2",
"formdata-node": "^4.3.2",
"node-fetch": "^2.6.7",
Expand Down
1 change: 1 addition & 0 deletions src/resources/beta/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export namespace Beta {
export import ThreadCreateAndRunParams = ThreadsAPI.ThreadCreateAndRunParams;
export import ThreadCreateAndRunParamsNonStreaming = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;
export import ThreadCreateAndRunParamsStreaming = ThreadsAPI.ThreadCreateAndRunParamsStreaming;
export import ThreadCreateAndRunPollParams = ThreadsAPI.ThreadCreateAndRunPollParams;
export import ThreadCreateAndRunStreamParams = ThreadsAPI.ThreadCreateAndRunStreamParams;
}
1 change: 1 addition & 0 deletions src/resources/beta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
ThreadCreateAndRunParams,
ThreadCreateAndRunParamsNonStreaming,
ThreadCreateAndRunParamsStreaming,
ThreadCreateAndRunPollParams,
ThreadCreateAndRunStreamParams,
Threads,
} from './threads/index';
4 changes: 4 additions & 0 deletions src/resources/beta/threads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ export {
RunCreateParamsStreaming,
RunUpdateParams,
RunListParams,
RunCreateAndPollParams,
RunCreateAndStreamParams,
RunStreamParams,
RunSubmitToolOutputsParams,
RunSubmitToolOutputsParamsNonStreaming,
RunSubmitToolOutputsParamsStreaming,
RunSubmitToolOutputsAndPollParams,
RunSubmitToolOutputsStreamParams,
RunsPage,
Runs,
Expand All @@ -52,6 +55,7 @@ export {
ThreadCreateAndRunParams,
ThreadCreateAndRunParamsNonStreaming,
ThreadCreateAndRunParamsStreaming,
ThreadCreateAndRunPollParams,
ThreadCreateAndRunStreamParams,
Threads,
} from './threads';
5 changes: 5 additions & 0 deletions src/resources/beta/threads/messages/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ export interface MessageListParams extends CursorPageParams {
* order and `desc` for descending order.
*/
order?: 'asc' | 'desc';

/**
* Filter messages by the run ID that generated them.
*/
run_id?: string;
}

export namespace Messages {
Expand Down
3 changes: 3 additions & 0 deletions src/resources/beta/threads/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ export {
RunCreateParamsStreaming,
RunUpdateParams,
RunListParams,
RunCreateAndPollParams,
RunCreateAndStreamParams,
RunStreamParams,
RunSubmitToolOutputsParams,
RunSubmitToolOutputsParamsNonStreaming,
RunSubmitToolOutputsParamsStreaming,
RunSubmitToolOutputsAndPollParams,
RunSubmitToolOutputsStreamParams,
RunsPage,
Runs,
Expand Down
Loading