Skip to content

Commit 3597aee

Browse files
chore(internal): codegen related update
1 parent c87f1af commit 3597aee

File tree

157 files changed

+2239
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+2239
-12
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ See this table for the available options:
132132
> Don't create more than one client in the same application. Each client has a connection pool and
133133
> thread pools, which are more efficient to share between requests.
134134
135+
### Modifying configuration
136+
137+
To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service:
138+
139+
```java
140+
import com.openai.client.OpenAIClient;
141+
142+
OpenAIClient clientWithOptions = client.withOptions(optionsBuilder -> {
143+
optionsBuilder.baseUrl("https://example.com");
144+
optionsBuilder.maxRetries(42);
145+
});
146+
```
147+
148+
The `withOptions()` method does not affect the original client or service.
149+
135150
## Requests and responses
136151

137152
To send a request to the OpenAI API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class.

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package com.openai.client
44

5+
import com.openai.core.ClientOptions
56
import com.openai.services.blocking.AudioService
67
import com.openai.services.blocking.BatchService
78
import com.openai.services.blocking.BetaService
@@ -19,6 +20,7 @@ import com.openai.services.blocking.ModerationService
1920
import com.openai.services.blocking.ResponseService
2021
import com.openai.services.blocking.UploadService
2122
import com.openai.services.blocking.VectorStoreService
23+
import java.util.function.Consumer
2224

2325
/**
2426
* A client for interacting with the OpenAI REST API synchronously. You can also switch to
@@ -49,6 +51,13 @@ interface OpenAIClient {
4951
*/
5052
fun withRawResponse(): WithRawResponse
5153

54+
/**
55+
* Returns a view of this service with the given option modifications applied.
56+
*
57+
* The original service is not modified.
58+
*/
59+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): OpenAIClient
60+
5261
fun completions(): CompletionService
5362

5463
fun chat(): ChatService
@@ -99,6 +108,13 @@ interface OpenAIClient {
99108
/** A view of [OpenAIClient] that provides access to raw HTTP responses for each method. */
100109
interface WithRawResponse {
101110

111+
/**
112+
* Returns a view of this service with the given option modifications applied.
113+
*
114+
* The original service is not modified.
115+
*/
116+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): OpenAIClient.WithRawResponse
117+
102118
fun completions(): CompletionService.WithRawResponse
103119

104120
fun chat(): ChatService.WithRawResponse

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package com.openai.client
44

5+
import com.openai.core.ClientOptions
56
import com.openai.services.async.AudioServiceAsync
67
import com.openai.services.async.BatchServiceAsync
78
import com.openai.services.async.BetaServiceAsync
@@ -19,6 +20,7 @@ import com.openai.services.async.ModerationServiceAsync
1920
import com.openai.services.async.ResponseServiceAsync
2021
import com.openai.services.async.UploadServiceAsync
2122
import com.openai.services.async.VectorStoreServiceAsync
23+
import java.util.function.Consumer
2224

2325
/**
2426
* A client for interacting with the OpenAI REST API asynchronously. You can also switch to
@@ -49,6 +51,13 @@ interface OpenAIClientAsync {
4951
*/
5052
fun withRawResponse(): WithRawResponse
5153

54+
/**
55+
* Returns a view of this service with the given option modifications applied.
56+
*
57+
* The original service is not modified.
58+
*/
59+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): OpenAIClientAsync
60+
5261
fun completions(): CompletionServiceAsync
5362

5463
fun chat(): ChatServiceAsync
@@ -99,6 +108,15 @@ interface OpenAIClientAsync {
99108
/** A view of [OpenAIClientAsync] that provides access to raw HTTP responses for each method. */
100109
interface WithRawResponse {
101110

111+
/**
112+
* Returns a view of this service with the given option modifications applied.
113+
*
114+
* The original service is not modified.
115+
*/
116+
fun withOptions(
117+
modifier: Consumer<ClientOptions.Builder>
118+
): OpenAIClientAsync.WithRawResponse
119+
102120
fun completions(): CompletionServiceAsync.WithRawResponse
103121

104122
fun chat(): ChatServiceAsync.WithRawResponse

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.openai.services.async.UploadServiceAsync
3838
import com.openai.services.async.UploadServiceAsyncImpl
3939
import com.openai.services.async.VectorStoreServiceAsync
4040
import com.openai.services.async.VectorStoreServiceAsyncImpl
41+
import java.util.function.Consumer
4142

4243
class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAIClientAsync {
4344

@@ -120,6 +121,9 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
120121

121122
override fun withRawResponse(): OpenAIClientAsync.WithRawResponse = withRawResponse
122123

124+
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): OpenAIClientAsync =
125+
OpenAIClientAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
126+
123127
override fun completions(): CompletionServiceAsync = completions
124128

125129
override fun chat(): ChatServiceAsync = chat
@@ -227,6 +231,13 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
227231
ContainerServiceAsyncImpl.WithRawResponseImpl(clientOptions)
228232
}
229233

234+
override fun withOptions(
235+
modifier: Consumer<ClientOptions.Builder>
236+
): OpenAIClientAsync.WithRawResponse =
237+
OpenAIClientAsyncImpl.WithRawResponseImpl(
238+
clientOptions.toBuilder().apply(modifier::accept).build()
239+
)
240+
230241
override fun completions(): CompletionServiceAsync.WithRawResponse = completions
231242

232243
override fun chat(): ChatServiceAsync.WithRawResponse = chat

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.openai.services.blocking.UploadService
3838
import com.openai.services.blocking.UploadServiceImpl
3939
import com.openai.services.blocking.VectorStoreService
4040
import com.openai.services.blocking.VectorStoreServiceImpl
41+
import java.util.function.Consumer
4142

4243
class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient {
4344

@@ -108,6 +109,9 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
108109

109110
override fun withRawResponse(): OpenAIClient.WithRawResponse = withRawResponse
110111

112+
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): OpenAIClient =
113+
OpenAIClientImpl(clientOptions.toBuilder().apply(modifier::accept).build())
114+
111115
override fun completions(): CompletionService = completions
112116

113117
override fun chat(): ChatService = chat
@@ -215,6 +219,13 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
215219
ContainerServiceImpl.WithRawResponseImpl(clientOptions)
216220
}
217221

