@@ -5,7 +5,6 @@ import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestIni
55import { uuid4 } from './internal/utils/uuid' ;
66import { validatePositiveInteger , isAbsoluteURL , safeJSON } from './internal/utils/values' ;
77import { sleep } from './internal/utils/sleep' ;
8- import { type Logger , type LogLevel , parseLogLevel } from './internal/utils/log' ;
98export type { Logger , LogLevel } from './internal/utils/log' ;
109import { castToError , isAbortError } from './internal/errors' ;
1110import type { APIResponseProps } from './internal/parse' ;
@@ -17,14 +16,8 @@ import * as Errors from './core/error';
1716import * as Uploads from './core/uploads' ;
1817import * as API from './resources/index' ;
1918import { APIPromise } from './core/api-promise' ;
20- import { type Fetch } from './internal/builtin-types' ;
21- import { HeadersLike , NullableHeaders , buildHeaders } from './internal/headers' ;
22- import { FinalRequestOptions , RequestOptions } from './internal/request-options' ;
2319import { LlamaModel , ModelListResponse , Models } from './resources/models' ;
2420import { ModerationCreateParams , ModerationCreateResponse , Moderations } from './resources/moderations' ;
25- import { readEnv } from './internal/utils/env' ;
26- import { formatRequestDetails , loggerFor } from './internal/utils/log' ;
27- import { isEmptyObj } from './internal/utils/values' ;
2821import {
2922 Chat ,
3023 CompletionMessage ,
@@ -38,6 +31,18 @@ import {
3831 ToolResponseMessage ,
3932 UserMessage ,
4033} from './resources/chat/chat' ;
34+ import { type Fetch } from './internal/builtin-types' ;
35+ import { HeadersLike , NullableHeaders , buildHeaders } from './internal/headers' ;
36+ import { FinalRequestOptions , RequestOptions } from './internal/request-options' ;
37+ import { readEnv } from './internal/utils/env' ;
38+ import {
39+ type LogLevel ,
40+ type Logger ,
41+ formatRequestDetails ,
42+ loggerFor ,
43+ parseLogLevel ,
44+ } from './internal/utils/log' ;
45+ import { isEmptyObj } from './internal/utils/values' ;
4146
4247export interface ClientOptions {
4348 /**
@@ -190,12 +195,20 @@ export class LlamaAPIClient {
190195 timeout : this . timeout ,
191196 logger : this . logger ,
192197 logLevel : this . logLevel ,
198+ fetch : this . fetch ,
193199 fetchOptions : this . fetchOptions ,
194200 apiKey : this . apiKey ,
195201 ...options ,
196202 } ) ;
197203 }
198204
205+ /**
206+ * Check whether the base URL is set to its default.
207+ */
208+ #baseURLOverridden( ) : boolean {
209+ return this . baseURL !== 'https://api.llama.com/v1' ;
210+ }
211+
199212 protected defaultQuery ( ) : Record < string , string | undefined > | undefined {
200213 return this . _options . defaultQuery ;
201214 }
@@ -245,11 +258,16 @@ export class LlamaAPIClient {
245258 return Errors . APIError . generate ( status , error , message , headers ) ;
246259 }
247260
248- buildURL ( path : string , query : Record < string , unknown > | null | undefined ) : string {
261+ buildURL (
262+ path : string ,
263+ query : Record < string , unknown > | null | undefined ,
264+ defaultBaseURL ?: string | undefined ,
265+ ) : string {
266+ const baseURL = ( ! this . #baseURLOverridden( ) && defaultBaseURL ) || this . baseURL ;
249267 const url =
250268 isAbsoluteURL ( path ) ?
251269 new URL ( path )
252- : new URL ( this . baseURL + ( this . baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
270+ : new URL ( baseURL + ( baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
253271
254272 const defaultQuery = this . defaultQuery ( ) ;
255273 if ( ! isEmptyObj ( defaultQuery ) ) {
@@ -590,9 +608,9 @@ export class LlamaAPIClient {
590608 { retryCount = 0 } : { retryCount ?: number } = { } ,
591609 ) : { req : FinalizedRequestInit ; url : string ; timeout : number } {
592610 const options = { ...inputOptions } ;
593- const { method, path, query } = options ;
611+ const { method, path, query, defaultBaseURL } = options ;
594612
595- const url = this . buildURL ( path ! , query as Record < string , unknown > ) ;
613+ const url = this . buildURL ( path ! , query as Record < string , unknown > , defaultBaseURL ) ;
596614 if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
597615 options . timeout = options . timeout ?? this . timeout ;
598616 const { bodyHeaders, body } = this . buildBody ( { options } ) ;
0 commit comments