From fd2337b018ab2f31bcea8f9feda0ddaf755390c7 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:51:10 -0400 Subject: [PATCH 1/8] chore(internal): bump lock file (#334) --- yarn.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yarn.lock b/yarn.lock index d7a57abaa..a31198557 100644 --- a/yarn.lock +++ b/yarn.lock @@ -380,10 +380,10 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@eslint/js@8.49.0": - version "8.49.0" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.49.0.tgz#86f79756004a97fa4df866835093f1df3d03c333" - integrity sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w== +"@eslint/js@8.50.0": + version "8.50.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.50.0.tgz#9e93b850f0f3fa35f5fa59adfd03adae8488e484" + integrity sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ== "@glimmer/env@0.1.7": version "0.1.7" @@ -1721,14 +1721,14 @@ eslint-visitor-keys@^3.4.3: integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== eslint@^8.49.0: - version "8.49.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.49.0.tgz#09d80a89bdb4edee2efcf6964623af1054bf6d42" - integrity sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ== + version "8.50.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.50.0.tgz#2ae6015fee0240fcd3f83e1e25df0287f487d6b2" + integrity sha512-FOnOGSuFuFLv/Sa+FDVRZl4GGVAAFFi8LecRsI5a1tMO5HIE8nCm4ivAlzt4dT3ol/PaaGC0rJEEXQmHJBGoOg== dependencies: "@eslint-community/eslint-utils" "^4.2.0" "@eslint-community/regexpp" "^4.6.1" "@eslint/eslintrc" "^2.1.2" - "@eslint/js" "8.49.0" + "@eslint/js" "8.50.0" "@humanwhocodes/config-array" "^0.11.11" "@humanwhocodes/module-importer" "^1.0.1" "@nodelib/fs.walk" "^1.2.8" From 462bcda7140611afa20bc25de4aec6d4b205b37d Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:59:38 -0400 Subject: [PATCH 2/8] feat(package): export a root error type (#338) --- src/core.ts | 24 +++++++++++++++--------- src/error.ts | 4 +++- src/index.ts | 6 ++++-- src/streaming.ts | 9 +++++---- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/core.ts b/src/core.ts index a151d9d1a..4aa51a127 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,6 +1,12 @@ import { VERSION } from './version'; import { Stream } from './streaming'; -import { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError } from './error'; +import { + OpenAIError, + APIError, + APIConnectionError, + APIConnectionTimeoutError, + APIUserAbortError, +} from './error'; import { kind as shimsKind, type Readable, @@ -440,7 +446,7 @@ export abstract class APIClient { if (value === null) { return `${encodeURIComponent(key)}=`; } - throw new Error( + throw new OpenAIError( `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`, ); }) @@ -599,7 +605,7 @@ export abstract class AbstractPage implements AsyncIterable { async getNextPage(): Promise { const nextInfo = this.nextPageInfo(); if (!nextInfo) { - throw new Error( + throw new OpenAIError( 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.', ); } @@ -925,10 +931,10 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve const validatePositiveInteger = (name: string, n: unknown): number => { if (typeof n !== 'number' || !Number.isInteger(n)) { - throw new Error(`${name} must be an integer`); + throw new OpenAIError(`${name} must be an integer`); } if (n < 0) { - throw new Error(`${name} must be a positive integer`); + throw new OpenAIError(`${name} must be a positive integer`); } return n; }; @@ -939,7 +945,7 @@ export const castToError = (err: any): Error => { }; export const ensurePresent = (value: T | null | undefined): T => { - if (value == null) throw new Error(`Expected a value to be given but received ${value} instead.`); + if (value == null) throw new OpenAIError(`Expected a value to be given but received ${value} instead.`); return value; }; @@ -962,14 +968,14 @@ export const coerceInteger = (value: unknown): number => { if (typeof value === 'number') return Math.round(value); if (typeof value === 'string') return parseInt(value, 10); - throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`); + throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`); }; export const coerceFloat = (value: unknown): number => { if (typeof value === 'number') return value; if (typeof value === 'string') return parseFloat(value); - throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`); + throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`); }; export const coerceBoolean = (value: unknown): boolean => { @@ -1073,5 +1079,5 @@ export const toBase64 = (str: string | null | undefined): string => { return btoa(str); } - throw new Error('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined'); + throw new OpenAIError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined'); }; diff --git a/src/error.ts b/src/error.ts index 39f91b229..873087c78 100644 --- a/src/error.ts +++ b/src/error.ts @@ -2,7 +2,9 @@ import { castToError, Headers } from './core'; -export class APIError extends Error { +export class OpenAIError extends Error {} + +export class APIError extends OpenAIError { readonly status: number | undefined; readonly headers: Headers | undefined; readonly error: Object | undefined; diff --git a/src/index.ts b/src/index.ts index 2ecbb6546..c36f37379 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,7 +103,7 @@ export class OpenAI extends Core.APIClient { ...opts }: ClientOptions = {}) { if (apiKey === undefined) { - throw new Error( + throw new Errors.OpenAIError( "The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'my apiKey' }).", ); } @@ -116,7 +116,7 @@ export class OpenAI extends Core.APIClient { }; if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) { - throw new Error( + throw new Errors.OpenAIError( "It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n", ); } @@ -164,6 +164,7 @@ export class OpenAI extends Core.APIClient { static OpenAI = this; + static OpenAIError = Errors.OpenAIError; static APIError = Errors.APIError; static APIConnectionError = Errors.APIConnectionError; static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; @@ -179,6 +180,7 @@ export class OpenAI extends Core.APIClient { } export const { + OpenAIError, APIError, APIConnectionError, APIConnectionTimeoutError, diff --git a/src/streaming.ts b/src/streaming.ts index 21dedbb0f..6ce851282 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -1,4 +1,5 @@ import { type Response } from './_shims/index'; +import { OpenAIError } from './error'; type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; @@ -23,7 +24,7 @@ export class Stream implements AsyncIterable { private async *iterMessages(): AsyncGenerator { if (!this.response.body) { this.controller.abort(); - throw new Error(`Attempted to iterate over a response with no body`); + throw new OpenAIError(`Attempted to iterate over a response with no body`); } const lineDecoder = new LineDecoder(); @@ -198,7 +199,7 @@ class LineDecoder { return Buffer.from(bytes).toString(); } - throw new Error( + throw new OpenAIError( `Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`, ); } @@ -210,14 +211,14 @@ class LineDecoder { return this.textDecoder.decode(bytes); } - throw new Error( + throw new OpenAIError( `Unexpected: received non-Uint8Array/ArrayBuffer (${ (bytes as any).constructor.name }) in a web platform. Please report this error.`, ); } - throw new Error( + throw new OpenAIError( `Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`, ); } From 1bf84b672c386f8ca46bb8fc120eb8d8d48b3a82 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:59:24 -0400 Subject: [PATCH 3/8] chore(internal): update lock file (#339) --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a31198557..901ac9da1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -878,9 +878,9 @@ integrity sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw== "@types/semver@^7.5.0": - version "7.5.2" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.2.tgz#31f6eec1ed7ec23f4f05608d3a2d381df041f564" - integrity sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw== + version "7.5.3" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.3.tgz#9a726e116beb26c24f1ccd6850201e1246122e04" + integrity sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw== "@types/stack-utils@^2.0.0": version "2.0.1" From b6dd38488ea7cc4c22495f16d027b7ffdb87da53 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:22:30 -0400 Subject: [PATCH 4/8] feat(client): handle retry-after with a date (#340) --- src/core.ts | 43 ++++++++++++----------- yarn.lock | 98 ++++++++++++++++++++++++++--------------------------- 2 files changed, 73 insertions(+), 68 deletions(-) diff --git a/src/core.ts b/src/core.ts index 4aa51a127..a715f4507 100644 --- a/src/core.ts +++ b/src/core.ts @@ -509,32 +509,37 @@ export abstract class APIClient { retriesRemaining -= 1; // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After - // - // TODO: we may want to handle the case where the header is using the http-date syntax: "Retry-After: ". - // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#syntax for details. - const retryAfter = parseInt(responseHeaders?.['retry-after'] || ''); + let timeoutMillis: number | undefined; + const retryAfterHeader = responseHeaders?.['retry-after']; + if (retryAfterHeader) { + const timeoutSeconds = parseInt(retryAfterHeader); + if (!Number.isNaN(timeoutSeconds)) { + timeoutMillis = timeoutSeconds * 1000; + } else { + timeoutMillis = Date.parse(retryAfterHeader) - Date.now(); + } + } - const maxRetries = options.maxRetries ?? this.maxRetries; - const timeout = this.calculateRetryTimeoutSeconds(retriesRemaining, retryAfter, maxRetries) * 1000; - await sleep(timeout); + // If the API asks us to wait a certain amount of time (and it's a reasonable amount), + // just do what it says, but otherwise calculate a default + if ( + !timeoutMillis || + !Number.isInteger(timeoutMillis) || + timeoutMillis <= 0 || + timeoutMillis > 60 * 1000 + ) { + const maxRetries = options.maxRetries ?? this.maxRetries; + timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries); + } + await sleep(timeoutMillis); return this.makeRequest(options, retriesRemaining); } - private calculateRetryTimeoutSeconds( - retriesRemaining: number, - retryAfter: number, - maxRetries: number, - ): number { + private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number { const initialRetryDelay = 0.5; const maxRetryDelay = 2; - // If the API asks us to wait a certain amount of time (and it's a reasonable amount), - // just do what it says. - if (Number.isInteger(retryAfter) && retryAfter <= 60) { - return retryAfter; - } - const numRetries = maxRetries - retriesRemaining; // Apply exponential backoff, but not more than the max. @@ -543,7 +548,7 @@ export abstract class APIClient { // Apply some jitter, plus-or-minus half a second. const jitter = Math.random() - 0.5; - return sleepSeconds + jitter; + return (sleepSeconds + jitter) * 1000; } private getUserAgent(): string { diff --git a/yarn.lock b/yarn.lock index 901ac9da1..c02ef2b4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -905,15 +905,15 @@ "@types/yargs-parser" "*" "@typescript-eslint/eslint-plugin@^6.7.0": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.2.tgz#f18cc75c9cceac8080a9dc2e7d166008c5207b9f" - integrity sha512-ooaHxlmSgZTM6CHYAFRlifqh1OAr3PAQEwi7lhYhaegbnXrnh7CDcHmc3+ihhbQC7H0i4JF0psI5ehzkF6Yl6Q== + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.3.tgz#d98046e9f7102d49a93d944d413c6055c47fafd7" + integrity sha512-vntq452UHNltxsaaN+L9WyuMch8bMd9CqJ3zhzTPXXidwbf5mqqKCVXEuvRZUqLJSTLeWE65lQwyXsRGnXkCTA== dependencies: "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "6.7.2" - "@typescript-eslint/type-utils" "6.7.2" - "@typescript-eslint/utils" "6.7.2" - "@typescript-eslint/visitor-keys" "6.7.2" + "@typescript-eslint/scope-manager" "6.7.3" + "@typescript-eslint/type-utils" "6.7.3" + "@typescript-eslint/utils" "6.7.3" + "@typescript-eslint/visitor-keys" "6.7.3" debug "^4.3.4" graphemer "^1.4.0" ignore "^5.2.4" @@ -922,31 +922,31 @@ ts-api-utils "^1.0.1" "@typescript-eslint/parser@^6.7.0": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.7.2.tgz#e0ae93771441b9518e67d0660c79e3a105497af4" - integrity sha512-KA3E4ox0ws+SPyxQf9iSI25R6b4Ne78ORhNHeVKrPQnoYsb9UhieoiRoJgrzgEeKGOXhcY1i8YtOeCHHTDa6Fw== - dependencies: - "@typescript-eslint/scope-manager" "6.7.2" - "@typescript-eslint/types" "6.7.2" - "@typescript-eslint/typescript-estree" "6.7.2" - "@typescript-eslint/visitor-keys" "6.7.2" + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.7.3.tgz#aaf40092a32877439e5957e18f2d6a91c82cc2fd" + integrity sha512-TlutE+iep2o7R8Lf+yoer3zU6/0EAUc8QIBB3GYBc1KGz4c4TRm83xwXUZVPlZ6YCLss4r77jbu6j3sendJoiQ== + dependencies: + "@typescript-eslint/scope-manager" "6.7.3" + "@typescript-eslint/types" "6.7.3" + "@typescript-eslint/typescript-estree" "6.7.3" + "@typescript-eslint/visitor-keys" "6.7.3" debug "^4.3.4" -"@typescript-eslint/scope-manager@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.7.2.tgz#cf59a2095d2f894770c94be489648ad1c78dc689" - integrity sha512-bgi6plgyZjEqapr7u2mhxGR6E8WCzKNUFWNh6fkpVe9+yzRZeYtDTbsIBzKbcxI+r1qVWt6VIoMSNZ4r2A+6Yw== +"@typescript-eslint/scope-manager@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.7.3.tgz#07e5709c9bdae3eaf216947433ef97b3b8b7d755" + integrity sha512-wOlo0QnEou9cHO2TdkJmzF7DFGvAKEnB82PuPNHpT8ZKKaZu6Bm63ugOTn9fXNJtvuDPanBc78lGUGGytJoVzQ== dependencies: - "@typescript-eslint/types" "6.7.2" - "@typescript-eslint/visitor-keys" "6.7.2" + "@typescript-eslint/types" "6.7.3" + "@typescript-eslint/visitor-keys" "6.7.3" -"@typescript-eslint/type-utils@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.7.2.tgz#ed921c9db87d72fa2939fee242d700561454f367" - integrity sha512-36F4fOYIROYRl0qj95dYKx6kybddLtsbmPIYNK0OBeXv2j9L5nZ17j9jmfy+bIDHKQgn2EZX+cofsqi8NPATBQ== +"@typescript-eslint/type-utils@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.7.3.tgz#c2c165c135dda68a5e70074ade183f5ad68f3400" + integrity sha512-Fc68K0aTDrKIBvLnKTZ5Pf3MXK495YErrbHb1R6aTpfK5OdSFj0rVN7ib6Tx6ePrZ2gsjLqr0s98NG7l96KSQw== dependencies: - "@typescript-eslint/typescript-estree" "6.7.2" - "@typescript-eslint/utils" "6.7.2" + "@typescript-eslint/typescript-estree" "6.7.3" + "@typescript-eslint/utils" "6.7.3" debug "^4.3.4" ts-api-utils "^1.0.1" @@ -955,10 +955,10 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.45.0.tgz#794760b9037ee4154c09549ef5a96599621109c5" integrity sha512-QQij+u/vgskA66azc9dCmx+rev79PzX8uDHpsqSjEFtfF2gBUTRCpvYMh2gw2ghkJabNkPlSUCimsyBEQZd1DA== -"@typescript-eslint/types@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.7.2.tgz#75a615a6dbeca09cafd102fe7f465da1d8a3c066" - integrity sha512-flJYwMYgnUNDAN9/GAI3l8+wTmvTYdv64fcH8aoJK76Y+1FCZ08RtI5zDerM/FYT5DMkAc+19E4aLmd5KqdFyg== +"@typescript-eslint/types@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.7.3.tgz#0402b5628a63f24f2dc9d4a678e9a92cc50ea3e9" + integrity sha512-4g+de6roB2NFcfkZb439tigpAMnvEIg3rIjWQ+EM7IBaYt/CdJt6em9BJ4h4UpdgaBWdmx2iWsafHTrqmgIPNw== "@typescript-eslint/typescript-estree@5.45.0": version "5.45.0" @@ -973,30 +973,30 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.2.tgz#ce5883c23b581a5caf878af641e49dd0349238c7" - integrity sha512-kiJKVMLkoSciGyFU0TOY0fRxnp9qq1AzVOHNeN1+B9erKFCJ4Z8WdjAkKQPP+b1pWStGFqezMLltxO+308dJTQ== +"@typescript-eslint/typescript-estree@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.3.tgz#ec5bb7ab4d3566818abaf0e4a8fa1958561b7279" + integrity sha512-YLQ3tJoS4VxLFYHTw21oe1/vIZPRqAO91z6Uv0Ss2BKm/Ag7/RVQBcXTGcXhgJMdA4U+HrKuY5gWlJlvoaKZ5g== dependencies: - "@typescript-eslint/types" "6.7.2" - "@typescript-eslint/visitor-keys" "6.7.2" + "@typescript-eslint/types" "6.7.3" + "@typescript-eslint/visitor-keys" "6.7.3" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/utils@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.7.2.tgz#b9ef0da6f04932167a9222cb4ac59cb187165ebf" - integrity sha512-ZCcBJug/TS6fXRTsoTkgnsvyWSiXwMNiPzBUani7hDidBdj1779qwM1FIAmpH4lvlOZNF3EScsxxuGifjpLSWQ== +"@typescript-eslint/utils@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.7.3.tgz#96c655816c373135b07282d67407cb577f62e143" + integrity sha512-vzLkVder21GpWRrmSR9JxGZ5+ibIUSudXlW52qeKpzUEQhRSmyZiVDDj3crAth7+5tmN1ulvgKaCU2f/bPRCzg== dependencies: "@eslint-community/eslint-utils" "^4.4.0" "@types/json-schema" "^7.0.12" "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "6.7.2" - "@typescript-eslint/types" "6.7.2" - "@typescript-eslint/typescript-estree" "6.7.2" + "@typescript-eslint/scope-manager" "6.7.3" + "@typescript-eslint/types" "6.7.3" + "@typescript-eslint/typescript-estree" "6.7.3" semver "^7.5.4" "@typescript-eslint/visitor-keys@5.45.0": @@ -1007,12 +1007,12 @@ "@typescript-eslint/types" "5.45.0" eslint-visitor-keys "^3.3.0" -"@typescript-eslint/visitor-keys@6.7.2": - version "6.7.2" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.2.tgz#4cb2bd786f1f459731b0ad1584c9f73e1c7a4d5c" - integrity sha512-uVw9VIMFBUTz8rIeaUT3fFe8xIUx8r4ywAdlQv1ifH+6acn/XF8Y6rwJ7XNmkNMDrTW+7+vxFFPIF40nJCVsMQ== +"@typescript-eslint/visitor-keys@6.7.3": + version "6.7.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.3.tgz#83809631ca12909bd2083558d2f93f5747deebb2" + integrity sha512-HEVXkU9IB+nk9o63CeICMHxFWbHWr3E1mpilIQBe9+7L/lH97rleFLVtYsfnWB+JVMaiFnEaxvknvmIzX+CqVg== dependencies: - "@typescript-eslint/types" "6.7.2" + "@typescript-eslint/types" "6.7.3" eslint-visitor-keys "^3.4.1" abort-controller@^3.0.0: From 0001f062728b0e2047d2bf03b9d947a4be0c7206 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:04:58 -0400 Subject: [PATCH 5/8] chore(internal): update lock file (#342) --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index c02ef2b4e..31af2fa43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -356,9 +356,9 @@ eslint-visitor-keys "^3.3.0" "@eslint-community/regexpp@^4.5.1": - version "4.8.1" - resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.8.1.tgz#8c4bb756cc2aa7eaf13cfa5e69c83afb3260c20c" - integrity sha512-PWiOzLIUAjN/w5K17PoF4n6sKBw0gqLHPhywmYHP4t1VFQQVYeb1yWsJwnMVEMl3tUHME7X/SJPZLmtG7XBDxQ== + version "4.8.2" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.8.2.tgz#26585b7c0ba36362893d3a3c206ee0c57c389616" + integrity sha512-0MGxAVt1m/ZK+LTJp/j0qF7Hz97D9O/FH9Ms3ltnyIdDD57cbb1ACIQTkbHvNXtWDv5TPq7w5Kq56+cNukbo7g== "@eslint-community/regexpp@^4.6.1": version "4.6.2" From a02ac8e7f881551527a3cbcadad53b7e424650e8 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 27 Sep 2023 05:44:52 +0100 Subject: [PATCH 6/8] chore(internal): update lock file (#343) --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 31af2fa43..fb2b9a2c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -356,9 +356,9 @@ eslint-visitor-keys "^3.3.0" "@eslint-community/regexpp@^4.5.1": - version "4.8.2" - resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.8.2.tgz#26585b7c0ba36362893d3a3c206ee0c57c389616" - integrity sha512-0MGxAVt1m/ZK+LTJp/j0qF7Hz97D9O/FH9Ms3ltnyIdDD57cbb1ACIQTkbHvNXtWDv5TPq7w5Kq56+cNukbo7g== + version "4.9.0" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.9.0.tgz#7ccb5f58703fa61ffdcbf39e2c604a109e781162" + integrity sha512-zJmuCWj2VLBt4c25CfBIbMZLGLyhkvs7LznyVX5HfpzeocThgIj5XQK4L+g3U36mMcx8bPMhGyPpwCATamC4jQ== "@eslint-community/regexpp@^4.6.1": version "4.6.2" From f10c757d831d90407ba47b4659d9cd34b1a35b1d Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:27:37 +0100 Subject: [PATCH 7/8] fix(api): add content_filter to chat completion finish reason (#344) --- src/resources/chat/completions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/chat/completions.ts b/src/resources/chat/completions.ts index 18338c669..b72b595d2 100644 --- a/src/resources/chat/completions.ts +++ b/src/resources/chat/completions.ts @@ -139,7 +139,7 @@ export namespace ChatCompletionChunk { * content was omitted due to a flag from our content filters, or `function_call` * if the model called a function. */ - finish_reason: 'stop' | 'length' | 'function_call' | null; + finish_reason: 'stop' | 'length' | 'function_call' | 'content_filter' | null; /** * The index of the choice in the list of choices. From 3e28dcf90d25f89f9e706090b4b5b81b098d9925 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Fri, 29 Sep 2023 09:27:56 +0100 Subject: [PATCH 8/8] release: 4.11.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 22 ++++++++++++++++++++++ package.json | 2 +- src/version.ts | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 7a2c6223d..58acdf5b1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.10.0" + ".": "4.11.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index edf69aa6a..5b7f19589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## 4.11.0 (2023-09-29) + +Full Changelog: [v4.10.0...v4.11.0](https://github.com/openai/openai-node/compare/v4.10.0...v4.11.0) + +### Features + +* **client:** handle retry-after with a date ([#340](https://github.com/openai/openai-node/issues/340)) ([b6dd384](https://github.com/openai/openai-node/commit/b6dd38488ea7cc4c22495f16d027b7ffdb87da53)) +* **package:** export a root error type ([#338](https://github.com/openai/openai-node/issues/338)) ([462bcda](https://github.com/openai/openai-node/commit/462bcda7140611afa20bc25de4aec6d4b205b37d)) + + +### Bug Fixes + +* **api:** add content_filter to chat completion finish reason ([#344](https://github.com/openai/openai-node/issues/344)) ([f10c757](https://github.com/openai/openai-node/commit/f10c757d831d90407ba47b4659d9cd34b1a35b1d)) + + +### Chores + +* **internal:** bump lock file ([#334](https://github.com/openai/openai-node/issues/334)) ([fd2337b](https://github.com/openai/openai-node/commit/fd2337b018ab2f31bcea8f9feda0ddaf755390c7)) +* **internal:** update lock file ([#339](https://github.com/openai/openai-node/issues/339)) ([1bf84b6](https://github.com/openai/openai-node/commit/1bf84b672c386f8ca46bb8fc120eb8d8d48b3a82)) +* **internal:** update lock file ([#342](https://github.com/openai/openai-node/issues/342)) ([0001f06](https://github.com/openai/openai-node/commit/0001f062728b0e2047d2bf03b9d947a4be0c7206)) +* **internal:** update lock file ([#343](https://github.com/openai/openai-node/issues/343)) ([a02ac8e](https://github.com/openai/openai-node/commit/a02ac8e7f881551527a3cbcadad53b7e424650e8)) + ## 4.10.0 (2023-09-21) Full Changelog: [v4.9.1...v4.10.0](https://github.com/openai/openai-node/compare/v4.9.1...v4.10.0) diff --git a/package.json b/package.json index df892786a..0087741fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openai", - "version": "4.10.0", + "version": "4.11.0", "description": "Client library for the OpenAI API", "author": "OpenAI ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index 37e598a80..ac2d33f18 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '4.10.0'; // x-release-please-version +export const VERSION = '4.11.0'; // x-release-please-version