File tree 2 files changed +41
-0
lines changed
packages/vertexai/src/methods 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,33 @@ describe('ChromeAdapter', () => {
153
153
} )
154
154
) . to . be . false ;
155
155
} ) ;
156
+ it ( 'returns true if request has image with supported mime type' , async ( ) => {
157
+ const adapter = new ChromeAdapter (
158
+ {
159
+ availability : async ( ) => Availability . available
160
+ } as LanguageModel ,
161
+ 'prefer_on_device'
162
+ ) ;
163
+ for ( const mimeType of ChromeAdapter . SUPPORTED_MIME_TYPES ) {
164
+ expect (
165
+ await adapter . isAvailable ( {
166
+ contents : [
167
+ {
168
+ role : 'user' ,
169
+ parts : [
170
+ {
171
+ inlineData : {
172
+ mimeType,
173
+ data : ''
174
+ }
175
+ }
176
+ ]
177
+ }
178
+ ]
179
+ } )
180
+ ) . to . be . true ;
181
+ }
182
+ } ) ;
156
183
it ( 'returns true if model is readily available' , async ( ) => {
157
184
const languageModelProvider = {
158
185
availability : ( ) => Promise . resolve ( Availability . available )
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ import {
35
35
* and encapsulates logic for detecting when on-device is possible.
36
36
*/
37
37
export class ChromeAdapter {
38
+ // Visible for testing
39
+ static SUPPORTED_MIME_TYPES = [ 'image/jpeg' , 'image/png' , 'image/webp' ] ;
38
40
private isDownloading = false ;
39
41
private downloadPromise : Promise < LanguageModel | void > | undefined ;
40
42
private oldSession : LanguageModel | undefined ;
@@ -142,6 +144,18 @@ export class ChromeAdapter {
142
144
if ( content . role !== 'user' ) {
143
145
return false ;
144
146
}
147
+
148
+ // Returns false if request contains an image with an unsupported mime type.
149
+ for ( const part of content . parts ) {
150
+ if (
151
+ part . inlineData &&
152
+ ChromeAdapter . SUPPORTED_MIME_TYPES . indexOf (
153
+ part . inlineData . mimeType
154
+ ) === - 1
155
+ ) {
156
+ return false ;
157
+ }
158
+ }
145
159
}
146
160
147
161
return true ;
You can’t perform that action at this time.
0 commit comments