Skip to content

Commit f47f295

Browse files
committed
Fix issues from revert call
1 parent ba49350 commit f47f295

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ internal fun Part.toInternal(): com.google.firebase.vertexai.common.shared.Part
8282
InlineData(mimeType, Base64.encodeToString(inlineData, BASE_64_FLAGS))
8383
)
8484
is com.google.firebase.vertexai.type.FunctionCallPart ->
85-
FunctionCallPart(FunctionCall(name, args.orEmpty()))
85+
FunctionCallPart(FunctionCall(name, args))
8686
is com.google.firebase.vertexai.type.FunctionResponsePart ->
87-
FunctionResponsePart(FunctionResponse(name, response.toInternal()))
87+
FunctionResponsePart(FunctionResponse(name, response))
8888
is FileDataPart ->
8989
com.google.firebase.vertexai.common.shared.FileDataPart(
9090
FileData(mimeType = mimeType, fileUri = uri)
@@ -232,12 +232,12 @@ internal fun com.google.firebase.vertexai.common.shared.Part.toPublic(): Part {
232232
is FunctionCallPart ->
233233
com.google.firebase.vertexai.type.FunctionCallPart(
234234
functionCall.name,
235-
functionCall.args.orEmpty(),
235+
functionCall.args.orEmpty().mapValues { it.value ?: JsonNull }
236236
)
237237
is FunctionResponsePart ->
238238
com.google.firebase.vertexai.type.FunctionResponsePart(
239239
functionResponse.name,
240-
functionResponse.response.toPublic(),
240+
functionResponse.response,
241241
)
242242
is com.google.firebase.vertexai.common.shared.FileDataPart ->
243243
FileDataPart(fileData.mimeType, fileData.fileUri)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
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
2022
import org.json.JSONObject
2123

2224
/** Interface representing data sent to and received from requests. */
@@ -48,15 +50,16 @@ public class InlineDataPart(public val inlineData: ByteArray, public val mimeTyp
4850
* @param name the name of the function to call
4951
* @param args the function parameters and values as a [Map]
5052
*/
51-
class FunctionCallPart(val name: String, val args: Map<String, JsonElement>) : Part
53+
public class FunctionCallPart(public val name: String, public val args: Map<String, JsonElement>) :
54+
Part
5255

5356
/**
5457
* Represents function call output to be returned to the model when it requests a function call.
5558
*
5659
* @param name the name of the called function
5760
* @param response the response produced by the function as a [JSONObject]
5861
*/
59-
class FunctionResponsePart(val name: String, val response: JsonObject) : Part
62+
public class FunctionResponsePart(public val name: String, public val response: JsonObject) : Part
6063

6164
/**
6265
* 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: 7 additions & 9 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.args["season"] shouldBe null
356+
callPart.args["season"] shouldBe JsonPrimitive(null)
357357
}
358358
}
359359

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

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

@@ -387,11 +387,9 @@ internal class UnarySnapshotTests {
387387
it.parts.first().shouldBeInstanceOf<FunctionCallPart>()
388388
}
389389

390-
callPart.functionCall.args["current"] shouldBe JsonPrimitive(true)
391-
callPart.functionCall.args["testObject"]!!
392-
.jsonObject["testProperty"]!!
393-
.jsonPrimitive
394-
.content shouldBe "string property"
390+
callPart.args["current"] shouldBe JsonPrimitive(true)
391+
callPart.args["testObject"]!!.jsonObject["testProperty"]!!.jsonPrimitive.content shouldBe
392+
"string property"
395393
}
396394
}
397395

@@ -415,8 +413,8 @@ internal class UnarySnapshotTests {
415413
val callPart = response.functionCalls.shouldNotBeEmpty().first()
416414

417415
callPart.name shouldBe "sum"
418-
callPart.args["x"] shouldBe "4"
419-
callPart.args["y"] shouldBe "5"
416+
callPart.args["x"] shouldBe JsonPrimitive(4)
417+
callPart.args["y"] shouldBe JsonPrimitive(5)
420418
}
421419
}
422420

0 commit comments

Comments
 (0)