@@ -27,7 +27,7 @@ namespace Firebase.Sample.FirebaseAI {
2727 using System . Threading . Tasks ;
2828 using Google . MiniJSON ;
2929 using UnityEngine ;
30- using UnityEngine . Video ;
30+ using UnityEngine . Networking ;
3131 using System . IO ;
3232#if INCLUDE_FIREBASE_AUTH
3333 using Firebase . Auth ;
@@ -443,7 +443,7 @@ async Task TestEnumSchemaResponse(Backend backend) {
443443 generationConfig : new GenerationConfig (
444444 responseMimeType : "text/x.enum" ,
445445 responseSchema : Schema . Enum ( new string [ ] { enumValue } ) ) ) ;
446-
446+
447447 var response = await model . GenerateContentAsync (
448448 "Hello, I am testing setting the response schema to an enum." ) ;
449449
@@ -459,7 +459,7 @@ async Task TestAnyOfSchemaResponse(Backend backend) {
459459 Schema . AnyOf ( new [ ] { Schema . Int ( ) , Schema . String ( ) } ) ,
460460 minItems : 2 ,
461461 maxItems : 6 ) ) ) ;
462-
462+
463463 var response = await model . GenerateContentAsync (
464464 "Hello, I am testing setting the response schema with an array, cause you give me some random values." ) ;
465465
@@ -653,7 +653,7 @@ async Task TestYoutubeLink(Backend backend) {
653653 async Task TestGenerateImage ( Backend backend ) {
654654 var model = GetFirebaseAI ( backend ) . GetGenerativeModel ( "gemini-2.0-flash-exp" ,
655655 generationConfig : new GenerationConfig (
656- responseModalities : new [ ] { ResponseModality . Text , ResponseModality . Image } )
656+ responseModalities : new [ ] { ResponseModality . Text , ResponseModality . Image } )
657657 ) ;
658658
659659 GenerateContentResponse response = await model . GenerateContentAsync (
@@ -732,17 +732,40 @@ async Task TestReadSecureFile() {
732732
733733 // The url prefix to use when fetching test data to use from the separate GitHub repo.
734734 readonly string testDataUrl =
735- "https://raw.githubusercontent.com/FirebaseExtended/vertexai-sdk-test-data/3737ae1fe9c5ecbd55abdeabc273ef4f392cbf19 /mock-responses/" ;
735+ "https://raw.githubusercontent.com/FirebaseExtended/vertexai-sdk-test-data/47becf9101d11ea3c568bf60b12f1c8ed9fb684e /mock-responses/" ;
736736 readonly HttpClient httpClient = new ( ) ;
737737
738+ private Task < string > LoadStreamingAsset ( string fullPath ) {
739+ TaskCompletionSource < string > tcs = new TaskCompletionSource < string > ( ) ;
740+ UnityWebRequest request = UnityWebRequest . Get ( fullPath ) ;
741+ request . SendWebRequest ( ) . completed += ( _ ) => {
742+ if ( request . result == UnityWebRequest . Result . Success ) {
743+ tcs . SetResult ( request . downloadHandler . text ) ;
744+ } else {
745+ tcs . SetResult ( null ) ;
746+ }
747+ } ;
748+ return tcs . Task ;
749+ }
750+
738751 // Gets the Json test data from the given filename, potentially downloading from a GitHub repo.
739752 private async Task < Dictionary < string , object > > GetJsonTestData ( string filename ) {
740- // TODO: Check if the file is available locally first
753+ string jsonString = null ;
754+ // First, try to load the file from StreamingAssets
755+ string localPath = Path . Combine ( Application . streamingAssetsPath , "TestData" , filename ) ;
756+ if ( localPath . StartsWith ( "jar" ) || localPath . StartsWith ( "http" ) ) {
757+ // Special case to access StreamingAsset content on Android
758+ jsonString = await LoadStreamingAsset ( localPath ) ;
759+ } else if ( File . Exists ( localPath ) ) {
760+ jsonString = File . ReadAllText ( localPath ) ;
761+ }
741762
742- var response = await httpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Get , testDataUrl + filename ) ) ;
743- response . EnsureSuccessStatusCode ( ) ;
744-
745- string jsonString = await response . Content . ReadAsStringAsync ( ) ;
763+ if ( string . IsNullOrEmpty ( jsonString ) ) {
764+ var response = await httpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Get , testDataUrl + filename ) ) ;
765+ response . EnsureSuccessStatusCode ( ) ;
766+
767+ jsonString = await response . Content . ReadAsStringAsync ( ) ;
768+ }
746769
747770 return Json . Deserialize ( jsonString ) as Dictionary < string , object > ;
748771 }
@@ -857,7 +880,7 @@ async Task InternalTestBasicReplyShort() {
857880 async Task InternalTestCitations ( ) {
858881 Dictionary < string , object > json = await GetVertexJsonTestData ( "unary-success-citations.json" ) ;
859882 GenerateContentResponse response = GenerateContentResponse . FromJson ( json , FirebaseAI . Backend . InternalProvider . VertexAI ) ;
860-
883+
861884 ValidateTextPart ( response , "Some information cited from an external source" ) ;
862885
863886 CitationMetadata ? metadata = response . Candidates . First ( ) . CitationMetadata ;
@@ -1047,7 +1070,7 @@ async Task InternalTestBasicResponseLongUsageMetadata() {
10471070 // Test that parsing a basic short reply from Google AI endpoint works as expected.
10481071 // https://github.com/FirebaseExtended/vertexai-sdk-test-data/blob/main/mock-responses/googleai/unary-success-basic-reply-short.txt
10491072 async Task InternalTestGoogleAIBasicReplyShort ( ) {
1050- Dictionary < string , object > json = await GetGoogleAIJsonTestData ( "unary-success-basic-reply-short.txt " ) ; //
1073+ Dictionary < string , object > json = await GetGoogleAIJsonTestData ( "unary-success-basic-reply-short.json " ) ; //
10511074 GenerateContentResponse response = GenerateContentResponse . FromJson ( json , FirebaseAI . Backend . InternalProvider . GoogleAI ) ;
10521075
10531076 ValidateTextPart ( response , "Google's headquarters, also known as the Googleplex, is located in **Mountain View, California**.\n " ) ;
@@ -1073,12 +1096,12 @@ async Task InternalTestGoogleAIBasicReplyShort() {
10731096 // Test parsing a Google AI format response with citations.
10741097 // Based on: https://github.com/FirebaseExtended/vertexai-sdk-test-data/blob/main/mock-responses/googleai/unary-success-citations.txt
10751098 async Task InternalTestGoogleAICitations ( ) {
1076- Dictionary < string , object > json = await GetGoogleAIJsonTestData ( "unary-success-citations.txt " ) ;
1099+ Dictionary < string , object > json = await GetGoogleAIJsonTestData ( "unary-success-citations.json " ) ;
10771100 GenerateContentResponse response = GenerateContentResponse . FromJson ( json , FirebaseAI . Backend . InternalProvider . GoogleAI ) ;
10781101
10791102 // Validate Text Part (check start and end)
10801103 string expectedStart = "Okay, let's break down quantum mechanics." ;
1081- string expectedEnd = "foundation for many technologies, including: \n " ;
1104+ string expectedEnd = "area of physics! " ;
10821105 Assert ( "Candidate count" , response . Candidates . Count ( ) == 1 ) ;
10831106 Candidate candidate = response . Candidates . First ( ) ;
10841107 AssertEq ( "Content role" , candidate . Content . Role , "model" ) ;
0 commit comments