1616 */
1717import { ImagenModelParams , ModelParams , GenAIErrorCode } from './types' ;
1818import { GenAIError } from './errors' ;
19- import { ImagenModel , getGenerativeModel , getImagenModel } from './api' ;
19+ import { ImagenModel , getGenerativeModel , getImagenModel , vertexAIBackend } from './api' ;
2020import { expect } from 'chai' ;
21- import { VertexAI } from './public-types' ;
21+ import { GenAI } from './public-types' ;
2222import { GenerativeModel } from './models/generative-model' ;
2323
24- const fakeVertexAI : VertexAI = {
24+ const fakeGenAI : GenAI = {
2525 app : {
2626 name : 'DEFAULT' ,
2727 automaticDataCollectionEnabled : true ,
@@ -31,13 +31,14 @@ const fakeVertexAI: VertexAI = {
3131 appId : 'my-appid'
3232 }
3333 } ,
34+ backend : vertexAIBackend ( 'us-central1' ) ,
3435 location : 'us-central1'
3536} ;
3637
3738describe ( 'Top level API' , ( ) => {
3839 it ( 'getGenerativeModel throws if no model is provided' , ( ) => {
3940 try {
40- getGenerativeModel ( fakeVertexAI , { } as ModelParams ) ;
41+ getGenerativeModel ( fakeGenAI , { } as ModelParams ) ;
4142 } catch ( e ) {
4243 expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_MODEL ) ;
4344 expect ( ( e as GenAIError ) . message ) . includes (
@@ -48,9 +49,9 @@ describe('Top level API', () => {
4849 } ) ;
4950 it ( 'getGenerativeModel throws if no apiKey is provided' , ( ) => {
5051 const fakeVertexNoApiKey = {
51- ...fakeVertexAI ,
52+ ...fakeGenAI ,
5253 app : { options : { projectId : 'my-project' , appId : 'my-appid' } }
53- } as VertexAI ;
54+ } as GenAI ;
5455 try {
5556 getGenerativeModel ( fakeVertexNoApiKey , { model : 'my-model' } ) ;
5657 } catch ( e ) {
@@ -64,15 +65,13 @@ describe('Top level API', () => {
6465 } ) ;
6566 it ( 'getGenerativeModel throws if no projectId is provided' , ( ) => {
6667 const fakeVertexNoProject = {
67- ...fakeVertexAI ,
68+ ...fakeGenAI ,
6869 app : { options : { apiKey : 'my-key' , appId : 'my-appid' } }
69- } as VertexAI ;
70+ } as GenAI ;
7071 try {
7172 getGenerativeModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
7273 } catch ( e ) {
73- expect ( ( e as GenAIError ) . code ) . includes (
74- GenAIErrorCode . NO_PROJECT_ID
75- ) ;
74+ expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_PROJECT_ID ) ;
7675 expect ( ( e as GenAIError ) . message ) . equals (
7776 `VertexAI: The "projectId" field is empty in the local` +
7877 ` Firebase config. Firebase VertexAI requires this field ` +
@@ -82,28 +81,28 @@ describe('Top level API', () => {
8281 } ) ;
8382 it ( 'getGenerativeModel throws if no appId is provided' , ( ) => {
8483 const fakeVertexNoProject = {
85- ...fakeVertexAI ,
84+ ...fakeGenAI ,
8685 app : { options : { apiKey : 'my-key' , projectId : 'my-projectid' } }
87- } as VertexAI ;
86+ } as GenAI ;
8887 try {
8988 getGenerativeModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
9089 } catch ( e ) {
91- expect ( ( e as VertexAIError ) . code ) . includes ( VertexAIErrorCode . NO_APP_ID ) ;
92- expect ( ( e as VertexAIError ) . message ) . equals (
90+ expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_APP_ID ) ;
91+ expect ( ( e as GenAIError ) . message ) . equals (
9392 `VertexAI: The "appId" field is empty in the local` +
9493 ` Firebase config. Firebase VertexAI requires this field ` +
95- `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
94+ `to contain a valid app ID. (vertexAI/${ GenAIErrorCode . NO_APP_ID } )`
9695 ) ;
9796 }
9897 } ) ;
9998 it ( 'getGenerativeModel gets a GenerativeModel' , ( ) => {
100- const genModel = getGenerativeModel ( fakeVertexAI , { model : 'my-model' } ) ;
99+ const genModel = getGenerativeModel ( fakeGenAI , { model : 'my-model' } ) ;
101100 expect ( genModel ) . to . be . an . instanceOf ( GenerativeModel ) ;
102101 expect ( genModel . model ) . to . equal ( 'publishers/google/models/my-model' ) ;
103102 } ) ;
104103 it ( 'getImagenModel throws if no model is provided' , ( ) => {
105104 try {
106- getImagenModel ( fakeVertexAI , { } as ImagenModelParams ) ;
105+ getImagenModel ( fakeGenAI , { } as ImagenModelParams ) ;
107106 } catch ( e ) {
108107 expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_MODEL ) ;
109108 expect ( ( e as GenAIError ) . message ) . includes (
@@ -114,9 +113,9 @@ describe('Top level API', () => {
114113 } ) ;
115114 it ( 'getImagenModel throws if no apiKey is provided' , ( ) => {
116115 const fakeVertexNoApiKey = {
117- ...fakeVertexAI ,
116+ ...fakeGenAI ,
118117 app : { options : { projectId : 'my-project' , appId : 'my-appid' } }
119- } as VertexAI ;
118+ } as GenAI ;
120119 try {
121120 getImagenModel ( fakeVertexNoApiKey , { model : 'my-model' } ) ;
122121 } catch ( e ) {
@@ -130,15 +129,13 @@ describe('Top level API', () => {
130129 } ) ;
131130 it ( 'getImagenModel throws if no projectId is provided' , ( ) => {
132131 const fakeVertexNoProject = {
133- ...fakeVertexAI ,
132+ ...fakeGenAI ,
134133 app : { options : { apiKey : 'my-key' , appId : 'my-appid' } }
135- } as VertexAI ;
134+ } as GenAI ;
136135 try {
137136 getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
138137 } catch ( e ) {
139- expect ( ( e as GenAIError ) . code ) . includes (
140- GenAIErrorCode . NO_PROJECT_ID
141- ) ;
138+ expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_PROJECT_ID ) ;
142139 expect ( ( e as GenAIError ) . message ) . equals (
143140 `VertexAI: The "projectId" field is empty in the local` +
144141 ` Firebase config. Firebase VertexAI requires this field ` +
@@ -148,22 +145,22 @@ describe('Top level API', () => {
148145 } ) ;
149146 it ( 'getImagenModel throws if no appId is provided' , ( ) => {
150147 const fakeVertexNoProject = {
151- ...fakeVertexAI ,
148+ ...fakeGenAI ,
152149 app : { options : { apiKey : 'my-key' , projectId : 'my-project' } }
153- } as VertexAI ;
150+ } as GenAI ;
154151 try {
155152 getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
156153 } catch ( e ) {
157- expect ( ( e as VertexAIError ) . code ) . includes ( VertexAIErrorCode . NO_APP_ID ) ;
158- expect ( ( e as VertexAIError ) . message ) . equals (
154+ expect ( ( e as GenAIError ) . code ) . includes ( GenAIErrorCode . NO_APP_ID ) ;
155+ expect ( ( e as GenAIError ) . message ) . equals (
159156 `VertexAI: The "appId" field is empty in the local` +
160157 ` Firebase config. Firebase VertexAI requires this field ` +
161- `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
158+ `to contain a valid app ID. (vertexAI/${ GenAIErrorCode . NO_APP_ID } )`
162159 ) ;
163160 }
164161 } ) ;
165162 it ( 'getImagenModel gets an ImagenModel' , ( ) => {
166- const genModel = getImagenModel ( fakeVertexAI , { model : 'my-model' } ) ;
163+ const genModel = getImagenModel ( fakeGenAI , { model : 'my-model' } ) ;
167164 expect ( genModel ) . to . be . an . instanceOf ( ImagenModel ) ;
168165 expect ( genModel . model ) . to . equal ( 'publishers/google/models/my-model' ) ;
169166 } ) ;
0 commit comments