File tree 3 files changed +18
-4
lines changed
3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -961,14 +961,16 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
961
961
/**
962
962
* Read an environment variable.
963
963
*
964
+ * Trims beginning and trailing whitespace.
965
+ *
964
966
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
965
967
*/
966
968
export const readEnv = ( env : string ) : string | undefined => {
967
969
if ( typeof process !== 'undefined' ) {
968
- return process . env ?. [ env ] ?? undefined ;
970
+ return process . env ?. [ env ] ?. trim ( ) ?? undefined ;
969
971
}
970
972
if ( typeof Deno !== 'undefined' ) {
971
- return Deno . env ?. get ?.( env ) ;
973
+ return Deno . env ?. get ?.( env ) ?. trim ( ) ;
972
974
}
973
975
return undefined ;
974
976
} ;
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ export class OpenAI extends Core.APIClient {
118
118
apiKey,
119
119
organization,
120
120
...opts ,
121
- baseURL : baseURL ?? `https://api.openai.com/v1` ,
121
+ baseURL : baseURL || `https://api.openai.com/v1` ,
122
122
} ;
123
123
124
124
if ( ! options . dangerouslyAllowBrowser && Core . isRunningInBrowser ( ) ) {
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ describe('instantiate client', () => {
134
134
} ) ;
135
135
136
136
afterEach ( ( ) => {
137
- process . env [ 'SINK_BASE_URL ' ] = undefined ;
137
+ process . env [ 'OPENAI_BASE_URL ' ] = undefined ;
138
138
} ) ;
139
139
140
140
test ( 'explicit option' , ( ) => {
@@ -147,6 +147,18 @@ describe('instantiate client', () => {
147
147
const client = new OpenAI ( { apiKey : 'My API Key' } ) ;
148
148
expect ( client . baseURL ) . toEqual ( 'https://example.com/from_env' ) ;
149
149
} ) ;
150
+
151
+ test ( 'empty env variable' , ( ) => {
152
+ process . env [ 'OPENAI_BASE_URL' ] = '' ; // empty
153
+ const client = new OpenAI ( { apiKey : 'My API Key' } ) ;
154
+ expect ( client . baseURL ) . toEqual ( 'https://api.openai.com/v1' ) ;
155
+ } ) ;
156
+
157
+ test ( 'blank env variable' , ( ) => {
158
+ process . env [ 'OPENAI_BASE_URL' ] = ' ' ; // blank
159
+ const client = new OpenAI ( { apiKey : 'My API Key' } ) ;
160
+ expect ( client . baseURL ) . toEqual ( 'https://api.openai.com/v1' ) ;
161
+ } ) ;
150
162
} ) ;
151
163
152
164
test ( 'maxRetries option is correctly set' , ( ) => {
You can’t perform that action at this time.
0 commit comments