@@ -27,7 +27,8 @@ const fakeVertexAI: VertexAI = {
2727 automaticDataCollectionEnabled : true ,
2828 options : {
2929 apiKey : 'key' ,
30- projectId : 'my-project'
30+ projectId : 'my-project' ,
31+ appId : 'my-appid'
3132 }
3233 } ,
3334 location : 'us-central1'
@@ -48,7 +49,7 @@ describe('Top level API', () => {
4849 it ( 'getGenerativeModel throws if no apiKey is provided' , ( ) => {
4950 const fakeVertexNoApiKey = {
5051 ...fakeVertexAI ,
51- app : { options : { projectId : 'my-project' } }
52+ app : { options : { projectId : 'my-project' , appId : 'my-appid' } }
5253 } as VertexAI ;
5354 try {
5455 getGenerativeModel ( fakeVertexNoApiKey , { model : 'my-model' } ) ;
@@ -64,7 +65,7 @@ describe('Top level API', () => {
6465 it ( 'getGenerativeModel throws if no projectId is provided' , ( ) => {
6566 const fakeVertexNoProject = {
6667 ...fakeVertexAI ,
67- app : { options : { apiKey : 'my-key' } }
68+ app : { options : { apiKey : 'my-key' , appId : 'my-appid' } }
6869 } as VertexAI ;
6970 try {
7071 getGenerativeModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
@@ -79,6 +80,24 @@ describe('Top level API', () => {
7980 ) ;
8081 }
8182 } ) ;
83+ it ( 'getGenerativeModel throws if no appId is provided' , ( ) => {
84+ const fakeVertexNoProject = {
85+ ...fakeVertexAI ,
86+ app : { options : { apiKey : 'my-key' , projectId : 'my-projectid' } }
87+ } as VertexAI ;
88+ try {
89+ getGenerativeModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
90+ } catch ( e ) {
91+ expect ( ( e as VertexAIError ) . code ) . includes (
92+ VertexAIErrorCode . NO_APP_ID
93+ ) ;
94+ expect ( ( e as VertexAIError ) . message ) . equals (
95+ `VertexAI: The "appId" field is empty in the local` +
96+ ` Firebase config. Firebase VertexAI requires this field ` +
97+ `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
98+ ) ;
99+ }
100+ } ) ;
82101 it ( 'getGenerativeModel gets a GenerativeModel' , ( ) => {
83102 const genModel = getGenerativeModel ( fakeVertexAI , { model : 'my-model' } ) ;
84103 expect ( genModel ) . to . be . an . instanceOf ( GenerativeModel ) ;
@@ -98,7 +117,7 @@ describe('Top level API', () => {
98117 it ( 'getImagenModel throws if no apiKey is provided' , ( ) => {
99118 const fakeVertexNoApiKey = {
100119 ...fakeVertexAI ,
101- app : { options : { projectId : 'my-project' } }
120+ app : { options : { projectId : 'my-project' , appId : 'my-appid' } }
102121 } as VertexAI ;
103122 try {
104123 getImagenModel ( fakeVertexNoApiKey , { model : 'my-model' } ) ;
@@ -114,7 +133,7 @@ describe('Top level API', () => {
114133 it ( 'getImagenModel throws if no projectId is provided' , ( ) => {
115134 const fakeVertexNoProject = {
116135 ...fakeVertexAI ,
117- app : { options : { apiKey : 'my-key' } }
136+ app : { options : { apiKey : 'my-key' , appId : 'my-appid' } }
118137 } as VertexAI ;
119138 try {
120139 getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
@@ -129,6 +148,24 @@ describe('Top level API', () => {
129148 ) ;
130149 }
131150 } ) ;
151+ it ( 'getImagenModel throws if no appId is provided' , ( ) => {
152+ const fakeVertexNoProject = {
153+ ...fakeVertexAI ,
154+ app : { options : { apiKey : 'my-key' , projectId : 'my-project' } }
155+ } as VertexAI ;
156+ try {
157+ getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
158+ } catch ( e ) {
159+ expect ( ( e as VertexAIError ) . code ) . includes (
160+ VertexAIErrorCode . NO_APP_ID
161+ ) ;
162+ expect ( ( e as VertexAIError ) . message ) . equals (
163+ `VertexAI: The "appId" field is empty in the local` +
164+ ` Firebase config. Firebase VertexAI requires this field ` +
165+ `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
166+ ) ;
167+ }
168+ } ) ;
132169 it ( 'getImagenModel gets an ImagenModel' , ( ) => {
133170 const genModel = getImagenModel ( fakeVertexAI , { model : 'my-model' } ) ;
134171 expect ( genModel ) . to . be . an . instanceOf ( ImagenModel ) ;
0 commit comments