Skip to content

Commit f1e7af5

Browse files
authored
Merge branch 'main' into dconeybe/dataconnect/GradlePluginMacOSAndWindows
2 parents 3fee185 + 57e64e7 commit f1e7af5

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

.github/workflows/ci_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167

168168
steps:
169169
- name: Download Artifacts
170-
uses: actions/[email protected].5
170+
uses: actions/[email protected].7
171171
with:
172172
path: artifacts
173173

firebase-vertexai/CHANGELOG.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Unreleased
2-
* [changed] Breaking Change: refactored enum classes to be normal classes (#6340).
2+
* [feature] Added support for `title` and `publicationDate` in citations. (#6309)
3+
* [feature] Added support for `frequencyPenalty`, `presencePenalty`, and `HarmBlockMethod`. (#6309)
4+
* [changed] **Breaking Change**: Introduced `Citations` class. Now `CitationMetadata` wraps that type. (#6276)
5+
* [changed] **Breaking Change**: Introduced `FunctionCall` and `FunctionResponse` types. Now `FunctionCallPart` and `FunctionResponsePart` wrap those types, respectively. (#6311)
6+
* [changed] **Breaking Change**: Reworked `Schema` declaration mechanism. (#6258)
7+
* [changed] **Breaking Change**: Reworked function calling mechanism to use the new `Schema` format. Function calls no longer use native types, nor include references to the actual executable code. (#6258)
8+
* [changed] **Breaking Change**: Made `totalBillableCharacters` field in `CountTokens` nullable and optional. (#6294)
9+
* [changed] **Breaking Change**: Removed `UNKNOWN` option for the `HarmBlockThreshold` enum. (#6294)
10+
* [changed] **Breaking Change**: Removed `UNSPECIFIED` option for the `HarmBlockThreshold`, `HarmProbability`, `HarmSeverity`, and `BlockReason` enums. (#6294)
11+
* [changed] **Breaking Change**: Renamed `BlockThreshold` as `HarmBlockThreshold`. (#6262)
12+
* [changed] **Breaking Change**: Renamed all types and methods starting with `blob` to start with `inlineData`. (#6309)
13+
* [changed] **Breaking Change**: Changed the order of arguments in `InlineDataPart` to match `ImagePart`. (#6340)
14+
* [changed] **Breaking Change**: Changed `RequestOption` to accept only `long` timeout values. (#6289)
15+
* [changed] **Breaking Change**: Moved `requestOptions` to the last positional argument in the `generativeModel` argument list. (#6292)
16+
* [changed] **Breaking Change**: Replaced sealed classes with abstract classes for `StringFormat`. (#6334)
17+
* [changed] **Breaking Change**: Refactored enum classes to be normal classes. (#6340)
18+
* [changed] **Breaking Change**: Marked `GenerativeModel` properties as private. (#6309)
319

420

521
# 16.0.0-beta05
@@ -17,4 +33,3 @@
1733
* [feature] Added support for `responseMimeType` in `GenerationConfig`.
1834
* [changed] Renamed `GoogleGenerativeAIException` to `FirebaseVertexAIException`.
1935
* [changed] Updated the KDocs for various classes and functions.
20-

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ internal constructor(
231231
generationConfig?.toInternal(),
232232
tools?.map { it.toInternal() },
233233
toolConfig?.toInternal(),
234-
systemInstruction?.toInternal()
234+
systemInstruction?.copy(role = "system")?.toInternal()
235235
)
236236

237237
private fun constructCountTokensRequest(vararg prompt: Content) =

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public class Content
3030
@JvmOverloads
3131
constructor(public val role: String? = "user", public val parts: List<Part>) {
3232

33+
public fun copy(role: String? = this.role, parts: List<Part> = this.parts): Content {
34+
return Content(role, parts)
35+
}
36+
3337
/** Builder class to facilitate constructing complex [Content] objects. */
3438
public class Builder {
3539

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal constructor(
3636
public companion object {
3737
/** Returns a schema for a boolean */
3838
@JvmStatic
39+
@JvmOverloads
3940
public fun boolean(description: String? = null, nullable: Boolean = false): Schema =
4041
Schema(
4142
description = description,
@@ -51,6 +52,7 @@ internal constructor(
5152
*/
5253
@JvmStatic
5354
@JvmName("numInt")
55+
@JvmOverloads
5456
public fun integer(description: String? = null, nullable: Boolean = false): Schema =
5557
Schema(
5658
description = description,
@@ -67,6 +69,7 @@ internal constructor(
6769
*/
6870
@JvmStatic
6971
@JvmName("numLong")
72+
@JvmOverloads
7073
public fun long(description: String? = null, nullable: Boolean = false): Schema =
7174
Schema(
7275
description = description,
@@ -82,6 +85,7 @@ internal constructor(
8285
*/
8386
@JvmStatic
8487
@JvmName("numDouble")
88+
@JvmOverloads
8589
public fun double(description: String? = null, nullable: Boolean = false): Schema =
8690
Schema(description = description, nullable = nullable, type = "NUMBER", format = "double")
8791

@@ -93,6 +97,7 @@ internal constructor(
9397
*/
9498
@JvmStatic
9599
@JvmName("numFloat")
100+
@JvmOverloads
96101
public fun float(description: String? = null, nullable: Boolean = false): Schema =
97102
Schema(description = description, nullable = nullable, type = "NUMBER", format = "float")
98103

@@ -105,6 +110,7 @@ internal constructor(
105110
*/
106111
@JvmStatic
107112
@JvmName("str")
113+
@JvmOverloads
108114
public fun string(
109115
description: String? = null,
110116
nullable: Boolean = false,
@@ -125,6 +131,7 @@ internal constructor(
125131
* @param nullable: Whether null is a valid value for this schema
126132
*/
127133
@JvmStatic
134+
@JvmOverloads
128135
public fun obj(
129136
properties: Map<String, Schema>,
130137
optionalProperties: List<String> = emptyList(),
@@ -153,6 +160,7 @@ internal constructor(
153160
* @param nullable: Whether null is a valid value for this schema
154161
*/
155162
@JvmStatic
163+
@JvmOverloads
156164
public fun array(
157165
items: Schema,
158166
description: String? = null,
@@ -173,6 +181,7 @@ internal constructor(
173181
* @param nullable: Whether null is a valid value for this schema
174182
*/
175183
@JvmStatic
184+
@JvmOverloads
176185
public fun enumeration(
177186
values: List<String>,
178187
description: String? = null,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.vertexai
18+
19+
import com.google.firebase.vertexai.common.APIController
20+
import com.google.firebase.vertexai.common.GenerateContentResponse
21+
import com.google.firebase.vertexai.common.JSON
22+
import com.google.firebase.vertexai.common.server.Candidate
23+
import com.google.firebase.vertexai.common.shared.Content
24+
import com.google.firebase.vertexai.common.shared.TextPart
25+
import com.google.firebase.vertexai.common.util.doBlocking
26+
import com.google.firebase.vertexai.type.RequestOptions
27+
import com.google.firebase.vertexai.type.content
28+
import io.kotest.assertions.json.shouldContainJsonKey
29+
import io.kotest.assertions.json.shouldContainJsonKeyValue
30+
import io.kotest.matchers.collections.shouldNotBeEmpty
31+
import io.kotest.matchers.types.shouldBeInstanceOf
32+
import io.ktor.client.engine.mock.MockEngine
33+
import io.ktor.client.engine.mock.respond
34+
import io.ktor.http.HttpHeaders
35+
import io.ktor.http.HttpStatusCode
36+
import io.ktor.http.content.TextContent
37+
import io.ktor.http.headersOf
38+
import kotlin.time.Duration.Companion.seconds
39+
import kotlinx.coroutines.withTimeout
40+
import kotlinx.serialization.encodeToString
41+
import org.junit.Test
42+
43+
internal class GenerativeModelTesting {
44+
private val TEST_CLIENT_ID = "test"
45+
46+
@Test
47+
fun addition() = doBlocking {
48+
val mockEngine = MockEngine {
49+
respond(
50+
generateContentResponseAsJsonString("text response"),
51+
HttpStatusCode.OK,
52+
headersOf(HttpHeaders.ContentType, "application/json")
53+
)
54+
}
55+
56+
val apiController =
57+
APIController(
58+
"super_cool_test_key",
59+
"gemini-1.5-flash",
60+
RequestOptions(timeout = 5.seconds, endpoint = "https://my.custom.endpoint"),
61+
mockEngine,
62+
TEST_CLIENT_ID,
63+
null,
64+
)
65+
66+
val generativeModel =
67+
GenerativeModel(
68+
"gemini-1.5-flash",
69+
systemInstruction = content { text("system instruction") },
70+
controller = apiController
71+
)
72+
73+
withTimeout(5.seconds) { generativeModel.generateContent("my test prompt") }
74+
75+
mockEngine.requestHistory.shouldNotBeEmpty()
76+
77+
val request = mockEngine.requestHistory.first().body
78+
request.shouldBeInstanceOf<TextContent>()
79+
80+
request.text.let {
81+
it shouldContainJsonKey "system_instruction"
82+
it.shouldContainJsonKeyValue("$.system_instruction.role", "system")
83+
it.shouldContainJsonKeyValue("$.system_instruction.parts[0].text", "system instruction")
84+
}
85+
}
86+
87+
private fun generateContentResponseAsJsonString(text: String): String {
88+
return JSON.encodeToString(
89+
GenerateContentResponse(listOf(Candidate(Content(parts = listOf(TextPart(text))))))
90+
)
91+
}
92+
}

0 commit comments

Comments
 (0)