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.24.1 #589

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

## 4.24.1 (2023-12-22)

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

### Bug Fixes

* **pagination:** correct type annotation object field ([#590](https://github.com/openai/openai-node/issues/590)) ([4066eda](https://github.com/openai/openai-node/commit/4066edad4b5305e82e610f44f4720843f2b69d39))


### Documentation

* **messages:** improvements to helpers reference + typos ([#595](https://github.com/openai/openai-node/issues/595)) ([96a59b9](https://github.com/openai/openai-node/commit/96a59b91c424db67b8a5bdb7cab5da68c57282d4))
* reformat README.md ([#592](https://github.com/openai/openai-node/issues/592)) ([8ffc7f8](https://github.com/openai/openai-node/commit/8ffc7f876cc8f4b7afaf68a37f94f826ef22a6b8))


### Refactors

* write jest config in typescript ([#588](https://github.com/openai/openai-node/issues/588)) ([eb6ceeb](https://github.com/openai/openai-node/commit/eb6ceebf90ba45ec5b803f32b9b080829f6a973a))

## 4.24.0 (2023-12-19)

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

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

<!-- x-release-please-end -->
Expand All @@ -30,6 +30,7 @@ import OpenAI from 'https://deno.land/x/openai@v4.24.0/mod.ts';

The full API of this library can be found in [api.md file](api.md) along with many [code examples](https://github.com/openai/openai-node/tree/master/examples). The code below shows how to get started using the chat completions API.

<!-- prettier-ignore -->
```js
import OpenAI from 'openai';

Expand Down Expand Up @@ -77,6 +78,7 @@ or call `stream.controller.abort()`.

This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

<!-- prettier-ignore -->
```ts
import OpenAI from 'openai';

Expand Down Expand Up @@ -267,6 +269,7 @@ When the library is unable to connect to the API,
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
a subclass of `APIError` will be thrown:

<!-- prettier-ignore -->
```ts
async function main() {
const fineTune = await openai.fineTunes
Expand Down Expand Up @@ -388,6 +391,7 @@ The "raw" `Response` returned by `fetch()` can be accessed through the `.asRespo

You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.

<!-- prettier-ignore -->
```ts
const openai = new OpenAI();

Expand All @@ -412,12 +416,11 @@ If you would prefer to use a global, web-standards-compliant `fetch` function ev
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
add the following import before your first import `from "OpenAI"`:

<!-- prettier-ignore -->
```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import "openai/shims/web";
import OpenAI from "openai";
import 'openai/shims/web';
import OpenAI from 'openai';
```

To do the inverse, add `import "openai/shims/node"` (which does import polyfills).
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.24.0/mod.ts";
import OpenAI from "https://deno.land/x/openai@v4.24.1/mod.ts";

const client = new OpenAI();
\`\`\`
Expand Down
2 changes: 1 addition & 1 deletion helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ iterator, and exposes helper methods to accumulate chunks into a convenient shap
about the conversation.

Alternatively, you can use `openai.chat.completions.create({ stream: true, … })` which returns an async
iteratable of the chunks in the stream and uses less memory (most notably, it does not accumulate a final chat
iterable of the chunks in the stream and uses less memory (most notably, it does not accumulate a final chat
completion object for you).

If you need to cancel a stream, you can `break` from a `for await` loop or call `stream.abort()`.
Expand Down
9 changes: 6 additions & 3 deletions jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
import type { JestConfigWithTsJest } from 'ts-jest';

const config: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
moduleNameMapper: {
'^openai$': '<rootDir>/src/index.ts',
Expand All @@ -14,3 +15,5 @@ module.exports = {
'<rootDir>/deno_tests/',
],
};

export default config;
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.24.0",
"version": "4.24.1",
"description": "The official TypeScript library for the OpenAI API",
"author": "OpenAI <support@openai.com>",
"types": "dist/index.d.ts",
Expand Down
30 changes: 14 additions & 16 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from
export interface PageResponse<Item> {
data: Array<Item>;

object: 'list';
object: string;
}

/**
Expand All @@ -14,17 +14,17 @@ export interface PageResponse<Item> {
export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {
data: Array<Item>;

object: 'list';
object: string;

constructor(client: APIClient, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {
super(client, response, body, options);

this.data = body.data;
this.data = body.data || [];
this.object = body.object;
}

getPaginatedItems(): Item[] {
return this.data;
return this.data ?? [];
}

// @deprecated Please use `nextPageInfo()` instead
Expand All @@ -46,14 +46,8 @@ export interface CursorPageResponse<Item> {
}

export interface CursorPageParams {
/**
* Identifier for the last job from the previous pagination request.
*/
after?: string;

/**
* Number of fine-tuning jobs to retrieve.
*/
limit?: number;
}

Expand All @@ -71,11 +65,11 @@ export class CursorPage<Item extends { id: string }>
) {
super(client, response, body, options);

this.data = body.data;
this.data = body.data || [];
}

getPaginatedItems(): Item[] {
return this.data;
return this.data ?? [];
}

// @deprecated Please use `nextPageInfo()` instead
Expand All @@ -89,12 +83,16 @@ export class CursorPage<Item extends { id: string }>
}

nextPageInfo(): PageInfo | null {
if (!this.data?.length) {
const data = this.getPaginatedItems();
if (!data.length) {
return null;
}

const id = data[data.length - 1]?.id;
if (!id) {
return null;
}

const next = this.data[this.data.length - 1]?.id;
if (!next) return null;
return { params: { after: next } };
return { params: { after: id } };
}
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '4.24.0'; // x-release-please-version
export const VERSION = '4.24.1'; // x-release-please-version