1616
1717using System ;
1818using System . Collections . Generic ;
19- using System . Collections . ObjectModel ;
2019using System . Linq ;
2120using Google . MiniJSON ;
2221using Firebase . AI . Internal ;
@@ -27,14 +26,14 @@ namespace Firebase.AI {
2726/// The model's response to a generate content request.
2827/// </summary>
2928public readonly struct GenerateContentResponse {
30- private readonly ReadOnlyCollection < Candidate > _candidates ;
29+ private readonly IReadOnlyList < Candidate > _candidates ;
3130
3231 /// <summary>
3332 /// A list of candidate response content, ordered from best to worst.
3433 /// </summary>
35- public IEnumerable < Candidate > Candidates {
34+ public IReadOnlyList < Candidate > Candidates {
3635 get {
37- return _candidates ?? new ReadOnlyCollection < Candidate > ( new List < Candidate > ( ) ) ;
36+ return _candidates ?? new List < Candidate > ( ) ;
3837 }
3938 }
4039
@@ -64,16 +63,16 @@ public string Text {
6463 /// <summary>
6564 /// Returns function calls found in any `Part`s of the first candidate of the response, if any.
6665 /// </summary>
67- public IEnumerable < ModelContent . FunctionCallPart > FunctionCalls {
66+ public IReadOnlyList < ModelContent . FunctionCallPart > FunctionCalls {
6867 get {
69- return Candidates . FirstOrDefault ( ) . Content . Parts . OfType < ModelContent . FunctionCallPart > ( ) ;
68+ return Candidates . FirstOrDefault ( ) . Content . Parts . OfType < ModelContent . FunctionCallPart > ( ) . ToList ( ) ;
7069 }
7170 }
7271
7372 // Hidden constructor, users don't need to make this.
7473 private GenerateContentResponse ( List < Candidate > candidates , PromptFeedback ? promptFeedback ,
7574 UsageMetadata ? usageMetadata ) {
76- _candidates = new ReadOnlyCollection < Candidate > ( candidates ?? new List < Candidate > ( ) ) ;
75+ _candidates = candidates ;
7776 PromptFeedback = promptFeedback ;
7877 UsageMetadata = usageMetadata ;
7978 }
@@ -132,7 +131,7 @@ public enum BlockReason {
132131/// A metadata struct containing any feedback the model had on the prompt it was provided.
133132/// </summary>
134133public readonly struct PromptFeedback {
135- private readonly ReadOnlyCollection < SafetyRating > _safetyRatings ;
134+ private readonly IReadOnlyList < SafetyRating > _safetyRatings ;
136135
137136 /// <summary>
138137 /// The reason a prompt was blocked, if it was blocked.
@@ -145,9 +144,9 @@ public readonly struct PromptFeedback {
145144 /// <summary>
146145 /// The safety ratings of the prompt.
147146 /// </summary>
148- public IEnumerable < SafetyRating > SafetyRatings {
147+ public IReadOnlyList < SafetyRating > SafetyRatings {
149148 get {
150- return _safetyRatings ?? new ReadOnlyCollection < SafetyRating > ( new List < SafetyRating > ( ) ) ;
149+ return _safetyRatings ?? new List < SafetyRating > ( ) ;
151150 }
152151 }
153152
@@ -156,7 +155,7 @@ private PromptFeedback(BlockReason? blockReason, string blockReasonMessage,
156155 List < SafetyRating > safetyRatings ) {
157156 BlockReason = blockReason ;
158157 BlockReasonMessage = blockReasonMessage ;
159- _safetyRatings = new ReadOnlyCollection < SafetyRating > ( safetyRatings ?? new List < SafetyRating > ( ) ) ;
158+ _safetyRatings = safetyRatings ;
160159 }
161160
162161 private static BlockReason ParseBlockReason ( string str ) {
@@ -191,37 +190,37 @@ internal static PromptFeedback FromJson(Dictionary<string, object> jsonDict) {
191190/// section within the Service Specific Terms).
192191/// </summary>
193192public readonly struct GroundingMetadata {
194- private readonly ReadOnlyCollection < string > _webSearchQueries ;
195- private readonly ReadOnlyCollection < GroundingChunk > _groundingChunks ;
196- private readonly ReadOnlyCollection < GroundingSupport > _groundingSupports ;
193+ private readonly IReadOnlyList < string > _webSearchQueries ;
194+ private readonly IReadOnlyList < GroundingChunk > _groundingChunks ;
195+ private readonly IReadOnlyList < GroundingSupport > _groundingSupports ;
197196
198197 /// <summary>
199198 /// A list of web search queries that the model performed to gather the grounding information.
200199 /// These can be used to allow users to explore the search results themselves.
201200 /// </summary>
202- public IEnumerable < string > WebSearchQueries {
201+ public IReadOnlyList < string > WebSearchQueries {
203202 get {
204- return _webSearchQueries ?? new ReadOnlyCollection < string > ( new List < string > ( ) ) ;
203+ return _webSearchQueries ?? new List < string > ( ) ;
205204 }
206205 }
207206
208207 /// <summary>
209208 /// A list of `GroundingChunk` structs. Each chunk represents a piece of retrieved content
210209 /// (e.g., from a web page) that the model used to ground its response.
211210 /// </summary>
212- public IEnumerable < GroundingChunk > GroundingChunks {
211+ public IReadOnlyList < GroundingChunk > GroundingChunks {
213212 get {
214- return _groundingChunks ?? new ReadOnlyCollection < GroundingChunk > ( new List < GroundingChunk > ( ) ) ;
213+ return _groundingChunks ?? new List < GroundingChunk > ( ) ;
215214 }
216215 }
217216
218217 /// <summary>
219218 /// A list of `GroundingSupport` structs. Each object details how specific segments of the
220219 /// model's response are supported by the `groundingChunks`.
221220 /// </summary>
222- public IEnumerable < GroundingSupport > GroundingSupports {
221+ public IReadOnlyList < GroundingSupport > GroundingSupports {
223222 get {
224- return _groundingSupports ?? new ReadOnlyCollection < GroundingSupport > ( new List < GroundingSupport > ( ) ) ;
223+ return _groundingSupports ?? new List < GroundingSupport > ( ) ;
225224 }
226225 }
227226
@@ -234,9 +233,9 @@ public IEnumerable<GroundingSupport> GroundingSupports {
234233
235234 private GroundingMetadata ( List < string > webSearchQueries , List < GroundingChunk > groundingChunks ,
236235 List < GroundingSupport > groundingSupports , SearchEntryPoint ? searchEntryPoint ) {
237- _webSearchQueries = new ReadOnlyCollection < string > ( webSearchQueries ?? new List < string > ( ) ) ;
238- _groundingChunks = new ReadOnlyCollection < GroundingChunk > ( groundingChunks ?? new List < GroundingChunk > ( ) ) ;
239- _groundingSupports = new ReadOnlyCollection < GroundingSupport > ( groundingSupports ?? new List < GroundingSupport > ( ) ) ;
236+ _webSearchQueries = webSearchQueries ;
237+ _groundingChunks = groundingChunks ;
238+ _groundingSupports = groundingSupports ;
240239 SearchEntryPoint = searchEntryPoint ;
241240 }
242241
@@ -347,7 +346,7 @@ internal static WebGroundingChunk FromJson(Dictionary<string, object> jsonDict)
347346/// retrieved grounding chunks.
348347/// </summary>
349348public readonly struct GroundingSupport {
350- private readonly ReadOnlyCollection < int > _groundingChunkIndices ;
349+ private readonly IReadOnlyList < int > _groundingChunkIndices ;
351350
352351 /// <summary>
353352 /// Specifies the segment of the model's response content that this grounding support pertains
@@ -363,15 +362,15 @@ public readonly struct GroundingSupport {
363362 /// means that `groundingChunks[1]`, `groundingChunks[3]`, `groundingChunks[4]` are the
364363 /// retrieved content supporting this part of the response.
365364 /// </summary>
366- public IEnumerable < int > GroundingChunkIndices {
365+ public IReadOnlyList < int > GroundingChunkIndices {
367366 get {
368- return _groundingChunkIndices ?? new ReadOnlyCollection < int > ( new List < int > ( ) ) ;
367+ return _groundingChunkIndices ?? new List < int > ( ) ;
369368 }
370369 }
371370
372371 private GroundingSupport ( Segment segment , List < int > groundingChunkIndices ) {
373372 Segment = segment ;
374- _groundingChunkIndices = new ReadOnlyCollection < int > ( groundingChunkIndices ?? new List < int > ( ) ) ;
373+ _groundingChunkIndices = groundingChunkIndices ;
375374 }
376375
377376 internal static GroundingSupport FromJson ( Dictionary < string , object > jsonDict ) {
@@ -459,17 +458,17 @@ public readonly struct UsageMetadata {
459458 /// </summary>
460459 public int TotalTokenCount { get ; }
461460
462- private readonly ReadOnlyCollection < ModalityTokenCount > _promptTokensDetails ;
463- public IEnumerable < ModalityTokenCount > PromptTokensDetails {
461+ private readonly IReadOnlyList < ModalityTokenCount > _promptTokensDetails ;
462+ public IReadOnlyList < ModalityTokenCount > PromptTokensDetails {
464463 get {
465- return _promptTokensDetails ?? new ReadOnlyCollection < ModalityTokenCount > ( new List < ModalityTokenCount > ( ) ) ;
464+ return _promptTokensDetails ?? new List < ModalityTokenCount > ( ) ;
466465 }
467466 }
468467
469- private readonly ReadOnlyCollection < ModalityTokenCount > _candidatesTokensDetails ;
470- public IEnumerable < ModalityTokenCount > CandidatesTokensDetails {
468+ private readonly IReadOnlyList < ModalityTokenCount > _candidatesTokensDetails ;
469+ public IReadOnlyList < ModalityTokenCount > CandidatesTokensDetails {
471470 get {
472- return _candidatesTokensDetails ?? new ReadOnlyCollection < ModalityTokenCount > ( new List < ModalityTokenCount > ( ) ) ;
471+ return _candidatesTokensDetails ?? new List < ModalityTokenCount > ( ) ;
473472 }
474473 }
475474
@@ -480,11 +479,8 @@ private UsageMetadata(int promptTC, int candidatesTC, int thoughtsTC, int totalT
480479 CandidatesTokenCount = candidatesTC ;
481480 ThoughtsTokenCount = thoughtsTC ;
482481 TotalTokenCount = totalTC ;
483- _promptTokensDetails =
484- new ReadOnlyCollection < ModalityTokenCount > ( promptDetails ?? new List < ModalityTokenCount > ( ) ) ;
485- _candidatesTokensDetails =
486- new ReadOnlyCollection < ModalityTokenCount > ( candidateDetails ?? new List < ModalityTokenCount > ( ) ) ;
487-
482+ _promptTokensDetails = promptDetails ;
483+ _candidatesTokensDetails = candidateDetails ;
488484 }
489485
490486 /// <summary>
0 commit comments