Skip to content

Commit 2d6c899

Browse files
authored
Remove functionResponse accessor, and mark functionCallingConfig nullable (#6373)
There's no need for the response accessor, as under normal circunstances there's no need to have easy access to the [FunctionResponsePart] the app adds to a prompt. Additionally, to make evolving the API easier and backward compatible, made `functionCallingConfig` parameter nullable in `ToolConfig`.
1 parent 7cf67aa commit 2d6c899

File tree

5 files changed

+17
-52
lines changed

5 files changed

+17
-52
lines changed

firebase-vertexai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
* [changed] **Breaking Change**: Changed `functionCallingConfig` parameter type to be nullable in `ToolConfig`. (#6373)
3+
* [changed] **Breaking Change**: Removed `functionResponse` accessor method from `GenerateContentResponse`. (#6373)
24
* [changed] **Breaking Change**: Migrated `FirebaseVertexAIException` from a sealed class to an abstract class, and marked constructors as internal. (#6368)
35
* [feature] Added support for `title` and `publicationDate` in citations. (#6309)
46
* [feature] Added support for `frequencyPenalty`, `presencePenalty`, and `HarmBlockMethod`. (#6309)

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/client/Types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal data class Tool(
4343

4444
@Serializable
4545
internal data class ToolConfig(
46-
@SerialName("function_calling_config") val functionCallingConfig: FunctionCallingConfig
46+
@SerialName("function_calling_config") val functionCallingConfig: FunctionCallingConfig?
4747
)
4848

4949
@Serializable

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,19 @@ internal fun HarmBlockMethod.toInternal() =
151151

152152
internal fun ToolConfig.toInternal() =
153153
com.google.firebase.vertexai.common.client.ToolConfig(
154-
com.google.firebase.vertexai.common.client.FunctionCallingConfig(
155-
when (functionCallingConfig.mode) {
156-
FunctionCallingConfig.Mode.ANY ->
157-
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.ANY
158-
FunctionCallingConfig.Mode.AUTO ->
159-
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.AUTO
160-
FunctionCallingConfig.Mode.NONE ->
161-
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.NONE
162-
},
163-
functionCallingConfig.allowedFunctionNames
164-
)
154+
functionCallingConfig?.let {
155+
com.google.firebase.vertexai.common.client.FunctionCallingConfig(
156+
when (it.mode) {
157+
FunctionCallingConfig.Mode.ANY ->
158+
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.ANY
159+
FunctionCallingConfig.Mode.AUTO ->
160+
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.AUTO
161+
FunctionCallingConfig.Mode.NONE ->
162+
com.google.firebase.vertexai.common.client.FunctionCallingConfig.Mode.NONE
163+
},
164+
it.allowedFunctionNames
165+
)
166+
}
165167
)
166168

167169
internal fun HarmBlockThreshold.toInternal() =

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.google.firebase.vertexai.type
1818

19-
import android.util.Log
20-
2119
/**
2220
* Represents a response from the model.
2321
*
@@ -39,41 +37,4 @@ public class GenerateContentResponse(
3937
public val functionCalls: List<FunctionCallPart> by lazy {
4038
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
4139
}
42-
43-
/**
44-
* Convenience field representing the first function response part in the response, if it exists.
45-
*/
46-
public val functionResponse: FunctionResponsePart? by lazy { firstPartAs() }
47-
48-
private inline fun <reified T : Part> firstPartAs(): T? {
49-
if (candidates.isEmpty()) {
50-
warn("No candidates were found, but was asked to get a candidate.")
51-
return null
52-
}
53-
54-
val (parts, otherParts) = candidates.first().content.parts.partition { it is T }
55-
val type = T::class.simpleName ?: "of the part type you asked for"
56-
57-
if (parts.isEmpty()) {
58-
if (otherParts.isNotEmpty()) {
59-
warn(
60-
"We didn't find any $type, but we did find other part types. Did you ask for the right type?"
61-
)
62-
}
63-
64-
return null
65-
}
66-
67-
if (parts.size > 1) {
68-
warn("Multiple $type were found, returning the first one.")
69-
} else if (otherParts.isNotEmpty()) {
70-
warn("Returning the only $type found, but other part types were present as well.")
71-
}
72-
73-
return parts.first() as T
74-
}
75-
76-
private fun warn(message: String) {
77-
Log.w("GenerateContentResponse", message)
78-
}
7940
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ package com.google.firebase.vertexai.type
2222
*
2323
* @param functionCallingConfig The config for function calling
2424
*/
25-
public class ToolConfig(internal val functionCallingConfig: FunctionCallingConfig)
25+
public class ToolConfig(internal val functionCallingConfig: FunctionCallingConfig?)

0 commit comments

Comments
 (0)