Skip to content

Commit 3c7efbe

Browse files
committed
Merge remote-tracking branch 'origin/main' into DemoDokka
2 parents fb43135 + 6d166e0 commit 3c7efbe

File tree

15 files changed

+234
-46
lines changed

15 files changed

+234
-46
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Unreleased
22

3+
4+
# 16.1.0
35
* [fixed] Fixed `FirebaseAI.getInstance` StackOverflowException (#6971)
46
* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API.
57
* [changed] Introduced the `Voice` class, which accepts a voice name, and deprecated the `Voices` class.
68
* [changed] **Breaking Change**: Updated `SpeechConfig` to take in `Voice` class instead of `Voices` class.
79
* **Action Required:** Update all references of `SpeechConfig` initialization to use `Voice` class.
810
* [fixed] Fix incorrect model name in count token requests to the developer API backend
11+
* [feature] Added support for extra schema properties like `title`, `minItems`, `maxItems`, `minimum`
12+
and `maximum`. As well as support for the `anyOf` schema.
913

10-
1114
# 16.0.0
1215
* [feature] Initial release of the Firebase AI SDK (`firebase-ai`). This SDK *replaces* the previous
1316
Vertex AI in Firebase SDK (`firebase-vertexai`) to accommodate the evolving set of supported

firebase-ai/api.txt

Lines changed: 52 additions & 0 deletions
Large diffs are not rendered by default.

firebase-ai/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=16.1.0
16-
latestReleasedVersion=16.0.0
15+
version=16.2.0
16+
latestReleasedVersion=16.1.0

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class ImagenPersonFilterLevel private constructor(internal val internalVa
2525
*
2626
* > Important: Generation of images containing people or faces may require your use case to be
2727
* reviewed and approved by Cloud support; see the
28-
* [Responsible AI and usage
29-
* guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen)
28+
* [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen)
3029
* for more details.
3130
*/
3231
@JvmField public val ALLOW_ALL: ImagenPersonFilterLevel = ImagenPersonFilterLevel("allow_all")
@@ -35,8 +34,7 @@ public class ImagenPersonFilterLevel private constructor(internal val internalVa
3534
*
3635
* > Important: Generation of images containing people or faces may require your use case to be
3736
* reviewed and approved by Cloud support; see the
38-
* [Responsible AI and usage
39-
* guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen)
37+
* [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen)
4038
* for more details.
4139
*/
4240
@JvmField

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

Lines changed: 124 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ internal constructor(
4242
public val properties: Map<String, Schema>? = null,
4343
public val required: List<String>? = null,
4444
public val items: Schema? = null,
45+
public val title: String? = null,
46+
public val minItems: Int? = null,
47+
public val maxItems: Int? = null,
48+
public val minimum: Double? = null,
49+
public val maximum: Double? = null,
50+
public val anyOf: List<Schema>? = null,
4551
) {
4652

4753
public companion object {
@@ -53,12 +59,12 @@ internal constructor(
5359
*/
5460
@JvmStatic
5561
@JvmOverloads
56-
public fun boolean(description: String? = null, nullable: Boolean = false): Schema =
57-
Schema(
58-
description = description,
59-
nullable = nullable,
60-
type = "BOOLEAN",
61-
)
62+
public fun boolean(
63+
description: String? = null,
64+
nullable: Boolean = false,
65+
title: String? = null,
66+
): Schema =
67+
Schema(description = description, nullable = nullable, type = "BOOLEAN", title = title)
6268

6369
/**
6470
* Returns a [Schema] for a 32-bit signed integer number.
@@ -73,12 +79,21 @@ internal constructor(
7379
@JvmStatic
7480
@JvmName("numInt")
7581
@JvmOverloads
76-
public fun integer(description: String? = null, nullable: Boolean = false): Schema =
82+
public fun integer(
83+
description: String? = null,
84+
nullable: Boolean = false,
85+
title: String? = null,
86+
minimum: Double? = null,
87+
maximum: Double? = null,
88+
): Schema =
7789
Schema(
7890
description = description,
7991
format = "int32",
8092
nullable = nullable,
8193
type = "INTEGER",
94+
title = title,
95+
minimum = minimum,
96+
maximum = maximum,
8297
)
8398

8499
/**
@@ -90,11 +105,20 @@ internal constructor(
90105
@JvmStatic
91106
@JvmName("numLong")
92107
@JvmOverloads
93-
public fun long(description: String? = null, nullable: Boolean = false): Schema =
108+
public fun long(
109+
description: String? = null,
110+
nullable: Boolean = false,
111+
title: String? = null,
112+
minimum: Double? = null,
113+
maximum: Double? = null,
114+
): Schema =
94115
Schema(
95116
description = description,
96117
nullable = nullable,
97118
type = "INTEGER",
119+
title = title,
120+
minimum = minimum,
121+
maximum = maximum,
98122
)
99123

100124
/**
@@ -106,8 +130,21 @@ internal constructor(
106130
@JvmStatic
107131
@JvmName("numDouble")
108132
@JvmOverloads
109-
public fun double(description: String? = null, nullable: Boolean = false): Schema =
110-
Schema(description = description, nullable = nullable, type = "NUMBER")
133+
public fun double(
134+
description: String? = null,
135+
nullable: Boolean = false,
136+
title: String? = null,
137+
minimum: Double? = null,
138+
maximum: Double? = null,
139+
): Schema =
140+
Schema(
141+
description = description,
142+
nullable = nullable,
143+
type = "NUMBER",
144+
title = title,
145+
minimum = minimum,
146+
maximum = maximum,
147+
)
111148

112149
/**
113150
* Returns a [Schema] for a single-precision floating-point number.
@@ -123,8 +160,22 @@ internal constructor(
123160
@JvmStatic
124161
@JvmName("numFloat")
125162
@JvmOverloads
126-
public fun float(description: String? = null, nullable: Boolean = false): Schema =
127-
Schema(description = description, nullable = nullable, type = "NUMBER", format = "float")
163+
public fun float(
164+
description: String? = null,
165+
nullable: Boolean = false,
166+
title: String? = null,
167+
minimum: Double? = null,
168+
maximum: Double? = null,
169+
): Schema =
170+
Schema(
171+
description = description,
172+
nullable = nullable,
173+
type = "NUMBER",
174+
format = "float",
175+
title = title,
176+
minimum = minimum,
177+
maximum = maximum,
178+
)
128179

129180
/**
130181
* Returns a [Schema] for a string.
@@ -139,13 +190,15 @@ internal constructor(
139190
public fun string(
140191
description: String? = null,
141192
nullable: Boolean = false,
142-
format: StringFormat? = null
193+
format: StringFormat? = null,
194+
title: String? = null,
143195
): Schema =
144196
Schema(
145197
description = description,
146198
format = format?.value,
147199
nullable = nullable,
148-
type = "STRING"
200+
type = "STRING",
201+
title = title,
149202
)
150203

151204
/**
@@ -155,6 +208,7 @@ internal constructor(
155208
* `String` and values of type [Schema].
156209
*
157210
* **Example:** A `city` could be represented with the following object `Schema`.
211+
*
158212
* ```
159213
* Schema.obj(mapOf(
160214
* "name" to Schema.string(),
@@ -176,6 +230,7 @@ internal constructor(
176230
optionalProperties: List<String> = emptyList(),
177231
description: String? = null,
178232
nullable: Boolean = false,
233+
title: String? = null,
179234
): Schema {
180235
if (!properties.keys.containsAll(optionalProperties)) {
181236
throw IllegalArgumentException(
@@ -188,6 +243,7 @@ internal constructor(
188243
properties = properties,
189244
required = properties.keys.minus(optionalProperties.toSet()).toList(),
190245
type = "OBJECT",
246+
title = title,
191247
)
192248
}
193249

@@ -203,20 +259,25 @@ internal constructor(
203259
public fun array(
204260
items: Schema,
205261
description: String? = null,
206-
nullable: Boolean = false
262+
nullable: Boolean = false,
263+
title: String? = null,
264+
minItems: Int? = null,
265+
maxItems: Int? = null,
207266
): Schema =
208267
Schema(
209268
description = description,
210269
nullable = nullable,
211270
items = items,
212271
type = "ARRAY",
272+
title = title,
273+
minItems = minItems,
274+
maxItems = maxItems,
213275
)
214276

215277
/**
216278
* Returns a [Schema] for an enumeration.
217279
*
218280
* For example, the cardinal directions can be represented as:
219-
*
220281
* ```
221282
* Schema.enumeration(listOf("north", "east", "south", "west"), "Cardinal directions")
222283
* ```
@@ -230,37 +291,79 @@ internal constructor(
230291
public fun enumeration(
231292
values: List<String>,
232293
description: String? = null,
233-
nullable: Boolean = false
294+
nullable: Boolean = false,
295+
title: String? = null,
234296
): Schema =
235297
Schema(
236298
description = description,
237299
format = "enum",
238300
nullable = nullable,
239301
enum = values,
240302
type = "STRING",
303+
title = title,
241304
)
305+
306+
/**
307+
* Returns a [Schema] representing a value that must conform to *any* (one of) the provided
308+
* sub-schema.
309+
*
310+
* Example: A field that can hold either a simple userID or a more detailed user object.
311+
*
312+
* Schema.anyOf( listOf( Schema.integer(description = "User ID"), Schema.obj(mapOf(
313+
*
314+
* ```
315+
* "userID" to Schema.integer(description = "User ID"),
316+
* "username" to Schema.string(description = "Username")
317+
* ```
318+
*
319+
* )) )
320+
*
321+
* @param schemas The list of valid schemas which could be here
322+
*/
323+
@JvmStatic
324+
public fun anyOf(schemas: List<Schema>): Schema = Schema(type = "ANYOF", anyOf = schemas)
242325
}
243326

244-
internal fun toInternal(): Internal =
245-
Internal(
246-
type,
327+
internal fun toInternal(): Internal {
328+
val cleanedType =
329+
if (type == "ANYOF") {
330+
null
331+
} else {
332+
type
333+
}
334+
return Internal(
335+
cleanedType,
247336
description,
248337
format,
249338
nullable,
250339
enum,
251340
properties?.mapValues { it.value.toInternal() },
252341
required,
253342
items?.toInternal(),
343+
title,
344+
minItems,
345+
maxItems,
346+
minimum,
347+
maximum,
348+
anyOf?.map { it.toInternal() },
254349
)
350+
}
351+
255352
@Serializable
256353
internal data class Internal(
257-
val type: String,
354+
val type: String? = null,
258355
val description: String? = null,
259356
val format: String? = null,
260357
val nullable: Boolean? = false,
261358
val enum: List<String>? = null,
262359
val properties: Map<String, Internal>? = null,
263360
val required: List<String>? = null,
264361
val items: Internal? = null,
362+
val title: String? = null,
363+
val minItems: Int? = null,
364+
val maxItems: Int? = null,
365+
val minimum: Double? = null,
366+
val maximum: Double? = null,
367+
val anyOf: List<Internal>? = null,
265368
)
266369
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import kotlinx.serialization.SerialName
2020
import kotlinx.serialization.Serializable
2121

2222
/**
23-
* Various voices supported by the server. The list of all voices can be found
24-
* [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd)
23+
* Various voices supported by the server. In the documentation, find the list of
24+
* [all supported voices](https://cloud.google.com/text-to-speech/docs/chirp3-hd).
2525
*/
2626
@PublicPreviewAPI
2727
public class Voice public constructor(public val voiceName: String) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import kotlinx.serialization.SerialName
2020
import kotlinx.serialization.Serializable
2121

2222
/** Various voices supported by the server */
23-
@Deprecated("Please use the Voice class instead.", ReplaceWith("Voice"))
23+
@Deprecated("Use the Voice class instead.", ReplaceWith("Voice"))
2424
@PublicPreviewAPI
2525
public class Voices private constructor(public val ordinal: Int) {
2626

0 commit comments

Comments
 (0)