@@ -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,22 @@ 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 ( VertexAIErrorCode . NO_APP_ID ) ;
92+ expect ( ( e as VertexAIError ) . message ) . equals (
93+ `VertexAI: The "appId" field is empty in the local` +
94+ ` Firebase config. Firebase VertexAI requires this field ` +
95+ `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
96+ ) ;
97+ }
98+ } ) ;
8299 it ( 'getGenerativeModel gets a GenerativeModel' , ( ) => {
83100 const genModel = getGenerativeModel ( fakeVertexAI , { model : 'my-model' } ) ;
84101 expect ( genModel ) . to . be . an . instanceOf ( GenerativeModel ) ;
@@ -98,7 +115,7 @@ describe('Top level API', () => {
98115 it ( 'getImagenModel throws if no apiKey is provided' , ( ) => {
99116 const fakeVertexNoApiKey = {
100117 ...fakeVertexAI ,
101- app : { options : { projectId : 'my-project' } }
118+ app : { options : { projectId : 'my-project' , appId : 'my-appid' } }
102119 } as VertexAI ;
103120 try {
104121 getImagenModel ( fakeVertexNoApiKey , { model : 'my-model' } ) ;
@@ -114,7 +131,7 @@ describe('Top level API', () => {
114131 it ( 'getImagenModel throws if no projectId is provided' , ( ) => {
115132 const fakeVertexNoProject = {
116133 ...fakeVertexAI ,
117- app : { options : { apiKey : 'my-key' } }
134+ app : { options : { apiKey : 'my-key' , appId : 'my-appid' } }
118135 } as VertexAI ;
119136 try {
120137 getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
@@ -129,6 +146,22 @@ describe('Top level API', () => {
129146 ) ;
130147 }
131148 } ) ;
149+ it ( 'getImagenModel throws if no appId is provided' , ( ) => {
150+ const fakeVertexNoProject = {
151+ ...fakeVertexAI ,
152+ app : { options : { apiKey : 'my-key' , projectId : 'my-project' } }
153+ } as VertexAI ;
154+ try {
155+ getImagenModel ( fakeVertexNoProject , { model : 'my-model' } ) ;
156+ } catch ( e ) {
157+ expect ( ( e as VertexAIError ) . code ) . includes ( VertexAIErrorCode . NO_APP_ID ) ;
158+ expect ( ( e as VertexAIError ) . message ) . equals (
159+ `VertexAI: The "appId" field is empty in the local` +
160+ ` Firebase config. Firebase VertexAI requires this field ` +
161+ `to contain a valid app ID. (vertexAI/${ VertexAIErrorCode . NO_APP_ID } )`
162+ ) ;
163+ }
164+ } ) ;
132165 it ( 'getImagenModel gets an ImagenModel' , ( ) => {
133166 const genModel = getImagenModel ( fakeVertexAI , { model : 'my-model' } ) ;
134167 expect ( genModel ) . to . be . an . instanceOf ( ImagenModel ) ;
0 commit comments