@@ -10,6 +10,7 @@ import com.openai.core.ClientOptions
10
10
import com.openai.core.Timeout
11
11
import com.openai.core.http.Headers
12
12
import com.openai.core.http.QueryParams
13
+ import com.openai.core.jsonMapper
13
14
import com.openai.credential.Credential
14
15
import java.net.Proxy
15
16
import java.time.Clock
@@ -32,10 +33,9 @@ class OpenAIOkHttpClientAsync private constructor() {
32
33
class Builder internal constructor() {
33
34
34
35
private var clientOptions: ClientOptions .Builder = ClientOptions .builder()
35
- private var timeout: Timeout = Timeout .default()
36
36
private var proxy: Proxy ? = null
37
37
38
- fun baseUrl ( baseUrl : String ) = apply { clientOptions.baseUrl(baseUrl) }
38
+ fun proxy ( proxy : Proxy ) = apply { this .proxy = proxy }
39
39
40
40
/* *
41
41
* Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -56,6 +56,54 @@ class OpenAIOkHttpClientAsync private constructor() {
56
56
57
57
fun clock (clock : Clock ) = apply { clientOptions.clock(clock) }
58
58
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
+
59
107
fun headers (headers : Headers ) = apply { clientOptions.headers(headers) }
60
108
61
109
fun headers (headers : Map <String , Iterable <String >>) = apply {
@@ -136,54 +184,6 @@ class OpenAIOkHttpClientAsync private constructor() {
136
184
clientOptions.removeAllQueryParams(keys)
137
185
}
138
186
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
-
187
187
fun fromEnv () = apply { clientOptions.fromEnv() }
188
188
189
189
/* *
@@ -194,7 +194,9 @@ class OpenAIOkHttpClientAsync private constructor() {
194
194
fun build (): OpenAIClientAsync =
195
195
OpenAIClientAsyncImpl (
196
196
clientOptions
197
- .httpClient(OkHttpClient .builder().timeout(timeout).proxy(proxy).build())
197
+ .httpClient(
198
+ OkHttpClient .builder().timeout(clientOptions.timeout()).proxy(proxy).build()
199
+ )
198
200
.build()
199
201
)
200
202
}
0 commit comments