Skip to content

Commit ba49350

Browse files
committed
Revert "Introduce FunctionCall and FunctionResponse types (#6311)"
This reverts commit 7bab838.
1 parent d6ee0d2 commit ba49350

File tree

3 files changed

+34
-59
lines changed

3 files changed

+34
-59
lines changed

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import android.graphics.BitmapFactory
2121
import android.util.Base64
2222
import com.google.firebase.vertexai.common.client.Schema
2323
import com.google.firebase.vertexai.common.shared.FileData
24+
import com.google.firebase.vertexai.common.shared.FunctionCall
25+
import com.google.firebase.vertexai.common.shared.FunctionCallPart
26+
import com.google.firebase.vertexai.common.shared.FunctionResponse
27+
import com.google.firebase.vertexai.common.shared.FunctionResponsePart
2428
import com.google.firebase.vertexai.common.shared.InlineData
2529
import com.google.firebase.vertexai.type.BlockReason
2630
import com.google.firebase.vertexai.type.Candidate
@@ -30,12 +34,8 @@ import com.google.firebase.vertexai.type.Content
3034
import com.google.firebase.vertexai.type.CountTokensResponse
3135
import com.google.firebase.vertexai.type.FileDataPart
3236
import com.google.firebase.vertexai.type.FinishReason
33-
import com.google.firebase.vertexai.type.FunctionCall
34-
import com.google.firebase.vertexai.type.FunctionCallPart
3537
import com.google.firebase.vertexai.type.FunctionCallingConfig
3638
import com.google.firebase.vertexai.type.FunctionDeclaration
37-
import com.google.firebase.vertexai.type.FunctionResponse
38-
import com.google.firebase.vertexai.type.FunctionResponsePart
3939
import com.google.firebase.vertexai.type.GenerateContentResponse
4040
import com.google.firebase.vertexai.type.GenerationConfig
4141
import com.google.firebase.vertexai.type.HarmBlockMethod
@@ -81,10 +81,10 @@ internal fun Part.toInternal(): com.google.firebase.vertexai.common.shared.Part
8181
com.google.firebase.vertexai.common.shared.InlineDataPart(
8282
InlineData(mimeType, Base64.encodeToString(inlineData, BASE_64_FLAGS))
8383
)
84-
is FunctionCallPart ->
85-
com.google.firebase.vertexai.common.shared.FunctionCallPart(functionCall.toInternal())
86-
is FunctionResponsePart ->
87-
com.google.firebase.vertexai.common.shared.FunctionResponsePart(functionResponse.toInternal())
84+
is com.google.firebase.vertexai.type.FunctionCallPart ->
85+
FunctionCallPart(FunctionCall(name, args.orEmpty()))
86+
is com.google.firebase.vertexai.type.FunctionResponsePart ->
87+
FunctionResponsePart(FunctionResponse(name, response.toInternal()))
8888
is FileDataPart ->
8989
com.google.firebase.vertexai.common.shared.FileDataPart(
9090
FileData(mimeType = mimeType, fileUri = uri)
@@ -96,12 +96,6 @@ internal fun Part.toInternal(): com.google.firebase.vertexai.common.shared.Part
9696
}
9797
}
9898

99-
internal fun FunctionCall.toInternal() =
100-
com.google.firebase.vertexai.common.shared.FunctionCall(name, args)
101-
102-
internal fun FunctionResponse.toInternal() =
103-
com.google.firebase.vertexai.common.shared.FunctionResponse(name, response)
104-
10599
internal fun SafetySetting.toInternal() =
106100
com.google.firebase.vertexai.common.shared.SafetySetting(
107101
harmCategory.toInternal(),
@@ -235,10 +229,16 @@ internal fun com.google.firebase.vertexai.common.shared.Part.toPublic(): Part {
235229
InlineDataPart(data, inlineData.mimeType)
236230
}
237231
}
238-
is com.google.firebase.vertexai.common.shared.FunctionCallPart ->
239-
FunctionCallPart(functionCall.toPublic())
240-
is com.google.firebase.vertexai.common.shared.FunctionResponsePart ->
241-
FunctionResponsePart(functionResponse.toPublic())
232+
is FunctionCallPart ->
233+
com.google.firebase.vertexai.type.FunctionCallPart(
234+
functionCall.name,
235+
functionCall.args.orEmpty(),
236+
)
237+
is FunctionResponsePart ->
238+
com.google.firebase.vertexai.type.FunctionResponsePart(
239+
functionResponse.name,
240+
functionResponse.response.toPublic(),
241+
)
242242
is com.google.firebase.vertexai.common.shared.FileDataPart ->
243243
FileDataPart(fileData.mimeType, fileData.fileUri)
244244
else ->
@@ -248,15 +248,6 @@ internal fun com.google.firebase.vertexai.common.shared.Part.toPublic(): Part {
248248
}
249249
}
250250

