diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8e73ce77a..f33e27aba 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.24.0" + ".": "4.24.1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f8d4d7e..73926f94c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index cbc41f199..bd32cd053 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ You can import in Deno via: ```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'; ``` @@ -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. + ```js import OpenAI from 'openai'; @@ -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: + ```ts import OpenAI from 'openai'; @@ -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: + ```ts async function main() { const fineTune = await openai.fineTunes @@ -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. + ```ts const openai = new OpenAI(); @@ -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"`: - ```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). diff --git a/build-deno b/build-deno index 6a0b059b9..37d62c7da 100755 --- a/build-deno +++ b/build-deno @@ -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(); \`\`\` diff --git a/helpers.md b/helpers.md index 859d45ab0..8b53e284e 100644 --- a/helpers.md +++ b/helpers.md @@ -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()`. diff --git a/jest.config.js b/jest.config.ts similarity index 69% rename from jest.config.js rename to jest.config.ts index 5fc957640..f746f4bf9 100644 --- a/jest.config.js +++ b/jest.config.ts @@ -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$': '/src/index.ts', @@ -14,3 +15,5 @@ module.exports = { '/deno_tests/', ], }; + +export default config; diff --git a/package.json b/package.json index 3b3d680f8..7a88ec1cf 100644 --- a/package.json +++ b/package.json @@ -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 ", "types": "dist/index.d.ts", diff --git a/src/pagination.ts b/src/pagination.ts index af6cd964e..5d890a140 100644 --- a/src/pagination.ts +++ b/src/pagination.ts @@ -5,7 +5,7 @@ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from export interface PageResponse { data: Array; - object: 'list'; + object: string; } /** @@ -14,17 +14,17 @@ export interface PageResponse { export class Page extends AbstractPage implements PageResponse { data: Array; - object: 'list'; + object: string; constructor(client: APIClient, response: Response, body: PageResponse, 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 @@ -46,14 +46,8 @@ export interface CursorPageResponse { } export interface CursorPageParams { - /** - * Identifier for the last job from the previous pagination request. - */ after?: string; - /** - * Number of fine-tuning jobs to retrieve. - */ limit?: number; } @@ -71,11 +65,11 @@ export class CursorPage ) { 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 @@ -89,12 +83,16 @@ export class CursorPage } 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 } }; } } diff --git a/src/version.ts b/src/version.ts index c46048091..0cd107b3c 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '4.24.0'; // x-release-please-version +export const VERSION = '4.24.1'; // x-release-please-version