222+
override fun withOptions(
223+
modifier: Consumer<ClientOptions.Builder>
224+
): OpenAIClient.WithRawResponse =
225+
OpenAIClientImpl.WithRawResponseImpl(
226+
clientOptions.toBuilder().apply(modifier::accept).build()
227+
)
228+
218229
override fun completions(): CompletionService.WithRawResponse = completions
219230

220231
override fun chat(): ChatService.WithRawResponse = chat

openai-java-core/src/main/kotlin/com/openai/services/async/AudioServiceAsync.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
package com.openai.services.async
44

5+
import com.openai.core.ClientOptions
56
import com.openai.services.async.audio.SpeechServiceAsync
67
import com.openai.services.async.audio.TranscriptionServiceAsync
78
import com.openai.services.async.audio.TranslationServiceAsync
9+
import java.util.function.Consumer
810

911
interface AudioServiceAsync {
1012

@@ -13,6 +15,13 @@ interface AudioServiceAsync {
1315
*/
1416
fun withRawResponse(): WithRawResponse
1517

18+
/**
19+
* Returns a view of this service with the given option modifications applied.
20+
*
21+
* The original service is not modified.
22+
*/
23+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): AudioServiceAsync
24+
1625
fun transcriptions(): TranscriptionServiceAsync
1726

1827
fun translations(): TranslationServiceAsync
@@ -22,6 +31,15 @@ interface AudioServiceAsync {
2231
/** A view of [AudioServiceAsync] that provides access to raw HTTP responses for each method. */
2332
interface WithRawResponse {
2433

34+
/**
35+
* Returns a view of this service with the given option modifications applied.
36+
*
37+
* The original service is not modified.
38+
*/
39+
fun withOptions(
40+
modifier: Consumer<ClientOptions.Builder>
41+
): AudioServiceAsync.WithRawResponse
42+
2543
fun transcriptions(): TranscriptionServiceAsync.WithRawResponse
2644

2745
fun translations(): TranslationServiceAsync.WithRawResponse

openai-java-core/src/main/kotlin/com/openai/services/async/AudioServiceAsyncImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.openai.services.async.audio.TranscriptionServiceAsync
99
import com.openai.services.async.audio.TranscriptionServiceAsyncImpl
1010
import com.openai.services.async.audio.TranslationServiceAsync
1111
import com.openai.services.async.audio.TranslationServiceAsyncImpl
12+
import java.util.function.Consumer
1213

1314
class AudioServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) :
1415
AudioServiceAsync {
@@ -29,6 +30,9 @@ class AudioServiceAsyncImpl internal constructor(private val clientOptions: Clie
2930

3031
override fun withRawResponse(): AudioServiceAsync.WithRawResponse = withRawResponse
3132

33+
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): AudioServiceAsync =
34+
AudioServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
35+
3236
override fun transcriptions(): TranscriptionServiceAsync = transcriptions
3337

3438
override fun translations(): TranslationServiceAsync = translations
@@ -50,6 +54,13 @@ class AudioServiceAsyncImpl internal constructor(private val clientOptions: Clie
5054
SpeechServiceAsyncImpl.WithRawResponseImpl(clientOptions)
5155
}
5256

57+
override fun withOptions(
58+
modifier: Consumer<ClientOptions.Builder>
59+
): AudioServiceAsync.WithRawResponse =
60+
AudioServiceAsyncImpl.WithRawResponseImpl(
61+
clientOptions.toBuilder().apply(modifier::accept).build()
62+
)
63+
5364
override fun transcriptions(): TranscriptionServiceAsync.WithRawResponse = transcriptions
5465

5566
override fun translations(): TranslationServiceAsync.WithRawResponse = translations

openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsync.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package com.openai.services.async
44

5+
import com.openai.core.ClientOptions
56
import com.openai.core.RequestOptions
67
import com.openai.core.http.HttpResponseFor
78
import com.openai.models.batches.Batch
@@ -11,6 +12,7 @@ import com.openai.models.batches.BatchListPageAsync
1112
import com.openai.models.batches.BatchListParams
1213
import com.openai.models.batches.BatchRetrieveParams
1314
import java.util.concurrent.CompletableFuture
15+
import java.util.function.Consumer
1416

1517
interface BatchServiceAsync {
1618

@@ -19,6 +21,13 @@ interface BatchServiceAsync {
1921
*/
2022
fun withRawResponse(): WithRawResponse
2123

24+
/**
25+
* Returns a view of this service with the given option modifications applied.
26+
*
27+
* The original service is not modified.
28+
*/
29+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BatchServiceAsync
30+
2231
/** Creates and executes a batch from an uploaded file of requests */
2332
fun create(params: BatchCreateParams): CompletableFuture<Batch> =
2433
create(params, RequestOptions.none())
@@ -118,6 +127,15 @@ interface BatchServiceAsync {
118127
/** A view of [BatchServiceAsync] that provides access to raw HTTP responses for each method. */
119128
interface WithRawResponse {
120129

130+
/**
131+
* Returns a view of this service with the given option modifications applied.
132+
*
133+
* The original service is not modified.
134+
*/
135+
fun withOptions(
136+
modifier: Consumer<ClientOptions.Builder>
137+
): BatchServiceAsync.WithRawResponse
138+
121139
/**
122140
* Returns a raw HTTP response for `post /batches`, but is otherwise the same as
123141
* [BatchServiceAsync.create].

openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsyncImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.openai.models.batches.BatchListPageResponse
2424
import com.openai.models.batches.BatchListParams
2525
import com.openai.models.batches.BatchRetrieveParams
2626
import java.util.concurrent.CompletableFuture
27+
import java.util.function.Consumer
2728
import kotlin.jvm.optionals.getOrNull
2829

2930
class BatchServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) :
@@ -35,6 +36,9 @@ class BatchServiceAsyncImpl internal constructor(private val clientOptions: Clie
3536

3637
override fun withRawResponse(): BatchServiceAsync.WithRawResponse = withRawResponse
3738

39+
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): BatchServiceAsync =
40+
BatchServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
41+
3842
override fun create(
3943
params: BatchCreateParams,
4044
requestOptions: RequestOptions,
@@ -68,6 +72,13 @@ class BatchServiceAsyncImpl internal constructor(private val clientOptions: Clie
6872

6973
private val errorHandler: Handler<ErrorObject?> = errorHandler(clientOptions.jsonMapper)
7074

75+
override fun withOptions(
76+
modifier: Consumer<ClientOptions.Builder>
77+
): BatchServiceAsync.WithRawResponse =
78+
BatchServiceAsyncImpl.WithRawResponseImpl(
79+
clientOptions.toBuilder().apply(modifier::accept).build()
80+
)
81+
7182
private val createHandler: Handler<Batch> =
7283
jsonHandler<Batch>(clientOptions.jsonMapper).withErrorHandler(errorHandler)
7384

openai-java-core/src/main/kotlin/com/openai/services/async/BetaServiceAsync.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@
22

33
package com.openai.services.async
44

5+
import com.openai.core.ClientOptions
6+
import java.util.function.Consumer
7+
58
interface BetaServiceAsync {
69

710
/**
811
* Returns a view of this service that provides access to raw HTTP responses for each method.
912
*/
1013
fun withRawResponse(): WithRawResponse
1114

15+
/**
16+
* Returns a view of this service with the given option modifications applied.
17+
*
18+
* The original service is not modified.
19+
*/
20+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BetaServiceAsync
21+
1222
/** A view of [BetaServiceAsync] that provides access to raw HTTP responses for each method. */
13-
interface WithRawResponse
23+
interface WithRawResponse {
24+
25+
/**
26+
* Returns a view of this service with the given option modifications applied.
27+
*
28+
* The original service is not modified.
29+
*/
30+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): BetaServiceAsync.WithRawResponse
31+
}
1432
}

openai-java-core/src/main/kotlin/com/openai/services/async/BetaServiceAsyncImpl.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.openai.services.async
44

55
import com.openai.core.ClientOptions
6+
import java.util.function.Consumer
67

78
class BetaServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) :
89
BetaServiceAsync {
@@ -13,6 +14,17 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien
1314

1415
override fun withRawResponse(): BetaServiceAsync.WithRawResponse = withRawResponse
1516

17+
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): BetaServiceAsync =
18+
BetaServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
19+
1620
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
17-
BetaServiceAsync.WithRawResponse
21+
BetaServiceAsync.WithRawResponse {
22+
23+
override fun withOptions(
24+
modifier: Consumer<ClientOptions.Builder>
25+
): BetaServiceAsync.WithRawResponse =
26+
BetaServiceAsyncImpl.WithRawResponseImpl(
27+
clientOptions.toBuilder().apply(modifier::accept).build()
28+
)
29+
}
1830
}

0 commit comments

Comments
 (0)