@@ -10,6 +10,7 @@ import com.openai.core.ClientOptions
1010import com.openai.core.Timeout
1111import com.openai.core.http.Headers
1212import com.openai.core.http.QueryParams
13+ import com.openai.core.jsonMapper
1314import com.openai.credential.Credential
1415import java.net.Proxy
1516import java.time.Clock
@@ -32,10 +33,9 @@ class OpenAIOkHttpClientAsync private constructor() {
3233 class Builder internal constructor() {
3334
3435 private var clientOptions: ClientOptions .Builder = ClientOptions .builder()
35- private var timeout: Timeout = Timeout .default()
3636 private var proxy: Proxy ? = null
3737
38- fun baseUrl ( baseUrl : String ) = apply { clientOptions.baseUrl(baseUrl) }
38+ fun proxy ( proxy : Proxy ) = apply { this .proxy = proxy }
3939
4040 /* *
4141 * Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -56,6 +56,54 @@ class OpenAIOkHttpClientAsync private constructor() {
5656
5757 fun clock (clock : Clock ) = apply { clientOptions.clock(clock) }
5858
59+ fun baseUrl (baseUrl : String? ) = apply { clientOptions.baseUrl(baseUrl) }
60+
61+ /* * Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
62+ fun baseUrl (baseUrl : Optional <String >) = baseUrl(baseUrl.getOrNull())
63+
64+ fun responseValidation (responseValidation : Boolean ) = apply {
65+ clientOptions.responseValidation(responseValidation)
66+ }
67+
68+ fun timeout (timeout : Timeout ) = apply { clientOptions.timeout(timeout) }
69+
70+ /* *
71+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
72+ *
73+ * See [Timeout.request] for more details.
74+ *
75+ * For fine-grained control, pass a [Timeout] object.
76+ */
77+ fun timeout (timeout : Duration ) = apply { clientOptions.timeout(timeout) }
78+
79+ fun maxRetries (maxRetries : Int ) = apply { clientOptions.maxRetries(maxRetries) }
80+
81+ fun apiKey (apiKey : String ) = apply { clientOptions.apiKey(apiKey) }
82+
83+ fun credential (credential : Credential ) = apply { clientOptions.credential(credential) }
84+
85+ fun azureServiceVersion (azureServiceVersion : AzureOpenAIServiceVersion ) = apply {
86+ clientOptions.azureServiceVersion(azureServiceVersion)
87+ }
88+
89+ fun organization (organization : String? ) = apply { clientOptions.organization(organization) }
90+
91+ /* * Alias for calling [Builder.organization] with `organization.orElse(null)`. */
92+ fun organization (organization : Optional <String >) = organization(organization.getOrNull())
93+
94+ fun project (project : String? ) = apply { clientOptions.project(project) }
95+
96+ /* * Alias for calling [Builder.project] with `project.orElse(null)`. */
97+ fun project (project : Optional <String >) = project(project.getOrNull())
98+
99+ fun webhookSecret (webhookSecret : String? ) = apply {
100+ clientOptions.webhookSecret(webhookSecret)
101+ }
102+
103+ /* * Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
104+ fun webhookSecret (webhookSecret : Optional <String >) =
105+ webhookSecret(webhookSecret.getOrNull())
106+
59107 fun headers (headers : Headers ) = apply { clientOptions.headers(headers) }
60108
61109 fun headers (headers : Map <String , Iterable <String >>) = apply {
@@ -136,54 +184,6 @@ class OpenAIOkHttpClientAsync private constructor() {
136184 clientOptions.removeAllQueryParams(keys)
137185 }
138186
139- fun timeout (timeout : Timeout ) = apply {
140- clientOptions.timeout(timeout)
141- this .timeout = timeout
142- }
143-
144- /* *
145- * Sets the maximum time allowed for a complete HTTP call, not including retries.
146- *
147- * See [Timeout.request] for more details.
148- *
149- * For fine-grained control, pass a [Timeout] object.
150- */
151- fun timeout (timeout : Duration ) = timeout(Timeout .builder().request(timeout).build())
152-
153- fun maxRetries (maxRetries : Int ) = apply { clientOptions.maxRetries(maxRetries) }
154-
155- fun proxy (proxy : Proxy ) = apply { this .proxy = proxy }
156-
157- fun responseValidation (responseValidation : Boolean ) = apply {
158- clientOptions.responseValidation(responseValidation)
159- }
160-
161- fun apiKey (apiKey : String ) = apply { clientOptions.apiKey(apiKey) }
162-
163- fun credential (credential : Credential ) = apply { clientOptions.credential(credential) }
164-
165- fun azureServiceVersion (azureServiceVersion : AzureOpenAIServiceVersion ) = apply {
166- clientOptions.azureServiceVersion(azureServiceVersion)
167- }
168-
169- fun organization (organization : String? ) = apply { clientOptions.organization(organization) }
170-
171- /* * Alias for calling [Builder.organization] with `organization.orElse(null)`. */
172- fun organization (organization : Optional <String >) = organization(organization.getOrNull())
173-
174- fun project (project : String? ) = apply { clientOptions.project(project) }
175-
176- /* * Alias for calling [Builder.project] with `project.orElse(null)`. */
177- fun project (project : Optional <String >) = project(project.getOrNull())
178-
179- fun webhookSecret (webhookSecret : String? ) = apply {
180- clientOptions.webhookSecret(webhookSecret)
181- }
182-
183- /* * Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
184- fun webhookSecret (webhookSecret : Optional <String >) =
185- webhookSecret(webhookSecret.getOrNull())
186-
187187 fun fromEnv () = apply { clientOptions.fromEnv() }
188188
189189 /* *
@@ -194,7 +194,9 @@ class OpenAIOkHttpClientAsync private constructor() {
194194 fun build (): OpenAIClientAsync =
195195 OpenAIClientAsyncImpl (
196196 clientOptions
197- .httpClient(OkHttpClient .builder().timeout(timeout).proxy(proxy).build())
197+ .httpClient(
198+ OkHttpClient .builder().timeout(clientOptions.timeout()).proxy(proxy).build()
199+ )
198200 .build()
199201 )
200202 }
0 commit comments