From 52dd95db76b21367cce01ce129f2fd71748af5ab Mon Sep 17 00:00:00 2001 From: Daymon Date: Thu, 8 Feb 2024 13:06:49 -0600 Subject: [PATCH] Support Java --- .../client/generativeai/type/RequestOptions.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/type/RequestOptions.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/type/RequestOptions.kt index fa5da553..cc9669d9 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/type/RequestOptions.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/type/RequestOptions.kt @@ -18,7 +18,8 @@ package com.google.ai.client.generativeai.type import io.ktor.client.plugins.HttpTimeout import kotlin.time.Duration -import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.DurationUnit +import kotlin.time.toDuration /** * Configurable options unique to how requests to the backend are performed. @@ -27,7 +28,13 @@ import kotlin.time.Duration.Companion.milliseconds * first response. * @property apiVersion the api endpoint to call. */ -class RequestOptions( - val timeout: Duration = HttpTimeout.INFINITE_TIMEOUT_MS.milliseconds, - val apiVersion: String = "v1" -) +class RequestOptions(val timeout: Duration, val apiVersion: String = "v1") { + @JvmOverloads + constructor( + timeout: Long? = HttpTimeout.INFINITE_TIMEOUT_MS, + apiVersion: String = "v1" + ) : this( + (timeout ?: HttpTimeout.INFINITE_TIMEOUT_MS).toDuration(DurationUnit.MILLISECONDS), + apiVersion + ) +}