From edf938a26beb3c3cda9949d3f73a098d8bcde697 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 19 Jul 2024 11:19:57 -0700 Subject: [PATCH 1/3] wire through response schema from common --- .../firebase/vertexai/internal/util/conversions.kt | 3 ++- .../google/firebase/vertexai/type/GenerationConfig.kt | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt index 1e599603002..dffaa2d2dbc 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt @@ -114,7 +114,8 @@ internal fun GenerationConfig.toInternal() = candidateCount = candidateCount, maxOutputTokens = maxOutputTokens, stopSequences = stopSequences, - responseMimeType = responseMimeType + responseMimeType = responseMimeType, + responseSchema = responseSchema ) internal fun com.google.firebase.vertexai.type.HarmCategory.toInternal() = diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt index 831dfc55eb9..8b52286146b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt @@ -25,9 +25,11 @@ package com.google.firebase.vertexai.type * @property candidateCount The max *unique* responses to return * @property maxOutputTokens The max tokens to generate per response * @property stopSequences A list of strings to stop generation on occurrence of - * * @property responseMimeType Response type for generated candidate text. See the + * @property responseMimeType Response type for generated candidate text. See the * [vertex docs](https://cloud.google.com/vertex-ai/docs/reference/rest/v1beta1/GenerationConfig) * for a list of supported types. + * @property responseSchema A schema that the response must adhere to, used with the + * `application/json` mimeType. */ class GenerationConfig private constructor( @@ -37,7 +39,8 @@ private constructor( val candidateCount: Int?, val maxOutputTokens: Int?, val stopSequences: List?, - val responseMimeType: String? + val responseMimeType: String?, + val responseSchema: Schema<*>? = null, ) { /** @@ -63,6 +66,7 @@ private constructor( @JvmField var maxOutputTokens: Int? = null @JvmField var stopSequences: List? = null @JvmField var responseMimeType: String? = null + @JvmField var responseSchema: Schema<*>? = null /** Create a new [GenerationConfig] with the attached arguments. */ fun build() = @@ -73,7 +77,8 @@ private constructor( candidateCount = candidateCount, maxOutputTokens = maxOutputTokens, stopSequences = stopSequences, - responseMimeType = responseMimeType + responseMimeType = responseMimeType, + responseSchema = responseSchema ) } From b20335cc391a3fe019e1fae4eb01610fe972a432 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 19 Jul 2024 11:22:14 -0700 Subject: [PATCH 2/3] add changelog --- firebase-vertexai/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/CHANGELOG.md b/firebase-vertexai/CHANGELOG.md index f3bb08e8f9b..319676102e5 100644 --- a/firebase-vertexai/CHANGELOG.md +++ b/firebase-vertexai/CHANGELOG.md @@ -1,5 +1,5 @@ # Unreleased - +* [feature] added support for `responseSchema` in `GenerationConfig`. # 16.0.0-beta03 * [changed] Breaking Change: changed `Schema.int` to return 32 bit integers instead of 64 bit (long). From 051bbf39c9429b8a809acebb486d91fed0a403f7 Mon Sep 17 00:00:00 2001 From: David Motsonashvili Date: Fri, 19 Jul 2024 11:27:27 -0700 Subject: [PATCH 3/3] missing toInternal --- .../com/google/firebase/vertexai/internal/util/conversions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt index dffaa2d2dbc..f6f77b42142 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt @@ -115,7 +115,7 @@ internal fun GenerationConfig.toInternal() = maxOutputTokens = maxOutputTokens, stopSequences = stopSequences, responseMimeType = responseMimeType, - responseSchema = responseSchema + responseSchema = responseSchema?.toInternal() ) internal fun com.google.firebase.vertexai.type.HarmCategory.toInternal() =