@@ -270,6 +270,7 @@ export class GenerativeModel {
270
270
safety_settings ?: SafetySetting [ ] ;
271
271
private _vertex_instance : VertexAI_Internal ;
272
272
private _use_non_stream = false ;
273
+ private publisherModelEndpoint : string ;
273
274
274
275
/**
275
276
* @constructor
@@ -288,6 +289,11 @@ export class GenerativeModel {
288
289
this . model = model ;
289
290
this . generation_config = generation_config ;
290
291
this . safety_settings = safety_settings ;
292
+ if ( model . startsWith ( "models/" ) ) {
293
+ this . publisherModelEndpoint = `publishers/google/${ this . model } ` ;
294
+ } else {
295
+ this . publisherModelEndpoint = `publishers/google/models/${ this . model } ` ;
296
+ }
291
297
}
292
298
293
299
/**
@@ -314,8 +320,6 @@ export class GenerativeModel {
314
320
return Promise . resolve ( result ) ;
315
321
}
316
322
317
- const publisherModelEndpoint = `publishers/google/models/${ this . model } ` ;
318
-
319
323
const generateContentRequest : GenerateContentRequest = {
320
324
contents : request . contents ,
321
325
generation_config : request . generation_config ?? this . generation_config ,
@@ -327,7 +331,7 @@ export class GenerativeModel {
327
331
response = await postRequest ( {
328
332
region : this . _vertex_instance . location ,
329
333
project : this . _vertex_instance . project ,
330
- resourcePath : publisherModelEndpoint ,
334
+ resourcePath : this . publisherModelEndpoint ,
331
335
resourceMethod : constants . GENERATE_CONTENT_METHOD ,
332
336
token : await this . _vertex_instance . token ,
333
337
data : generateContentRequest ,
@@ -361,8 +365,6 @@ export class GenerativeModel {
361
365
validateGenerationConfig ( request . generation_config ) ;
362
366
}
363
367
364
- const publisherModelEndpoint = `publishers/google/models/${ this . model } ` ;
365
-
366
368
const generateContentRequest : GenerateContentRequest = {
367
369
contents : request . contents ,
368
370
generation_config : request . generation_config ?? this . generation_config ,
@@ -374,7 +376,7 @@ export class GenerativeModel {
374
376
response = await postRequest ( {
375
377
region : this . _vertex_instance . location ,
376
378
project : this . _vertex_instance . project ,
377
- resourcePath : publisherModelEndpoint ,
379
+ resourcePath : this . publisherModelEndpoint ,
378
380
resourceMethod : constants . STREAMING_GENERATE_CONTENT_METHOD ,
379
381
token : await this . _vertex_instance . token ,
380
382
data : generateContentRequest ,
@@ -405,7 +407,7 @@ export class GenerativeModel {
405
407
response = await postRequest ( {
406
408
region : this . _vertex_instance . location ,
407
409
project : this . _vertex_instance . project ,
408
- resourcePath : `publishers/google/models/ ${ this . model } ` ,
410
+ resourcePath : this . publisherModelEndpoint ,
409
411
resourceMethod : 'countTokens' ,
410
412
token : await this . _vertex_instance . token ,
411
413
data : request ,
0 commit comments