@@ -56,8 +56,6 @@ export abstract class VertexAIModel {
5656 * @internal
5757 */
5858 protected constructor ( vertexAI : VertexAI , modelName : string ) {
59- this . model = VertexAIModel . normalizeModelName ( modelName ) ;
60-
6159 if ( ! vertexAI . app ?. options ?. apiKey ) {
6260 throw new VertexAIError (
6361 VertexAIErrorCode . NO_API_KEY ,
@@ -72,7 +70,8 @@ export abstract class VertexAIModel {
7270 this . _apiSettings = {
7371 apiKey : vertexAI . app . options . apiKey ,
7472 project : vertexAI . app . options . projectId ,
75- location : vertexAI . location
73+ location : vertexAI . location ,
74+ developerAPIEnabled : vertexAI . developerAPIEnabled
7675 } ;
7776
7877 if (
@@ -92,6 +91,11 @@ export abstract class VertexAIModel {
9291 this . _apiSettings . getAuthToken = ( ) =>
9392 ( vertexAI as VertexAIService ) . auth ! . getToken ( ) ;
9493 }
94+
95+ this . model = VertexAIModel . normalizeModelName (
96+ modelName ,
97+ this . _apiSettings . developerAPIEnabled
98+ ) ;
9599 }
96100 }
97101
@@ -101,19 +105,26 @@ export abstract class VertexAIModel {
101105 * @param modelName - The model name to normalize.
102106 * @returns The fully qualified model resource name.
103107 */
104- static normalizeModelName ( modelName : string ) : string {
108+ static normalizeModelName (
109+ modelName : string ,
110+ developerAPIEnabled ?: boolean
111+ ) : string {
105112 let model : string ;
106- if ( modelName . includes ( '/' ) ) {
107- if ( modelName . startsWith ( 'models/' ) ) {
108- // Add 'publishers/google' if the user is only passing in 'models/model-name'.
109- model = `publishers/google/${ modelName } ` ;
113+ if ( developerAPIEnabled ) {
114+ model = `models/${ modelName } ` ;
115+ } else {
116+ if ( modelName . includes ( '/' ) ) {
117+ if ( modelName . startsWith ( 'models/' ) ) {
118+ // Add 'publishers/google' if the user is only passing in 'models/model-name'.
119+ model = `publishers/google/${ modelName } ` ;
120+ } else {
121+ // Any other custom format (e.g. tuned models) must be passed in correctly.
122+ model = modelName ;
123+ }
110124 } else {
111- // Any other custom format (e.g. tuned models) must be passed in correctly .
112- model = modelName ;
125+ // If path is not included, assume it's a non-tuned model .
126+ model = `publishers/google/models/ ${ modelName } ` ;
113127 }
114- } else {
115- // If path is not included, assume it's a non-tuned model.
116- model = `publishers/google/models/${ modelName } ` ;
117128 }
118129
119130 return model ;
0 commit comments