@@ -22,6 +22,7 @@ namespace Firebase.Sample.VertexAI {
2222 using System . Net . Http ;
2323 using System . Threading . Tasks ;
2424 using Google . MiniJSON ;
25+ using UnityEngine ;
2526
2627 // An automated version of the UIHandler that runs tests on Vertex AI in Firebase.
2728 public class UIHandlerAutomated : UIHandler {
@@ -30,12 +31,16 @@ public class UIHandlerAutomated : UIHandler {
3031
3132 private Firebase . Sample . AutomatedTestRunner testRunner ;
3233
34+ // Texture used for tests involving images.
35+ public Texture2D RedBlueTexture ;
36+
3337 protected override void Start ( ) {
3438 // Set the list of tests to run, note this is done at Start since they are
3539 // non-static.
3640 Func < Task > [ ] tests = {
3741 TestCreateModel ,
3842 TestBasicText ,
43+ TestBasicImage ,
3944 TestModelOptions ,
4045 TestMultipleCandidates ,
4146 TestBasicTextStream ,
@@ -190,6 +195,33 @@ async Task TestBasicText() {
190195 }
191196 }
192197
198+ // Test if passing an Image and Text works.
199+ async Task TestBasicImage ( ) {
200+ var model = CreateGenerativeModel ( ) ;
201+
202+ Assert ( "Missing RedBlueTexture" , RedBlueTexture != null ) ;
203+
204+ byte [ ] imageData = ImageConversion . EncodeToPNG ( RedBlueTexture ) ;
205+ Assert ( "Image encoding failed" , imageData != null && imageData . Length > 0 ) ;
206+
207+ GenerateContentResponse response = await model . GenerateContentAsync (
208+ ModelContent . Text ( "I am testing Image input. What two colors do you see in the included image?" ) ,
209+ ModelContent . InlineData ( "image/png" , imageData )
210+ ) ;
211+
212+ Assert ( "Response missing candidates." , response . Candidates . Any ( ) ) ;
213+
214+ string result = response . Text ;
215+
216+ Assert ( "Response text was missing" , ! string . IsNullOrWhiteSpace ( result ) ) ;
217+ // We don't want to fail if the colors are missing/wrong because AI is unpredictable.
218+ if ( ! response . Text . Contains ( "red" , StringComparison . OrdinalIgnoreCase ) ||
219+ ! response . Text . Contains ( "blue" , StringComparison . OrdinalIgnoreCase ) ) {
220+ DebugLog ( "WARNING: Response string was missing the correct colors: " +
221+ $ "\n { result } ") ;
222+ }
223+ }
224+
193225 // Test if passing in multiple model options works.
194226 async Task TestModelOptions ( ) {
195227 // Note that most of these settings are hard to reliably verify, so as
0 commit comments