From a27ad3d4e06f2202daa169668d0e7d89e87a38a7 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:40:13 -0500 Subject: [PATCH 1/2] fix: use default base url if BASE_URL env var is blank (#615) Previously, a blank BASE_URL environment variable would cause an invalid URL error. Now it uses the default. --- src/core.ts | 6 ++++-- src/index.ts | 2 +- tests/index.test.ts | 14 +++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core.ts b/src/core.ts index 9e3cb2b43..b5896a1e3 100644 --- a/src/core.ts +++ b/src/core.ts @@ -961,14 +961,16 @@ export const ensurePresent = (value: T | null | undefined): T => { /** * Read an environment variable. * + * Trims beginning and trailing whitespace. + * * Will return undefined if the environment variable doesn't exist or cannot be accessed. */ export const readEnv = (env: string): string | undefined => { if (typeof process !== 'undefined') { - return process.env?.[env] ?? undefined; + return process.env?.[env]?.trim() ?? undefined; } if (typeof Deno !== 'undefined') { - return Deno.env?.get?.(env); + return Deno.env?.get?.(env)?.trim(); } return undefined; }; diff --git a/src/index.ts b/src/index.ts index a03531dbe..265fb8f1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -118,7 +118,7 @@ export class OpenAI extends Core.APIClient { apiKey, organization, ...opts, - baseURL: baseURL ?? `https://api.openai.com/v1`, + baseURL: baseURL || `https://api.openai.com/v1`, }; if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) { diff --git a/tests/index.test.ts b/tests/index.test.ts index e056d3b85..6b386b04c 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -134,7 +134,7 @@ describe('instantiate client', () => { }); afterEach(() => { - process.env['SINK_BASE_URL'] = undefined; + process.env['OPENAI_BASE_URL'] = undefined; }); test('explicit option', () => { @@ -147,6 +147,18 @@ describe('instantiate client', () => { const client = new OpenAI({ apiKey: 'My API Key' }); expect(client.baseURL).toEqual('https://example.com/from_env'); }); + + test('empty env variable', () => { + process.env['OPENAI_BASE_URL'] = ''; // empty + const client = new OpenAI({ apiKey: 'My API Key' }); + expect(client.baseURL).toEqual('https://api.openai.com/v1'); + }); + + test('blank env variable', () => { + process.env['OPENAI_BASE_URL'] = ' '; // blank + const client = new OpenAI({ apiKey: 'My API Key' }); + expect(client.baseURL).toEqual('https://api.openai.com/v1'); + }); }); test('maxRetries option is correctly set', () => { From b49f48ccbafb54ac99ed5002fd1b230293b07b6d Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:40:38 -0500 Subject: [PATCH 2/2] release: 4.24.3 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ README.md | 2 +- build-deno | 2 +- package.json | 2 +- src/version.ts | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 52d941c80..0c1de9bc2 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.24.2" + ".": "4.24.3" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b83a93d..6633e9678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 4.24.3 (2024-01-10) + +Full Changelog: [v4.24.2...v4.24.3](https://github.com/openai/openai-node/compare/v4.24.2...v4.24.3) + +### Bug Fixes + +* use default base url if BASE_URL env var is blank ([#615](https://github.com/openai/openai-node/issues/615)) ([a27ad3d](https://github.com/openai/openai-node/commit/a27ad3d4e06f2202daa169668d0e7d89e87a38a7)) + ## 4.24.2 (2024-01-08) Full Changelog: [v4.24.1...v4.24.2](https://github.com/openai/openai-node/compare/v4.24.1...v4.24.2) diff --git a/README.md b/README.md index c538aa457..6b4148e48 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.2/mod.ts'; +import OpenAI from 'https://deno.land/x/openai@v4.24.3/mod.ts'; ``` diff --git a/build-deno b/build-deno index 60212c0ff..fa50476c4 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.2/mod.ts"; +import OpenAI from "https://deno.land/x/openai@v4.24.3/mod.ts"; const client = new OpenAI(); \`\`\` diff --git a/package.json b/package.json index 13038f6da..fd282473b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openai", - "version": "4.24.2", + "version": "4.24.3", "description": "The official TypeScript library for the OpenAI API", "author": "OpenAI ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index d2fe00e18..ebde6dd94 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '4.24.2'; // x-release-please-version +export const VERSION = '4.24.3'; // x-release-please-version