language-model-create-multimodal.tentative.https.window.js (2866B)
1 // META: title=Language Model Create Multimodal 2 // META: script=/resources/testdriver.js 3 // META: script=../resources/util.js 4 // META: timeout=long 5 6 'use strict'; 7 8 const kValidImagePath = '/images/computer.jpg'; 9 const kValidAudioPath = '/media/speech.wav'; 10 11 promise_test(async () => { 12 await ensureLanguageModel({expectedInputs: [{type: 'audio'}, {type: 'image'}]}); 13 const kSupportedCreateOptions = [ 14 { expectedInputs: [{type: 'audio'}] }, 15 { expectedInputs: [{type: 'image'}] }, 16 { expectedInputs: [{type: 'audio'}, {type: 'image'}, {type: 'text'}] }, 17 { expectedInputs: [{type: 'audio', languages: ['en']}] }, 18 { expectedInputs: [{type: 'image', languages: ['en']}] }, 19 { expectedInputs: [{type: 'audio', languages: ['en']}, 20 {type: 'image', languages: ['en']}, 21 {type: 'text', languages: ['en']}] }, 22 ]; 23 for (const options of kSupportedCreateOptions) { 24 assert_true(!!await createLanguageModel(options), JSON.stringify(options)); 25 } 26 }, 'LanguageModel.create() succeeds with supported multimodal type and language options'); 27 28 promise_test(async () => { 29 await ensureLanguageModel({expectedInputs: [{type: 'audio'}, {type: 'image'}]}); 30 const audioContent = { type:'audio', value: await (await fetch(kValidAudioPath)).blob() }; 31 const imageContent = { type:'image', value: await (await fetch(kValidImagePath)).blob() }; 32 const kSupportedCreateOptions = [ 33 { expectedInputs: [{type: 'audio'}], initialPrompts: [{role: 'user', content: [audioContent]}] }, 34 { expectedInputs: [{type: 'image'}], initialPrompts: [{role: 'user', content: [imageContent]}] }, 35 { expectedInputs: [{type: 'audio'}, {type: 'image'}], 36 initialPrompts: [{role: 'user', content: [audioContent, imageContent]}] }, 37 ]; 38 for (const options of kSupportedCreateOptions) { 39 // TODO(crbug.com/419599702): Ensure the model actually gets initialPrompts. 40 assert_true(!!await createLanguageModel(options), JSON.stringify(options)); 41 } 42 }, 'LanguageModel.create() succeeds with supported multimodal initialPrompts'); 43 44 promise_test(async t => { 45 await ensureLanguageModel({expectedInputs: [{type: 'audio'}, {type: 'image'}]}); 46 const audioContent = { type:'audio', value: await (await fetch(kValidAudioPath)).blob() }; 47 const imageContent = { type:'image', value: await (await fetch(kValidImagePath)).blob() }; 48 const kUnsupportedCreateOptions = [ 49 { expectedInputs: [{type: 'audio'}], initialPrompts: [{role: 'user', content: [imageContent]}] }, 50 { expectedInputs: [{type: 'image'}], initialPrompts: [{role: 'user', content: [audioContent]}] }, 51 ]; 52 for (const options of kUnsupportedCreateOptions) { 53 await promise_rejects_dom(t, 'NotSupportedError', createLanguageModel(options), JSON.stringify(options)); 54 } 55 }, 'LanguageModel.create() fails with unsupported multimodal initialPrompts');