@@ -337,15 +337,15 @@ public class GroundingMetadata(
337
337
retrievalQueries = retrievalQueries.orEmpty(),
338
338
groundingAttribution = groundingAttribution?.map { it.toPublic() }.orEmpty(),
339
339
groundingChunks = groundingChunks?.map { it.toPublic() }.orEmpty(),
340
- groundingSupports = groundingSupports?.map { it.toPublic() }.orEmpty()
340
+ groundingSupports = groundingSupports?.map { it.toPublic() }.orEmpty().filterNotNull()
341
341
)
342
342
}
343
343
}
344
344
345
345
/* *
346
346
* Represents a Google Search entry point.
347
347
*
348
- * When using this feature , you are required to comply with the
348
+ * When using this API , you are required to comply with the
349
349
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
350
350
* Search".
351
351
*
@@ -355,23 +355,30 @@ public class GroundingMetadata(
355
355
* @property sdkBlob A blob of data for the client SDK to render the search entry point.
356
356
*/
357
357
public class SearchEntryPoint (
358
- public val renderedContent : String? ,
358
+ public val renderedContent : String ,
359
359
public val sdkBlob : String? ,
360
360
) {
361
361
@Serializable
362
362
internal data class Internal (
363
363
val renderedContent : String? ,
364
364
val sdkBlob : String? ,
365
365
) {
366
- internal fun toPublic () = SearchEntryPoint (renderedContent = renderedContent, sdkBlob = sdkBlob)
366
+ internal fun toPublic (): SearchEntryPoint {
367
+ // If rendered content is null, the user must not display the grounded result. If they do,
368
+ // they violate the service terms. To prevent this from happening, throw an exception.
369
+ if (renderedContent == null ) {
370
+ throw SerializationException (" renderedContent is null, should be a string" )
371
+ }
372
+ return SearchEntryPoint (renderedContent = renderedContent, sdkBlob = sdkBlob)
373
+ }
367
374
}
368
375
}
369
376
370
377
/* *
371
378
* Represents a chunk of retrieved data that supports a claim in the model's response. This is part
372
379
* of the grounding information provided when grounding is enabled.
373
380
*
374
- * When using this feature , you are required to comply with the
381
+ * When using this API , you are required to comply with the
375
382
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
376
383
* Search".
377
384
*
@@ -391,7 +398,7 @@ public class GroundingChunk(
391
398
/* *
392
399
* A grounding chunk from the web.
393
400
*
394
- * When using this feature , you are required to comply with the
401
+ * When using this API , you are required to comply with the
395
402
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
396
403
* Search".
397
404
*
@@ -415,7 +422,7 @@ public class WebGroundingChunk(
415
422
* Provides information about how a specific segment of the model's response is supported by the
416
423
* retrieved grounding chunks.
417
424
*
418
- * When using this feature , you are required to comply with the
425
+ * When using this API , you are required to comply with the
419
426
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
420
427
* Search".
421
428
*
@@ -426,19 +433,23 @@ public class WebGroundingChunk(
426
433
* that support the claim made in the associated `segment` of the response.
427
434
*/
428
435
public class GroundingSupport (
429
- public val segment : Segment ? ,
436
+ public val segment : Segment ,
430
437
public val groundingChunkIndices : List <Int >,
431
438
) {
432
439
@Serializable
433
440
internal data class Internal (
434
441
val segment : Segment .Internal ? ,
435
442
val groundingChunkIndices : List <Int >? ,
436
443
) {
437
- internal fun toPublic () =
438
- GroundingSupport (
439
- segment = segment?.toPublic(),
444
+ internal fun toPublic (): GroundingSupport ? {
445
+ if (segment == null ) {
446
+ return null
447
+ }
448
+ return GroundingSupport (
449
+ segment = segment.toPublic(),
440
450
groundingChunkIndices = groundingChunkIndices.orEmpty(),
441
451
)
452
+ }
442
453
}
443
454
}
444
455
0 commit comments