Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into TestModernization3
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe committed Oct 2, 2024
2 parents 7587b84 + 2d3e414 commit b2acdc6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ public boolean didCrashOnPreviousExecution() {
* @return In order of priority:
* <ul>
* <li>If {@link #setCrashlyticsCollectionEnabled(boolean)} is called with a value, use it.
* <li>If the <b>firebase_crashlytics_collection_enabled</b> key is in your app’s
* AndroidManifest.xml, use it.
* <li>If the <b>firebase_crashlytics_collection_enabled</b> key is in your app’s {@code
* AndroidManifest.xml}, use it.
* <li>Otherwise, use the default {@link FirebaseApp#isDataCollectionDefaultEnabled()} in
* FirebaseApp.
* {@link FirebaseApp}.
* </ul>
*/
public boolean isCrashlyticsCollectionEnabled() {
Expand All @@ -454,8 +454,8 @@ public boolean isCrashlyticsCollectionEnabled() {
/**
* Enables or disables the automatic data collection configuration for Crashlytics.
*
* <p>If this is set, it overrides any automatic data collection settings configured in the
* AndroidManifest.xml as well as any Firebase-wide settings.
* <p>If this is set, it overrides any automatic data collection settings configured in the {@code
* AndroidManifest.xml} as well as any Firebase-wide settings.
*
* <p>If automatic data collection is disabled for Crashlytics, crash reports are stored on the
* device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link
Expand All @@ -466,7 +466,7 @@ public boolean isCrashlyticsCollectionEnabled() {
* @param enabled whether to enable automatic data collection. When set to {@code false}, the new
* value does not apply until the next run of the app. To disable data collection by default
* for all app runs, add the {@code firebase_crashlytics_collection_enabled} flag to your
* app's AndroidManifest.xml.
* app's {@code AndroidManifest.xml}.
*/
public void setCrashlyticsCollectionEnabled(boolean enabled) {
core.setCrashlyticsCollectionEnabled(enabled);
Expand All @@ -475,9 +475,9 @@ public void setCrashlyticsCollectionEnabled(boolean enabled) {
/**
* Enables or disables the automatic data collection configuration for Crashlytics.
*
* <p>If this is set, it overrides any automatic data collection settings configured in the
* AndroidManifest.xml as well as any Firebase-wide settings. If set to {@code null}, the override
* is cleared.
* <p>If this is set, it overrides any automatic data collection settings configured in the {@code
* AndroidManifest.xml} as well as any Firebase-wide settings. If set to {@code null}, the
* override is cleared.
*
* <p>If automatic data collection is disabled for Crashlytics, crash reports are stored on the
* device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link
Expand All @@ -488,7 +488,7 @@ public void setCrashlyticsCollectionEnabled(boolean enabled) {
* @param enabled whether to enable or disable automatic data collection. When set to {@code
* false}, the new value does not apply until the next run of the app. When set to {@code
* null}, the override is cleared and automatic data collection settings are determined by the
* configuration in your AndroidManifest.xml or other Firebase-wide settings.
* configuration in your {@code AndroidManifest.xml} or other Firebase-wide settings.
*/
public void setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) {
core.setCrashlyticsCollectionEnabled(enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal data class FunctionResponsePart(val functionResponse: FunctionResponse)
@Serializable internal data class FunctionResponse(val name: String, val response: JsonObject)

@Serializable
internal data class FunctionCall(val name: String, val args: Map<String, String?>? = null)
internal data class FunctionCall(val name: String, val args: Map<String, JsonElement?>? = null)

@Serializable
internal data class FileDataPart(@SerialName("file_data") val fileData: FileData) : Part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import com.google.firebase.vertexai.type.content
import java.io.ByteArrayOutputStream
import java.util.Calendar
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import org.json.JSONObject

private const val BASE_64_FLAGS = Base64.NO_WRAP
Expand Down Expand Up @@ -97,10 +97,7 @@ internal fun Part.toInternal(): com.google.firebase.vertexai.common.shared.Part
}

internal fun FunctionCall.toInternal() =
com.google.firebase.vertexai.common.shared.FunctionCall(
name,
args.orEmpty().mapValues { it.value.toString() }
)
com.google.firebase.vertexai.common.shared.FunctionCall(name, args)

internal fun FunctionResponse.toInternal() =
com.google.firebase.vertexai.common.shared.FunctionResponse(name, response)
Expand Down Expand Up @@ -237,13 +234,7 @@ internal fun com.google.firebase.vertexai.common.shared.Part.toPublic(): Part {
}

internal fun com.google.firebase.vertexai.common.shared.FunctionCall.toPublic() =
FunctionCall(
name,
args.orEmpty().mapValues {
val argValue = it.value
if (argValue == null) JsonPrimitive(null) else Json.parseToJsonElement(argValue)
}
)
FunctionCall(name, args.orEmpty().mapValues { it.value ?: JsonNull })

internal fun com.google.firebase.vertexai.common.shared.FunctionResponse.toPublic() =
FunctionResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import io.ktor.http.HttpStatusCode
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.withTimeout
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.json.JSONArray
import org.junit.Test

Expand Down Expand Up @@ -372,6 +374,27 @@ internal class UnarySnapshotTests {
}
}

@Test
fun `function call with complex json literal parses correctly`() =
goldenUnaryFile("unary-success-function-call-complex-json-literal.json") {
withTimeout(testTimeout) {
val response = model.generateContent("prompt")
val content = response.candidates.shouldNotBeNullOrEmpty().first().content
val callPart =
content.let {
it.shouldNotBeNull()
it.parts.shouldNotBeEmpty()
it.parts.first().shouldBeInstanceOf<FunctionCallPart>()
}

callPart.functionCall.args["current"] shouldBe JsonPrimitive(true)
callPart.functionCall.args["testObject"]!!
.jsonObject["testProperty"]!!
.jsonPrimitive
.content shouldBe "string property"
}
}

@Test
fun `function call contains no arguments`() =
goldenUnaryFile("unary-success-function-call-no-arguments.json") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import io.ktor.http.HttpStatusCode
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.withTimeout
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonPrimitive
import org.junit.Test

@Serializable internal data class MountainColors(val name: String, val colors: List<String>)
Expand Down Expand Up @@ -330,7 +331,7 @@ internal class UnarySnapshotTests {
}

callPart.functionCall.args shouldNotBe null
callPart.functionCall.args?.get("current") shouldBe "true"
callPart.functionCall.args?.get("current") shouldBe JsonPrimitive(true)
}
}

Expand Down

0 comments on commit b2acdc6

Please sign in to comment.