Skip to content

Commit 11d3bde

Browse files
committed
make more fields required
1 parent 80347e0 commit 11d3bde

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

firebase-ai/api.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ package com.google.firebase.ai.type {
435435
}
436436

437437
public final class GroundingSupport {
438-
ctor public GroundingSupport(com.google.firebase.ai.type.Segment? segment, java.util.List<java.lang.Integer> groundingChunkIndices);
438+
ctor public GroundingSupport(com.google.firebase.ai.type.Segment segment, java.util.List<java.lang.Integer> groundingChunkIndices);
439439
method public java.util.List<java.lang.Integer> getGroundingChunkIndices();
440-
method public com.google.firebase.ai.type.Segment? getSegment();
440+
method public com.google.firebase.ai.type.Segment getSegment();
441441
property public final java.util.List<java.lang.Integer> groundingChunkIndices;
442-
property public final com.google.firebase.ai.type.Segment? segment;
442+
property public final com.google.firebase.ai.type.Segment segment;
443443
}
444444

445445
public final class HarmBlockMethod {
@@ -942,10 +942,10 @@ package com.google.firebase.ai.type {
942942
}
943943

944944
public final class SearchEntryPoint {
945-
ctor public SearchEntryPoint(String? renderedContent, String? sdkBlob);
946-
method public String? getRenderedContent();
945+
ctor public SearchEntryPoint(String renderedContent, String? sdkBlob);
946+
method public String getRenderedContent();
947947
method public String? getSdkBlob();
948-
property public final String? renderedContent;
948+
property public final String renderedContent;
949949
property public final String? sdkBlob;
950950
}
951951

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Candidate.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ public class GroundingMetadata(
337337
retrievalQueries = retrievalQueries.orEmpty(),
338338
groundingAttribution = groundingAttribution?.map { it.toPublic() }.orEmpty(),
339339
groundingChunks = groundingChunks?.map { it.toPublic() }.orEmpty(),
340-
groundingSupports = groundingSupports?.map { it.toPublic() }.orEmpty()
340+
groundingSupports = groundingSupports?.map { it.toPublic() }.orEmpty().filterNotNull()
341341
)
342342
}
343343
}
344344

345345
/**
346346
* Represents a Google Search entry point.
347347
*
348-
* When using this feature, you are required to comply with the
348+
* When using this API, you are required to comply with the
349349
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
350350
* Search".
351351
*
@@ -355,23 +355,30 @@ public class GroundingMetadata(
355355
* @property sdkBlob A blob of data for the client SDK to render the search entry point.
356356
*/
357357
public class SearchEntryPoint(
358-
public val renderedContent: String?,
358+
public val renderedContent: String,
359359
public val sdkBlob: String?,
360360
) {
361361
@Serializable
362362
internal data class Internal(
363363
val renderedContent: String?,
364364
val sdkBlob: String?,
365365
) {
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+
}
367374
}
368375
}
369376

370377
/**
371378
* Represents a chunk of retrieved data that supports a claim in the model's response. This is part
372379
* of the grounding information provided when grounding is enabled.
373380
*
374-
* When using this feature, you are required to comply with the
381+
* When using this API, you are required to comply with the
375382
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
376383
* Search".
377384
*
@@ -391,7 +398,7 @@ public class GroundingChunk(
391398
/**
392399
* A grounding chunk from the web.
393400
*
394-
* When using this feature, you are required to comply with the
401+
* When using this API, you are required to comply with the
395402
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
396403
* Search".
397404
*
@@ -415,7 +422,7 @@ public class WebGroundingChunk(
415422
* Provides information about how a specific segment of the model's response is supported by the
416423
* retrieved grounding chunks.
417424
*
418-
* When using this feature, you are required to comply with the
425+
* When using this API, you are required to comply with the
419426
* [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google
420427
* Search".
421428
*
@@ -426,19 +433,23 @@ public class WebGroundingChunk(
426433
* that support the claim made in the associated `segment` of the response.
427434
*/
428435
public class GroundingSupport(
429-
public val segment: Segment?,
436+
public val segment: Segment,
430437
public val groundingChunkIndices: List<Int>,
431438
) {
432439
@Serializable
433440
internal data class Internal(
434441
val segment: Segment.Internal?,
435442
val groundingChunkIndices: List<Int>?,
436443
) {
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(),
440450
groundingChunkIndices = groundingChunkIndices.orEmpty(),
441451
)
452+
}
442453
}
443454
}
444455

firebase-ai/src/test/java/com/google/firebase/ai/VertexAIUnarySnapshotTests.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,19 +619,19 @@ internal class VertexAIUnarySnapshotTests {
619619
groundingMetadata.groundingSupports.size shouldBe 3
620620
val groundingSupport = groundingMetadata.groundingSupports.first()
621621
groundingSupport.segment.shouldNotBeNull()
622-
groundingSupport.segment?.startIndex shouldBe 0
623-
groundingSupport.segment?.partIndex shouldBe 0
624-
groundingSupport.segment?.endIndex shouldBe 56
625-
groundingSupport.segment?.text shouldBe
622+
groundingSupport.segment.startIndex shouldBe 0
623+
groundingSupport.segment.partIndex shouldBe 0
624+
groundingSupport.segment.endIndex shouldBe 56
625+
groundingSupport.segment.text shouldBe
626626
"The current weather in London, United Kingdom is cloudy."
627627
groundingSupport.groundingChunkIndices.first() shouldBe 0
628628

629629
val secondGroundingSupport = groundingMetadata.groundingSupports[1]
630630
secondGroundingSupport.segment.shouldNotBeNull()
631-
secondGroundingSupport.segment?.startIndex shouldBe 57
632-
secondGroundingSupport.segment?.partIndex shouldBe 0
633-
secondGroundingSupport.segment?.endIndex shouldBe 123
634-
secondGroundingSupport.segment?.text shouldBe
631+
secondGroundingSupport.segment.startIndex shouldBe 57
632+
secondGroundingSupport.segment.partIndex shouldBe 0
633+
secondGroundingSupport.segment.endIndex shouldBe 123
634+
secondGroundingSupport.segment.text shouldBe
635635
"The temperature is 67°F (19°C), but it feels like 75°F (24°C)."
636636
secondGroundingSupport.groundingChunkIndices.first() shouldBe 1
637637
}

0 commit comments

Comments
 (0)