Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal constructor(
APIController(
apiKey,
modelName,
requestOptions.toInternal(),
requestOptions,
"gl-kotlin/${KotlinVersion.CURRENT} fire/${BuildConfig.VERSION_NAME}",
object : HeaderProvider {
override val timeout: Duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.annotation.VisibleForTesting
import com.google.firebase.vertexai.common.server.FinishReason
import com.google.firebase.vertexai.common.util.decodeToFlow
import com.google.firebase.vertexai.common.util.fullModelName
import com.google.firebase.vertexai.type.RequestOptions
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.HttpClientEngine
Expand All @@ -44,7 +45,9 @@ import io.ktor.http.contentType
import io.ktor.http.headersOf
import io.ktor.serialization.kotlinx.json.json
import io.ktor.utils.io.ByteChannel
import kotlin.math.max
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -115,7 +118,8 @@ internal constructor(
HttpClient(httpEngine) {
install(HttpTimeout) {
requestTimeoutMillis = requestOptions.timeout.inWholeMilliseconds
socketTimeoutMillis = 80_000
socketTimeoutMillis =
max(180.seconds.inWholeMilliseconds, requestOptions.timeout.inWholeMilliseconds)
}
install(ContentNegotiation) { json(JSON) }
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import com.google.firebase.vertexai.type.HarmSeverity
import com.google.firebase.vertexai.type.ImagePart
import com.google.firebase.vertexai.type.Part
import com.google.firebase.vertexai.type.PromptFeedback
import com.google.firebase.vertexai.type.RequestOptions
import com.google.firebase.vertexai.type.SafetyRating
import com.google.firebase.vertexai.type.SafetySetting
import com.google.firebase.vertexai.type.SerializationException
Expand All @@ -63,9 +62,6 @@ import org.json.JSONObject

private const val BASE_64_FLAGS = Base64.NO_WRAP

internal fun RequestOptions.toInternal() =
com.google.firebase.vertexai.common.RequestOptions(timeout, apiVersion, endpoint)

internal fun Content.toInternal() =
com.google.firebase.vertexai.common.shared.Content(
this.role ?: "user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@
package com.google.firebase.vertexai.type

import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.toDuration

/**
* Configurable options unique to how requests to the backend are performed.
*
* @property timeout the maximum amount of time for a request to take, from the first request to
* first response.
* @property apiVersion the api endpoint to call.
*/
class RequestOptions(val timeout: Duration) {

internal val endpoint = "https://firebaseml.googleapis.com"
internal val apiVersion = "v2beta"
/** Configurable options unique to how requests to the backend are performed. */
class RequestOptions
internal constructor(
internal val timeout: Duration,
internal val endpoint: String = "https://firebaseml.googleapis.com",
internal val apiVersion: String = "v2beta",
) {

/**
* Constructor for RequestOptions.
*
* @param timeoutInMillis the maximum amount of time, in milliseconds, for a request to take, from
* the first request to first response.
*/
@JvmOverloads
constructor(
timeout: Long? = Long.MAX_VALUE,
) : this((timeout ?: Long.MAX_VALUE).toDuration(DurationUnit.MILLISECONDS))
timeoutInMillis: Long = 180.seconds.inWholeMilliseconds
) : this(timeout = timeoutInMillis.toDuration(DurationUnit.MILLISECONDS))
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.google.firebase.vertexai.common.util.commonTest
import com.google.firebase.vertexai.common.util.createResponses
import com.google.firebase.vertexai.common.util.doBlocking
import com.google.firebase.vertexai.common.util.prepareStreamingResponse
import com.google.firebase.vertexai.type.RequestOptions
import io.kotest.assertions.json.shouldContainJsonKey
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -107,7 +108,7 @@ internal class RequestFormatTests {
}
}

mockEngine.requestHistory.first().url.host shouldBe "generativelanguage.googleapis.com"
mockEngine.requestHistory.first().url.host shouldBe "firebaseml.googleapis.com"
}

@Test
Expand All @@ -121,7 +122,7 @@ internal class RequestFormatTests {
APIController(
"super_cool_test_key",
"gemini-pro-1.5",
RequestOptions(endpoint = "https://my.custom.endpoint"),
RequestOptions(timeout = 5.seconds, endpoint = "https://my.custom.endpoint"),
mockEngine,
TEST_CLIENT_ID,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import com.google.firebase.vertexai.common.APIController
import com.google.firebase.vertexai.common.GenerateContentRequest
import com.google.firebase.vertexai.common.GenerateContentResponse
import com.google.firebase.vertexai.common.JSON
import com.google.firebase.vertexai.common.RequestOptions
import com.google.firebase.vertexai.common.server.Candidate
import com.google.firebase.vertexai.common.shared.Content
import com.google.firebase.vertexai.common.shared.TextPart
import com.google.firebase.vertexai.type.RequestOptions
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.nulls.shouldNotBeNull
import io.ktor.http.HttpStatusCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.google.firebase.vertexai.util

import com.google.firebase.vertexai.GenerativeModel
import com.google.firebase.vertexai.common.APIController
import com.google.firebase.vertexai.common.RequestOptions
import com.google.firebase.vertexai.type.RequestOptions
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.nulls.shouldNotBeNull
import io.ktor.http.HttpStatusCode
Expand Down
Loading