251-
internal fun com.google.firebase.vertexai.common.shared.FunctionCall.toPublic() =
252-
FunctionCall(name, args.orEmpty().mapValues { it.value ?: JsonNull })
253-
254-
internal fun com.google.firebase.vertexai.common.shared.FunctionResponse.toPublic() =
255-
FunctionResponse(
256-
name,
257-
response,
258-
)
259-
260251
internal fun com.google.firebase.vertexai.common.server.CitationSources.toPublic(): Citation {
261252
val publicationDateAsCalendar =
262253
publicationDate?.let {

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package com.google.firebase.vertexai.type
1818

1919
import android.graphics.Bitmap
20-
import kotlinx.serialization.json.JsonElement
21-
import kotlinx.serialization.json.JsonObject
20+
import org.json.JSONObject
2221

2322
/** Interface representing data sent to and received from requests. */
2423
public interface Part
@@ -44,35 +43,20 @@ public class ImagePart(public val image: Bitmap) : Part
4443
public class InlineDataPart(public val inlineData: ByteArray, public val mimeType: String) : Part
4544

4645
/**
47-
* Represents a function call request from the model
48-
*
49-
* @param functionCall The information provided by the model to call a function.
50-
*/
51-
public class FunctionCallPart(public val functionCall: FunctionCall) : Part
52-
53-
/**
54-
* The result of calling a function as requested by the model.
55-
*
56-
* @param functionResponse The information to send back to the model as the result of a functions
57-
* call.
58-
*/
59-
public class FunctionResponsePart(public val functionResponse: FunctionResponse) : Part
60-
61-
/**
62-
* The data necessary to invoke function [name] using the arguments [args].
46+
* Represents function call name and params received from requests.
6347
*
6448
* @param name the name of the function to call
6549
* @param args the function parameters and values as a [Map]
6650
*/
67-
public class FunctionCall(public val name: String, public val args: Map<String, JsonElement>)
51+
class FunctionCallPart(val name: String, val args: Map<String, JsonElement>) : Part
6852

6953
/**
70-
* The [response] generated after calling function [name].
54+
* Represents function call output to be returned to the model when it requests a function call.
7155
*
7256
* @param name the name of the called function
73-
* @param response the response produced by the function as a [JsonObject]
57+
* @param response the response produced by the function as a [JSONObject]
7458
*/
75-
public class FunctionResponse(public val name: String, public val response: JsonObject)
59+
class FunctionResponsePart(val name: String, val response: JsonObject) : Part
7660

7761
/**
7862
* Represents file data stored in Cloud Storage for Firebase, referenced by URI.

firebase-vertexai/src/test/java/com/google/firebase/vertexai/UnarySnapshotTests.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ internal class UnarySnapshotTests {
353353
val response = model.generateContent("prompt")
354354
val callPart = (response.candidates.first().content.parts.first() as FunctionCallPart)
355355

356-
callPart.functionCall.args["season"] shouldBe JsonPrimitive(null)
356+
callPart.args["season"] shouldBe null
357357
}
358358
}
359359

@@ -370,7 +370,7 @@ internal class UnarySnapshotTests {
370370
it.parts.first().shouldBeInstanceOf<FunctionCallPart>()
371371
}
372372

373-
callPart.functionCall.args["current"] shouldBe JsonPrimitive(true)
373+
callPart.args["current"] shouldBe "true"
374374
}
375375
}
376376

@@ -402,8 +402,8 @@ internal class UnarySnapshotTests {
402402
val response = model.generateContent("prompt")
403403
val callPart = response.functionCalls.shouldNotBeEmpty().first()
404404

405-
callPart.functionCall.name shouldBe "current_time"
406-
callPart.functionCall.args.isEmpty() shouldBe true
405+
callPart.name shouldBe "current_time"
406+
callPart.args.isEmpty() shouldBe true
407407
}
408408
}
409409

@@ -414,9 +414,9 @@ internal class UnarySnapshotTests {
414414
val response = model.generateContent("prompt")
415415
val callPart = response.functionCalls.shouldNotBeEmpty().first()
416416

417-
callPart.functionCall.name shouldBe "sum"
418-
callPart.functionCall.args["x"] shouldBe JsonPrimitive(4)
419-
callPart.functionCall.args["y"] shouldBe JsonPrimitive(5)
417+
callPart.name shouldBe "sum"
418+
callPart.args["x"] shouldBe "4"
419+
callPart.args["y"] shouldBe "5"
420420
}
421421
}
422422

@@ -429,8 +429,8 @@ internal class UnarySnapshotTests {
429429

430430
callList.size shouldBe 3
431431
callList.forEach {
432-
it.functionCall.name shouldBe "sum"
433-
it.functionCall.args.size shouldBe 2
432+
it.name shouldBe "sum"
433+
it.args.size shouldBe 2
434434
}
435435
}
436436
}
@@ -444,7 +444,7 @@ internal class UnarySnapshotTests {
444444

445445
response.text shouldBe "The sum of [1, 2, 3] is"
446446
callList.size shouldBe 2
447-
callList.forEach { it.functionCall.args.size shouldBe 2 }
447+
callList.forEach { it.args.size shouldBe 2 }
448448
}
449449
}
450450

0 commit comments

Comments
 (0)