diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4ef30715e..3ae04808a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -53,4 +53,25 @@ jobs:
- name: Run tests
run: ./scripts/test
+ examples:
+ name: examples
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Set up Java
+ uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: |
+ 8
+ 17
+ cache: gradle
+ - name: Set up Gradle
+ uses: gradle/gradle-build-action@v2
+ - env:
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
+ run: |
+ ./gradlew :openai-java-example:run
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 554e34bbe..f81bf9923 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.30.0"
+ ".": "0.31.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index e7dc5cc33..9790b6efb 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 65
+configured_endpoints: 72
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-5d30684c3118d049682ea30cdb4dbef39b97d51667da484689193dc40162af32.yml
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 941bb6a63..4b49c42c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,26 @@
# Changelog
+## 0.31.0 (2025-03-04)
+
+Full Changelog: [v0.30.0...v0.31.0](https://github.com/openai/openai-java/compare/v0.30.0...v0.31.0)
+
+### Features
+
+* **client:** add file upload endpoints ([#268](https://github.com/openai/openai-java/issues/268)) ([456274d](https://github.com/openai/openai-java/commit/456274d2dc572ad4711d2fc3640c7e01aa08f4b8))
+* **client:** allow configuring timeouts granularly ([#266](https://github.com/openai/openai-java/issues/266)) ([c3bc6e4](https://github.com/openai/openai-java/commit/c3bc6e4fb9717c7f6146f864ce3cc2451619c9f0))
+
+
+### Chores
+
+* **internal:** refactor `ErrorHandlingTest` ([#264](https://github.com/openai/openai-java/issues/264)) ([2472f85](https://github.com/openai/openai-java/commit/2472f859b49f49cf14539e787cf15e8f863f5dac))
+* **internal:** run example files in CI ([#271](https://github.com/openai/openai-java/issues/271)) ([8da7851](https://github.com/openai/openai-java/commit/8da785184c3e039ea4b9d2b26c6d14b607291750))
+
+
+### Documentation
+
+* add raw response readme documentation ([#269](https://github.com/openai/openai-java/issues/269)) ([2839903](https://github.com/openai/openai-java/commit/28399031c60eed8899475c5d1d38677c2eaa2284))
+* update URLs from stainlessapi.com to stainless.com ([#259](https://github.com/openai/openai-java/issues/259)) ([b824bf3](https://github.com/openai/openai-java/commit/b824bf39a44251e15c7c8b5b14bc6cbf9133dff5))
+
## 0.30.0 (2025-02-27)
Full Changelog: [v0.29.0...v0.30.0](https://github.com/openai/openai-java/compare/v0.29.0...v0.30.0)
diff --git a/README.md b/README.md
index f37bcbc53..f732fcf8d 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/0.30.0)
-[](https://javadoc.io/doc/com.openai/openai-java/0.30.0)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/0.31.0)
+[](https://javadoc.io/doc/com.openai/openai-java/0.31.0)
@@ -25,7 +25,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
### Gradle
```kotlin
-implementation("com.openai:openai-java:0.30.0")
+implementation("com.openai:openai-java:0.31.0")
```
### Maven
@@ -34,7 +34,7 @@ implementation("com.openai:openai-java:0.30.0")
com.openai
openai-java
- 0.30.0
+ 0.31.0
```
@@ -314,6 +314,37 @@ try (HttpResponse response = client.files().content(params)) {
}
```
+## Raw responses
+
+The SDK defines methods that deserialize responses into instances of Java classes. However, these methods don't provide access to the response headers, status code, or the raw response body.
+
+To access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:
+
+```java
+import com.openai.core.http.Headers;
+import com.openai.core.http.HttpResponseFor;
+import com.openai.models.ChatCompletion;
+import com.openai.models.ChatCompletionCreateParams;
+import com.openai.models.ChatModel;
+
+ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
+ .addUserMessage("Say this is a test")
+ .model(ChatModel.O3_MINI)
+ .build();
+HttpResponseFor chatCompletion = client.chat().completions().withRawResponse().create(params);
+
+int statusCode = chatCompletion.statusCode();
+Headers headers = chatCompletion.headers();
+```
+
+You can still deserialize the response into an instance of a Java class if needed:
+
+```java
+import com.openai.models.ChatCompletion;
+
+ChatCompletion parsedChatCompletion = chatCompletion.parse();
+```
+
## Error handling
The SDK throws custom unchecked exception types:
diff --git a/SECURITY.md b/SECURITY.md
index c54acaf33..3b3bd8a66 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -2,9 +2,9 @@
## Reporting Security Issues
-This SDK is generated by [Stainless Software Inc](http://stainlessapi.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
+This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
-To report a security issue, please contact the Stainless team at security@stainlessapi.com.
+To report a security issue, please contact the Stainless team at security@stainless.com.
## Responsible Disclosure
diff --git a/build.gradle.kts b/build.gradle.kts
index 52fd836f1..d91f6a4a8 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ repositories {
allprojects {
group = "com.openai"
- version = "0.30.0" // x-release-please-version
+ version = "0.31.0" // x-release-please-version
}
subprojects {
diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OkHttpClient.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OkHttpClient.kt
index 409bcf9de..8fc863a5c 100644
--- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OkHttpClient.kt
+++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OkHttpClient.kt
@@ -1,6 +1,7 @@
package com.openai.client.okhttp
import com.openai.core.RequestOptions
+import com.openai.core.Timeout
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.HttpClient
@@ -88,13 +89,12 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
)
}
- val timeout = requestOptions.timeout
- if (timeout != null) {
+ requestOptions.timeout?.let {
clientBuilder
- .connectTimeout(timeout)
- .readTimeout(timeout)
- .writeTimeout(timeout)
- .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
+ .connectTimeout(it.connect())
+ .readTimeout(it.read())
+ .writeTimeout(it.write())
+ .callTimeout(it.request())
}
val client = clientBuilder.build()
@@ -195,23 +195,24 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
class Builder internal constructor() {
private var baseUrl: HttpUrl? = null
- // The default timeout is 10 minutes.
- private var timeout: Duration = Duration.ofSeconds(600)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
fun build(): OkHttpClient =
OkHttpClient(
okhttp3.OkHttpClient.Builder()
- .connectTimeout(timeout)
- .readTimeout(timeout)
- .writeTimeout(timeout)
- .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
+ .connectTimeout(timeout.connect())
+ .readTimeout(timeout.read())
+ .writeTimeout(timeout.write())
+ .callTimeout(timeout.request())
.proxy(proxy)
.build(),
checkRequired("baseUrl", baseUrl),
diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt
index 41abe1c26..a0c4a83bc 100644
--- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt
+++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt
@@ -7,6 +7,7 @@ import com.openai.azure.AzureOpenAIServiceVersion
import com.openai.client.OpenAIClient
import com.openai.client.OpenAIClientImpl
import com.openai.core.ClientOptions
+import com.openai.core.Timeout
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
import com.openai.credential.Credential
@@ -30,8 +31,7 @@ class OpenAIOkHttpClient private constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
- // The default timeout for the client is 10 minutes.
- private var timeout: Duration = Duration.ofSeconds(600)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply {
@@ -127,7 +127,19 @@ class OpenAIOkHttpClient private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply {
+ clientOptions.timeout(timeout)
+ this.timeout = timeout
+ }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt
index 24b0d9ab5..13163b9fe 100644
--- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt
+++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt
@@ -7,6 +7,7 @@ import com.openai.azure.AzureOpenAIServiceVersion
import com.openai.client.OpenAIClientAsync
import com.openai.client.OpenAIClientAsyncImpl
import com.openai.core.ClientOptions
+import com.openai.core.Timeout
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
import com.openai.credential.Credential
@@ -30,8 +31,7 @@ class OpenAIOkHttpClientAsync private constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
- // The default timeout for the client is 10 minutes.
- private var timeout: Duration = Duration.ofSeconds(600)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply {
@@ -127,7 +127,19 @@ class OpenAIOkHttpClientAsync private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply {
+ clientOptions.timeout(timeout)
+ this.timeout = timeout
+ }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
index 7aa192b94..a1390a56f 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
@@ -2,6 +2,7 @@
package com.openai.client
+import com.openai.services.blocking.AudioService
import com.openai.services.blocking.BatchService
import com.openai.services.blocking.BetaService
import com.openai.services.blocking.ChatService
@@ -38,6 +39,11 @@ interface OpenAIClient {
*/
fun async(): OpenAIClientAsync
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
fun completions(): CompletionService
fun chat(): ChatService
@@ -48,6 +54,8 @@ interface OpenAIClient {
fun images(): ImageService
+ fun audio(): AudioService
+
fun moderations(): ModerationService
fun models(): ModelService
@@ -72,4 +80,32 @@ interface OpenAIClient {
* method.
*/
fun close()
+
+ /** A view of [OpenAIClient] that provides access to raw HTTP responses for each method. */
+ interface WithRawResponse {
+
+ fun completions(): CompletionService.WithRawResponse
+
+ fun chat(): ChatService.WithRawResponse
+
+ fun embeddings(): EmbeddingService.WithRawResponse
+
+ fun files(): FileService.WithRawResponse
+
+ fun images(): ImageService.WithRawResponse
+
+ fun audio(): AudioService.WithRawResponse
+
+ fun moderations(): ModerationService.WithRawResponse
+
+ fun models(): ModelService.WithRawResponse
+
+ fun fineTuning(): FineTuningService.WithRawResponse
+
+ fun beta(): BetaService.WithRawResponse
+
+ fun batches(): BatchService.WithRawResponse
+
+ fun uploads(): UploadService.WithRawResponse
+ }
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
index 1c1b63781..12679360b 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
@@ -2,6 +2,7 @@
package com.openai.client
+import com.openai.services.async.AudioServiceAsync
import com.openai.services.async.BatchServiceAsync
import com.openai.services.async.BetaServiceAsync
import com.openai.services.async.ChatServiceAsync
@@ -38,6 +39,11 @@ interface OpenAIClientAsync {
*/
fun sync(): OpenAIClient
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
fun completions(): CompletionServiceAsync
fun chat(): ChatServiceAsync
@@ -48,6 +54,8 @@ interface OpenAIClientAsync {
fun images(): ImageServiceAsync
+ fun audio(): AudioServiceAsync
+
fun moderations(): ModerationServiceAsync
fun models(): ModelServiceAsync
@@ -72,4 +80,32 @@ interface OpenAIClientAsync {
* method.
*/
fun close()
+
+ /** A view of [OpenAIClientAsync] that provides access to raw HTTP responses for each method. */
+ interface WithRawResponse {
+
+ fun completions(): CompletionServiceAsync.WithRawResponse
+
+ fun chat(): ChatServiceAsync.WithRawResponse
+
+ fun embeddings(): EmbeddingServiceAsync.WithRawResponse
+
+ fun files(): FileServiceAsync.WithRawResponse
+
+ fun images(): ImageServiceAsync.WithRawResponse
+
+ fun audio(): AudioServiceAsync.WithRawResponse
+
+ fun moderations(): ModerationServiceAsync.WithRawResponse
+
+ fun models(): ModelServiceAsync.WithRawResponse
+
+ fun fineTuning(): FineTuningServiceAsync.WithRawResponse
+
+ fun beta(): BetaServiceAsync.WithRawResponse
+
+ fun batches(): BatchServiceAsync.WithRawResponse
+
+ fun uploads(): UploadServiceAsync.WithRawResponse
+ }
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
index d69c816fc..cff9f827a 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
@@ -4,6 +4,8 @@ package com.openai.client
import com.openai.core.ClientOptions
import com.openai.core.getPackageVersion
+import com.openai.services.async.AudioServiceAsync
+import com.openai.services.async.AudioServiceAsyncImpl
import com.openai.services.async.BatchServiceAsync
import com.openai.services.async.BatchServiceAsyncImpl
import com.openai.services.async.BetaServiceAsync
@@ -40,6 +42,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
// Pass the original clientOptions so that this client sets its own User-Agent.
private val sync: OpenAIClient by lazy { OpenAIClientImpl(clientOptions) }
+ private val withRawResponse: OpenAIClientAsync.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
private val completions: CompletionServiceAsync by lazy {
CompletionServiceAsyncImpl(clientOptionsWithUserAgent)
}
@@ -56,6 +62,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
ImageServiceAsyncImpl(clientOptionsWithUserAgent)
}
+ private val audio: AudioServiceAsync by lazy {
+ AudioServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
private val moderations: ModerationServiceAsync by lazy {
ModerationServiceAsyncImpl(clientOptionsWithUserAgent)
}
@@ -80,6 +90,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
override fun sync(): OpenAIClient = sync
+ override fun withRawResponse(): OpenAIClientAsync.WithRawResponse = withRawResponse
+
override fun completions(): CompletionServiceAsync = completions
override fun chat(): ChatServiceAsync = chat
@@ -90,6 +102,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
override fun images(): ImageServiceAsync = images
+ override fun audio(): AudioServiceAsync = audio
+
override fun moderations(): ModerationServiceAsync = moderations
override fun models(): ModelServiceAsync = models
@@ -103,4 +117,80 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
override fun uploads(): UploadServiceAsync = uploads
override fun close() = clientOptions.httpClient.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ OpenAIClientAsync.WithRawResponse {
+
+ private val completions: CompletionServiceAsync.WithRawResponse by lazy {
+ CompletionServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val chat: ChatServiceAsync.WithRawResponse by lazy {
+ ChatServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val embeddings: EmbeddingServiceAsync.WithRawResponse by lazy {
+ EmbeddingServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val files: FileServiceAsync.WithRawResponse by lazy {
+ FileServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val images: ImageServiceAsync.WithRawResponse by lazy {
+ ImageServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val audio: AudioServiceAsync.WithRawResponse by lazy {
+ AudioServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val moderations: ModerationServiceAsync.WithRawResponse by lazy {
+ ModerationServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val models: ModelServiceAsync.WithRawResponse by lazy {
+ ModelServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val fineTuning: FineTuningServiceAsync.WithRawResponse by lazy {
+ FineTuningServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val beta: BetaServiceAsync.WithRawResponse by lazy {
+ BetaServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val batches: BatchServiceAsync.WithRawResponse by lazy {
+ BatchServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val uploads: UploadServiceAsync.WithRawResponse by lazy {
+ UploadServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun completions(): CompletionServiceAsync.WithRawResponse = completions
+
+ override fun chat(): ChatServiceAsync.WithRawResponse = chat
+
+ override fun embeddings(): EmbeddingServiceAsync.WithRawResponse = embeddings
+
+ override fun files(): FileServiceAsync.WithRawResponse = files
+
+ override fun images(): ImageServiceAsync.WithRawResponse = images
+
+ override fun audio(): AudioServiceAsync.WithRawResponse = audio
+
+ override fun moderations(): ModerationServiceAsync.WithRawResponse = moderations
+
+ override fun models(): ModelServiceAsync.WithRawResponse = models
+
+ override fun fineTuning(): FineTuningServiceAsync.WithRawResponse = fineTuning
+
+ override fun beta(): BetaServiceAsync.WithRawResponse = beta
+
+ override fun batches(): BatchServiceAsync.WithRawResponse = batches
+
+ override fun uploads(): UploadServiceAsync.WithRawResponse = uploads
+ }
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
index bc2e89270..4898af55f 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
@@ -4,6 +4,8 @@ package com.openai.client
import com.openai.core.ClientOptions
import com.openai.core.getPackageVersion
+import com.openai.services.blocking.AudioService
+import com.openai.services.blocking.AudioServiceImpl
import com.openai.services.blocking.BatchService
import com.openai.services.blocking.BatchServiceImpl
import com.openai.services.blocking.BetaService
@@ -40,6 +42,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
// Pass the original clientOptions so that this client sets its own User-Agent.
private val async: OpenAIClientAsync by lazy { OpenAIClientAsyncImpl(clientOptions) }
+ private val withRawResponse: OpenAIClient.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
private val completions: CompletionService by lazy {
CompletionServiceImpl(clientOptionsWithUserAgent)
}
@@ -54,6 +60,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
private val images: ImageService by lazy { ImageServiceImpl(clientOptionsWithUserAgent) }
+ private val audio: AudioService by lazy { AudioServiceImpl(clientOptionsWithUserAgent) }
+
private val moderations: ModerationService by lazy {
ModerationServiceImpl(clientOptionsWithUserAgent)
}
@@ -72,6 +80,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
override fun async(): OpenAIClientAsync = async
+ override fun withRawResponse(): OpenAIClient.WithRawResponse = withRawResponse
+
override fun completions(): CompletionService = completions
override fun chat(): ChatService = chat
@@ -82,6 +92,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
override fun images(): ImageService = images
+ override fun audio(): AudioService = audio
+
override fun moderations(): ModerationService = moderations
override fun models(): ModelService = models
@@ -95,4 +107,80 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
override fun uploads(): UploadService = uploads
override fun close() = clientOptions.httpClient.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ OpenAIClient.WithRawResponse {
+
+ private val completions: CompletionService.WithRawResponse by lazy {
+ CompletionServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val chat: ChatService.WithRawResponse by lazy {
+ ChatServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val embeddings: EmbeddingService.WithRawResponse by lazy {
+ EmbeddingServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val files: FileService.WithRawResponse by lazy {
+ FileServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val images: ImageService.WithRawResponse by lazy {
+ ImageServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val audio: AudioService.WithRawResponse by lazy {
+ AudioServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val moderations: ModerationService.WithRawResponse by lazy {
+ ModerationServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val models: ModelService.WithRawResponse by lazy {
+ ModelServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val fineTuning: FineTuningService.WithRawResponse by lazy {
+ FineTuningServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val beta: BetaService.WithRawResponse by lazy {
+ BetaServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val batches: BatchService.WithRawResponse by lazy {
+ BatchServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val uploads: UploadService.WithRawResponse by lazy {
+ UploadServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun completions(): CompletionService.WithRawResponse = completions
+
+ override fun chat(): ChatService.WithRawResponse = chat
+
+ override fun embeddings(): EmbeddingService.WithRawResponse = embeddings
+
+ override fun files(): FileService.WithRawResponse = files
+
+ override fun images(): ImageService.WithRawResponse = images
+
+ override fun audio(): AudioService.WithRawResponse = audio
+
+ override fun moderations(): ModerationService.WithRawResponse = moderations
+
+ override fun models(): ModelService.WithRawResponse = models
+
+ override fun fineTuning(): FineTuningService.WithRawResponse = fineTuning
+
+ override fun beta(): BetaService.WithRawResponse = beta
+
+ override fun batches(): BatchService.WithRawResponse = batches
+
+ override fun uploads(): UploadService.WithRawResponse = uploads
+ }
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Check.kt b/openai-java-core/src/main/kotlin/com/openai/core/Check.kt
index 1ff8c724b..6b58f9c77 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/Check.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Check.kt
@@ -5,6 +5,18 @@ package com.openai.core
fun checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required, but was not set" }
+@JvmSynthetic
+internal fun checkKnown(name: String, value: JsonField): T =
+ value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
+@JvmSynthetic
+internal fun checkKnown(name: String, value: MultipartField): T =
+ value.value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
@JvmSynthetic
internal fun checkLength(name: String, value: String, length: Int): String =
value.also {
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt
index 7b8e6ecd7..744f143f9 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt
@@ -30,6 +30,7 @@ private constructor(
@get:JvmName("headers") val headers: Headers,
@get:JvmName("queryParams") val queryParams: QueryParams,
@get:JvmName("responseValidation") val responseValidation: Boolean,
+ @get:JvmName("timeout") val timeout: Timeout,
@get:JvmName("maxRetries") val maxRetries: Int,
@get:JvmName("credential") val credential: Credential,
@get:JvmName("organization") val organization: String?,
@@ -58,6 +59,7 @@ private constructor(
private var headers: Headers.Builder = Headers.builder()
private var queryParams: QueryParams.Builder = QueryParams.builder()
private var responseValidation: Boolean = false
+ private var timeout: Timeout = Timeout.default()
private var maxRetries: Int = 2
private var credential: Credential? = null
private var azureServiceVersion: AzureOpenAIServiceVersion? = null
@@ -74,6 +76,7 @@ private constructor(
headers = clientOptions.headers.toBuilder()
queryParams = clientOptions.queryParams.toBuilder()
responseValidation = clientOptions.responseValidation
+ timeout = clientOptions.timeout
maxRetries = clientOptions.maxRetries
credential = clientOptions.credential
organization = clientOptions.organization
@@ -96,6 +99,8 @@ private constructor(
this.responseValidation = responseValidation
}
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }
fun apiKey(apiKey: String) = apply {
@@ -299,6 +304,7 @@ private constructor(
headers.build(),
queryParams.build(),
responseValidation,
+ timeout,
maxRetries,
credential,
organization,
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/HttpRequestBodies.kt b/openai-java-core/src/main/kotlin/com/openai/core/HttpRequestBodies.kt
deleted file mode 100644
index 253e7e531..000000000
--- a/openai-java-core/src/main/kotlin/com/openai/core/HttpRequestBodies.kt
+++ /dev/null
@@ -1,108 +0,0 @@
-@file:JvmName("HttpRequestBodies")
-
-package com.openai.core
-
-import com.fasterxml.jackson.databind.json.JsonMapper
-import com.openai.core.http.HttpRequestBody
-import com.openai.errors.OpenAIException
-import java.io.ByteArrayOutputStream
-import java.io.OutputStream
-import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
-
-@JvmSynthetic
-internal inline fun json(jsonMapper: JsonMapper, value: T): HttpRequestBody {
- return object : HttpRequestBody {
- private var cachedBytes: ByteArray? = null
-
- private fun serialize(): ByteArray {
- if (cachedBytes != null) return cachedBytes!!
-
- val buffer = ByteArrayOutputStream()
- try {
- jsonMapper.writeValue(buffer, value)
- cachedBytes = buffer.toByteArray()
- return cachedBytes!!
- } catch (e: Exception) {
- throw OpenAIException("Error writing request", e)
- }
- }
-
- override fun writeTo(outputStream: OutputStream) {
- outputStream.write(serialize())
- }
-
- override fun contentType(): String = "application/json"
-
- override fun contentLength(): Long {
- return serialize().size.toLong()
- }
-
- override fun repeatable(): Boolean = true
-
- override fun close() {}
- }
-}
-
-@JvmSynthetic
-internal fun multipartFormData(
- jsonMapper: JsonMapper,
- parts: Array?>,
-): HttpRequestBody {
- val builder = MultipartEntityBuilder.create()
- parts.forEach { part ->
- if (part?.value != null) {
- when (part.value) {
- is JsonValue -> {
- val buffer = ByteArrayOutputStream()
- try {
- jsonMapper.writeValue(buffer, part.value)
- } catch (e: Exception) {
- throw OpenAIException("Error serializing value to json", e)
- }
- builder.addBinaryBody(
- part.name,
- buffer.toByteArray(),
- part.contentType,
- part.filename,
- )
- }
- is Boolean ->
- builder.addTextBody(
- part.name,
- if (part.value) "true" else "false",
- part.contentType,
- )
- is Int -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is Long -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is Double -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is ByteArray ->
- builder.addBinaryBody(part.name, part.value, part.contentType, part.filename)
- is String -> builder.addTextBody(part.name, part.value, part.contentType)
- is Enum -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- else ->
- throw IllegalArgumentException(
- "Unsupported content type: ${part.value::class.java.simpleName}"
- )
- }
- }
- }
- val entity = builder.build()
-
- return object : HttpRequestBody {
- override fun writeTo(outputStream: OutputStream) {
- try {
- return entity.writeTo(outputStream)
- } catch (e: Exception) {
- throw OpenAIException("Error writing request", e)
- }
- }
-
- override fun contentType(): String = entity.contentType
-
- override fun contentLength(): Long = -1
-
- override fun repeatable(): Boolean = entity.isRepeatable
-
- override fun close() = entity.close()
- }
-}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/RequestOptions.kt b/openai-java-core/src/main/kotlin/com/openai/core/RequestOptions.kt
index c72629c4e..1d97b7bba 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/RequestOptions.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/RequestOptions.kt
@@ -2,13 +2,7 @@ package com.openai.core
import java.time.Duration
-class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Duration?) {
- fun applyDefaults(options: RequestOptions): RequestOptions {
- return RequestOptions(
- responseValidation = this.responseValidation ?: options.responseValidation,
- timeout = this.timeout ?: options.timeout,
- )
- }
+class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Timeout?) {
companion object {
@@ -16,22 +10,37 @@ class RequestOptions private constructor(val responseValidation: Boolean?, val t
@JvmStatic fun none() = NONE
+ @JvmSynthetic
+ internal fun from(clientOptions: ClientOptions): RequestOptions =
+ builder()
+ .responseValidation(clientOptions.responseValidation)
+ .timeout(clientOptions.timeout)
+ .build()
+
@JvmStatic fun builder() = Builder()
}
+ fun applyDefaults(options: RequestOptions): RequestOptions =
+ RequestOptions(
+ responseValidation = responseValidation ?: options.responseValidation,
+ timeout =
+ if (options.timeout != null && timeout != null) timeout.assign(options.timeout)
+ else timeout ?: options.timeout,
+ )
+
class Builder internal constructor() {
private var responseValidation: Boolean? = null
- private var timeout: Duration? = null
+ private var timeout: Timeout? = null
fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
- fun build(): RequestOptions {
- return RequestOptions(responseValidation, timeout)
- }
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
+
+ fun build(): RequestOptions = RequestOptions(responseValidation, timeout)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Timeout.kt b/openai-java-core/src/main/kotlin/com/openai/core/Timeout.kt
new file mode 100644
index 000000000..a27dd55a8
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Timeout.kt
@@ -0,0 +1,187 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.core
+
+import java.time.Duration
+import java.util.Objects
+import java.util.Optional
+
+/** A class containing timeouts for various processing phases of a request. */
+class Timeout
+private constructor(
+ private val connect: Duration?,
+ private val read: Duration?,
+ private val write: Duration?,
+ private val request: Duration?,
+) {
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(): Duration = connect ?: Duration.ofMinutes(1)
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(): Duration = read ?: request()
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(): Duration = write ?: request()
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as well
+ * as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(10)`.
+ */
+ fun request(): Duration = request ?: Duration.ofMinutes(10)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun default() = builder().build()
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Timeout]. */
+ class Builder internal constructor() {
+
+ private var connect: Duration? = null
+ private var read: Duration? = null
+ private var write: Duration? = null
+ private var request: Duration? = null
+
+ @JvmSynthetic
+ internal fun from(timeout: Timeout) = apply {
+ connect = timeout.connect
+ read = timeout.read
+ write = timeout.write
+ request = timeout.request
+ }
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(connect: Duration?) = apply { this.connect = connect }
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(connect: Optional) = connect(connect.orElse(null))
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(read: Duration?) = apply { this.read = read }
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(read: Optional) = read(read.orElse(null))
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(write: Duration?) = apply { this.write = write }
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(write: Optional) = write(write.orElse(null))
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as
+ * well as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(10)`.
+ */
+ fun request(request: Duration?) = apply { this.request = request }
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as
+ * well as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(10)`.
+ */
+ fun request(request: Optional) = request(request.orElse(null))
+
+ fun build(): Timeout = Timeout(connect, read, write, request)
+ }
+
+ @JvmSynthetic
+ internal fun assign(target: Timeout): Timeout =
+ target
+ .toBuilder()
+ .apply {
+ connect?.let(this::connect)
+ read?.let(this::read)
+ write?.let(this::write)
+ request?.let(this::request)
+ }
+ .build()
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Timeout && connect == other.connect && read == other.read && write == other.write && request == other.request /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(connect, read, write, request) /* spotless:on */
+
+ override fun toString() =
+ "Timeout{connect=$connect, read=$read, write=$write, request=$request}"
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Values.kt b/openai-java-core/src/main/kotlin/com/openai/core/Values.kt
index 9d9ed6e86..87838aa1d 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/Values.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Values.kt
@@ -27,10 +27,8 @@ import com.fasterxml.jackson.databind.node.JsonNodeType.POJO
import com.fasterxml.jackson.databind.node.JsonNodeType.STRING
import com.fasterxml.jackson.databind.ser.std.NullSerializer
import com.openai.errors.OpenAIInvalidDataException
-import java.nio.charset.Charset
import java.util.Objects
import java.util.Optional
-import org.apache.hc.core5.http.ContentType
@JsonDeserialize(using = JsonField.Deserializer::class)
sealed class JsonField {
@@ -287,12 +285,12 @@ private constructor(
return true
}
- return other is KnownValue<*> && value == other.value
+ return other is KnownValue<*> && value contentEquals other.value
}
- override fun hashCode() = value.hashCode()
+ override fun hashCode() = contentHash(value)
- override fun toString() = value.toString()
+ override fun toString() = value.contentToString()
companion object {
@JsonCreator @JvmStatic fun of(value: T) = KnownValue(value)
@@ -462,15 +460,63 @@ annotation class ExcludeMissing
)
annotation class NoAutoDetect
-class MultipartFormValue
-internal constructor(
- val name: String,
- val value: T,
- val contentType: ContentType,
- val filename: String? = null,
+class MultipartField
+private constructor(
+ @get:JvmName("value") val value: JsonField,
+ @get:JvmName("contentType") val contentType: String,
+ private val filename: String?,
) {
- private val hashCode: Int by lazy { contentHash(name, value, contentType, filename) }
+ companion object {
+
+ @JvmStatic fun of(value: T?) = builder().value(value).build()
+
+ @JvmStatic fun of(value: JsonField) = builder().value(value).build()
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ fun filename(): Optional = Optional.ofNullable(filename)
+
+ @JvmSynthetic
+ internal fun map(transform: (T) -> R): MultipartField =
+ MultipartField.builder()
+ .value(value.map(transform))
+ .contentType(contentType)
+ .filename(filename)
+ .build()
+
+ /** A builder for [MultipartField]. */
+ class Builder internal constructor() {
+
+ private var value: JsonField? = null
+ private var contentType: String? = null
+ private var filename: String? = null
+
+ fun value(value: JsonField) = apply { this.value = value }
+
+ fun value(value: T?) = value(JsonField.ofNullable(value))
+
+ fun contentType(contentType: String) = apply { this.contentType = contentType }
+
+ fun filename(filename: String?) = apply { this.filename = filename }
+
+ fun filename(filename: Optional) = filename(filename.orElse(null))
+
+ fun build(): MultipartField {
+ val value = checkRequired("value", value)
+ return MultipartField(
+ value,
+ contentType
+ ?: if (value is KnownValue && value.value is ByteArray)
+ "application/octet-stream"
+ else "text/plain; charset=utf-8",
+ filename,
+ )
+ }
+ }
+
+ private val hashCode: Int by lazy { contentHash(value, contentType, filename) }
override fun hashCode(): Int = hashCode
@@ -479,63 +525,12 @@ internal constructor(
return true
}
- return other is MultipartFormValue<*> &&
- name == other.name &&
- value contentEquals other.value &&
+ return other is MultipartField<*> &&
+ value == other.value &&
contentType == other.contentType &&
filename == other.filename
}
override fun toString(): String =
- "MultipartFormValue{name=$name, contentType=$contentType, filename=$filename, value=${valueToString()}}"
-
- private fun valueToString(): String =
- when (value) {
- is ByteArray -> "ByteArray of size ${value.size}"
- else -> value.toString()
- }
-
- companion object {
- internal fun fromString(
- name: String,
- value: String,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromBoolean(
- name: String,
- value: Boolean,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromLong(
- name: String,
- value: Long,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromDouble(
- name: String,
- value: Double,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromEnum(
- name: String,
- value: T,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromByteArray(
- name: String,
- value: ByteArray,
- contentType: ContentType,
- filename: String? = null,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType, filename)
- }
-}
-
-internal object ContentTypes {
- val DefaultText = ContentType.create(ContentType.TEXT_PLAIN.mimeType, Charset.forName("UTF-8"))
- val DefaultBinary = ContentType.DEFAULT_BINARY
+ "MultipartField{value=$value, contentType=$contentType, filename=$filename}"
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt
new file mode 100644
index 000000000..28c864f70
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpRequestBodies.kt
@@ -0,0 +1,90 @@
+// File generated from our OpenAPI spec by Stainless.
+
+@file:JvmName("HttpRequestBodies")
+
+package com.openai.core.http
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.fasterxml.jackson.databind.node.JsonNodeType
+import com.openai.core.MultipartField
+import com.openai.errors.OpenAIInvalidDataException
+import java.io.OutputStream
+import kotlin.jvm.optionals.getOrNull
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
+import org.apache.hc.core5.http.ContentType
+import org.apache.hc.core5.http.HttpEntity
+
+@JvmSynthetic
+internal inline fun json(jsonMapper: JsonMapper, value: T): HttpRequestBody =
+ object : HttpRequestBody {
+ private val bytes: ByteArray by lazy { jsonMapper.writeValueAsBytes(value) }
+
+ override fun writeTo(outputStream: OutputStream) = outputStream.write(bytes)
+
+ override fun contentType(): String = "application/json"
+
+ override fun contentLength(): Long = bytes.size.toLong()
+
+ override fun repeatable(): Boolean = true
+
+ override fun close() {}
+ }
+
+@JvmSynthetic
+internal fun multipartFormData(
+ jsonMapper: JsonMapper,
+ fields: Map>,
+): HttpRequestBody =
+ object : HttpRequestBody {
+ private val entity: HttpEntity by lazy {
+ MultipartEntityBuilder.create()
+ .apply {
+ fields.forEach { (name, field) ->
+ val node = jsonMapper.valueToTree(field.value)
+ serializePart(name, node).forEach { (name, bytes) ->
+ addBinaryBody(
+ name,
+ bytes,
+ ContentType.parseLenient(field.contentType),
+ field.filename().getOrNull(),
+ )
+ }
+ }
+ }
+ .build()
+ }
+
+ private fun serializePart(name: String, node: JsonNode): Sequence> =
+ when (node.nodeType) {
+ JsonNodeType.MISSING,
+ JsonNodeType.NULL -> emptySequence()
+ JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue())
+ JsonNodeType.STRING -> sequenceOf(name to node.textValue().toByteArray())
+ JsonNodeType.BOOLEAN ->
+ sequenceOf(name to node.booleanValue().toString().toByteArray())
+ JsonNodeType.NUMBER ->
+ sequenceOf(name to node.numberValue().toString().toByteArray())
+ JsonNodeType.ARRAY ->
+ node.elements().asSequence().flatMap { element ->
+ serializePart("$name[]", element)
+ }
+ JsonNodeType.OBJECT ->
+ node.fields().asSequence().flatMap { (key, value) ->
+ serializePart("$name[$key]", value)
+ }
+ JsonNodeType.POJO,
+ null ->
+ throw OpenAIInvalidDataException("Unexpected JsonNode type: ${node.nodeType}")
+ }
+
+ override fun writeTo(outputStream: OutputStream) = entity.writeTo(outputStream)
+
+ override fun contentType(): String = entity.contentType
+
+ override fun contentLength(): Long = entity.contentLength
+
+ override fun repeatable(): Boolean = entity.isRepeatable
+
+ override fun close() = entity.close()
+ }
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/http/HttpResponseFor.kt b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpResponseFor.kt
new file mode 100644
index 000000000..eaf211a05
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/core/http/HttpResponseFor.kt
@@ -0,0 +1,23 @@
+package com.openai.core.http
+
+import java.io.InputStream
+
+interface HttpResponseFor : HttpResponse {
+
+ fun parse(): T
+}
+
+@JvmSynthetic
+internal fun HttpResponse.parseable(parse: () -> T): HttpResponseFor =
+ object : HttpResponseFor {
+
+ override fun parse(): T = parse()
+
+ override fun statusCode(): Int = this@parseable.statusCode()
+
+ override fun headers(): Headers = this@parseable.headers()
+
+ override fun body(): InputStream = this@parseable.body()
+
+ override fun close() = this@parseable.close()
+ }
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt b/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
index 7b80a02e1..ce1e4c05c 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -432,15 +433,7 @@ private constructor(
*/
fun addTool(tool: AssistantTool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
- }
+ (tools ?: JsonField.of(mutableListOf())).also { checkKnown("tools", it).add(tool) }
}
/**
@@ -936,14 +929,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -1085,14 +1072,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioModel.kt
new file mode 100644
index 000000000..80e8e9f09
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioModel.kt
@@ -0,0 +1,98 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.openai.core.Enum
+import com.openai.core.JsonField
+import com.openai.errors.OpenAIInvalidDataException
+
+class AudioModel @JsonCreator private constructor(private val value: JsonField) : Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't match
+ * any known member, and you want to know that value. For example, if the SDK is on an older
+ * version than the API, then the API may respond with new members that the SDK is unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val WHISPER_1 = of("whisper-1")
+
+ @JvmStatic fun of(value: String) = AudioModel(JsonField.of(value))
+ }
+
+ /** An enum containing [AudioModel]'s known values. */
+ enum class Known {
+ WHISPER_1
+ }
+
+ /**
+ * An enum containing [AudioModel]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [AudioModel] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if the SDK
+ * is on an older version than the API, then the API may respond with new members that the SDK
+ * is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ WHISPER_1,
+ /** An enum member indicating that [AudioModel] was instantiated with an unknown value. */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if
+ * the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you want to
+ * throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ WHISPER_1 -> Value.WHISPER_1
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and don't want
+ * to throw for the unknown case.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value is a not a known member.
+ */
+ fun known(): Known =
+ when (this) {
+ WHISPER_1 -> Known.WHISPER_1
+ else -> throw OpenAIInvalidDataException("Unknown AudioModel: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for debugging and
+ * generally doesn't throw.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value does not have the expected
+ * primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioModel && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioResponseFormat.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioResponseFormat.kt
new file mode 100644
index 000000000..e75d48551
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioResponseFormat.kt
@@ -0,0 +1,130 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.openai.core.Enum
+import com.openai.core.JsonField
+import com.openai.errors.OpenAIInvalidDataException
+
+/**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or
+ * `vtt`.
+ */
+class AudioResponseFormat @JsonCreator private constructor(private val value: JsonField) :
+ Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't match
+ * any known member, and you want to know that value. For example, if the SDK is on an older
+ * version than the API, then the API may respond with new members that the SDK is unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val JSON = of("json")
+
+ @JvmField val TEXT = of("text")
+
+ @JvmField val SRT = of("srt")
+
+ @JvmField val VERBOSE_JSON = of("verbose_json")
+
+ @JvmField val VTT = of("vtt")
+
+ @JvmStatic fun of(value: String) = AudioResponseFormat(JsonField.of(value))
+ }
+
+ /** An enum containing [AudioResponseFormat]'s known values. */
+ enum class Known {
+ JSON,
+ TEXT,
+ SRT,
+ VERBOSE_JSON,
+ VTT,
+ }
+
+ /**
+ * An enum containing [AudioResponseFormat]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [AudioResponseFormat] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if the SDK
+ * is on an older version than the API, then the API may respond with new members that the SDK
+ * is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ JSON,
+ TEXT,
+ SRT,
+ VERBOSE_JSON,
+ VTT,
+ /**
+ * An enum member indicating that [AudioResponseFormat] was instantiated with an unknown
+ * value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if
+ * the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you want to
+ * throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ JSON -> Value.JSON
+ TEXT -> Value.TEXT
+ SRT -> Value.SRT
+ VERBOSE_JSON -> Value.VERBOSE_JSON
+ VTT -> Value.VTT
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and don't want
+ * to throw for the unknown case.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value is a not a known member.
+ */
+ fun known(): Known =
+ when (this) {
+ JSON -> Known.JSON
+ TEXT -> Known.TEXT
+ SRT -> Known.SRT
+ VERBOSE_JSON -> Known.VERBOSE_JSON
+ VTT -> Known.VTT
+ else -> throw OpenAIInvalidDataException("Unknown AudioResponseFormat: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for debugging and
+ * generally doesn't throw.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value does not have the expected
+ * primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioResponseFormat && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioSpeechCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioSpeechCreateParams.kt
new file mode 100644
index 000000000..24b65ffa6
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioSpeechCreateParams.kt
@@ -0,0 +1,846 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.openai.core.Enum
+import com.openai.core.ExcludeMissing
+import com.openai.core.JsonField
+import com.openai.core.JsonMissing
+import com.openai.core.JsonValue
+import com.openai.core.NoAutoDetect
+import com.openai.core.Params
+import com.openai.core.checkRequired
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+import com.openai.core.immutableEmptyMap
+import com.openai.core.toImmutable
+import com.openai.errors.OpenAIInvalidDataException
+import java.util.Objects
+import java.util.Optional
+
+/** Generates audio from the input text. */
+class AudioSpeechCreateParams
+private constructor(
+ private val body: Body,
+ private val additionalHeaders: Headers,
+ private val additionalQueryParams: QueryParams,
+) : Params {
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(): String = body.input()
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1` or
+ * `tts-1-hd`
+ */
+ fun model(): SpeechModel = body.model()
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are available
+ * in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(): Voice = body.voice()
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
+ */
+ fun responseFormat(): Optional = body.responseFormat()
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default.
+ */
+ fun speed(): Optional = body.speed()
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun _input(): JsonField = body._input()
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1` or
+ * `tts-1-hd`
+ */
+ fun _model(): JsonField = body._model()
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are available
+ * in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun _voice(): JsonField = body._voice()
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
+ */
+ fun _responseFormat(): JsonField = body._responseFormat()
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default.
+ */
+ fun _speed(): JsonField = body._speed()
+
+ fun _additionalBodyProperties(): Map = body._additionalProperties()
+
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ @JvmSynthetic internal fun _body(): Body = body
+
+ override fun _headers(): Headers = additionalHeaders
+
+ override fun _queryParams(): QueryParams = additionalQueryParams
+
+ @NoAutoDetect
+ class Body
+ @JsonCreator
+ private constructor(
+ @JsonProperty("input")
+ @ExcludeMissing
+ private val input: JsonField = JsonMissing.of(),
+ @JsonProperty("model")
+ @ExcludeMissing
+ private val model: JsonField = JsonMissing.of(),
+ @JsonProperty("voice")
+ @ExcludeMissing
+ private val voice: JsonField = JsonMissing.of(),
+ @JsonProperty("response_format")
+ @ExcludeMissing
+ private val responseFormat: JsonField = JsonMissing.of(),
+ @JsonProperty("speed")
+ @ExcludeMissing
+ private val speed: JsonField = JsonMissing.of(),
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap(),
+ ) {
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(): String = input.getRequired("input")
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`
+ * or `tts-1-hd`
+ */
+ fun model(): SpeechModel = model.getRequired("model")
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are
+ * available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(): Voice = voice.getRequired("voice")
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and
+ * `pcm`.
+ */
+ fun responseFormat(): Optional =
+ Optional.ofNullable(responseFormat.getNullable("response_format"))
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ fun speed(): Optional = Optional.ofNullable(speed.getNullable("speed"))
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ @JsonProperty("input") @ExcludeMissing fun _input(): JsonField = input
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`
+ * or `tts-1-hd`
+ */
+ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are
+ * available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ @JsonProperty("voice") @ExcludeMissing fun _voice(): JsonField = voice
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and
+ * `pcm`.
+ */
+ @JsonProperty("response_format")
+ @ExcludeMissing
+ fun _responseFormat(): JsonField = responseFormat
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ @JsonProperty("speed") @ExcludeMissing fun _speed(): JsonField = speed
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): Body = apply {
+ if (validated) {
+ return@apply
+ }
+
+ input()
+ model()
+ voice()
+ responseFormat()
+ speed()
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Body]. */
+ class Builder internal constructor() {
+
+ private var input: JsonField? = null
+ private var model: JsonField? = null
+ private var voice: JsonField? = null
+ private var responseFormat: JsonField = JsonMissing.of()
+ private var speed: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(body: Body) = apply {
+ input = body.input
+ model = body.model
+ voice = body.voice
+ responseFormat = body.responseFormat
+ speed = body.speed
+ additionalProperties = body.additionalProperties.toMutableMap()
+ }
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(input: String) = input(JsonField.of(input))
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(input: JsonField) = apply { this.input = input }
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts):
+ * `tts-1` or `tts-1-hd`
+ */
+ fun model(model: SpeechModel) = model(JsonField.of(model))
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts):
+ * `tts-1` or `tts-1-hd`
+ */
+ fun model(model: JsonField) = apply { this.model = model }
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts):
+ * `tts-1` or `tts-1-hd`
+ */
+ fun model(value: String) = model(SpeechModel.of(value))
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`,
+ * `coral`, `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the
+ * voices are available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(voice: Voice) = voice(JsonField.of(voice))
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`,
+ * `coral`, `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the
+ * voices are available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(voice: JsonField) = apply { this.voice = voice }
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`,
+ * and `pcm`.
+ */
+ fun responseFormat(responseFormat: ResponseFormat) =
+ responseFormat(JsonField.of(responseFormat))
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`,
+ * and `pcm`.
+ */
+ fun responseFormat(responseFormat: JsonField) = apply {
+ this.responseFormat = responseFormat
+ }
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ fun speed(speed: Double) = speed(JsonField.of(speed))
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ fun speed(speed: JsonField) = apply { this.speed = speed }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): Body =
+ Body(
+ checkRequired("input", input),
+ checkRequired("model", model),
+ checkRequired("voice", voice),
+ responseFormat,
+ speed,
+ additionalProperties.toImmutable(),
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Body && input == other.input && model == other.model && voice == other.voice && responseFormat == other.responseFormat && speed == other.speed && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(input, model, voice, responseFormat, speed, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "Body{input=$input, model=$model, voice=$voice, responseFormat=$responseFormat, speed=$speed, additionalProperties=$additionalProperties}"
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AudioSpeechCreateParams]. */
+ @NoAutoDetect
+ class Builder internal constructor() {
+
+ private var body: Body.Builder = Body.builder()
+ private var additionalHeaders: Headers.Builder = Headers.builder()
+ private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
+
+ @JvmSynthetic
+ internal fun from(audioSpeechCreateParams: AudioSpeechCreateParams) = apply {
+ body = audioSpeechCreateParams.body.toBuilder()
+ additionalHeaders = audioSpeechCreateParams.additionalHeaders.toBuilder()
+ additionalQueryParams = audioSpeechCreateParams.additionalQueryParams.toBuilder()
+ }
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(input: String) = apply { body.input(input) }
+
+ /** The text to generate audio for. The maximum length is 4096 characters. */
+ fun input(input: JsonField) = apply { body.input(input) }
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`
+ * or `tts-1-hd`
+ */
+ fun model(model: SpeechModel) = apply { body.model(model) }
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`
+ * or `tts-1-hd`
+ */
+ fun model(model: JsonField) = apply { body.model(model) }
+
+ /**
+ * One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`
+ * or `tts-1-hd`
+ */
+ fun model(value: String) = apply { body.model(value) }
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are
+ * available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(voice: Voice) = apply { body.voice(voice) }
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are
+ * available in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ fun voice(voice: JsonField) = apply { body.voice(voice) }
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and
+ * `pcm`.
+ */
+ fun responseFormat(responseFormat: ResponseFormat) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and
+ * `pcm`.
+ */
+ fun responseFormat(responseFormat: JsonField) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ fun speed(speed: Double) = apply { body.speed(speed) }
+
+ /**
+ * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the
+ * default.
+ */
+ fun speed(speed: JsonField) = apply { body.speed(speed) }
+
+ fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
+ body.additionalProperties(additionalBodyProperties)
+ }
+
+ fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
+ body.putAdditionalProperty(key, value)
+ }
+
+ fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
+ apply {
+ body.putAllAdditionalProperties(additionalBodyProperties)
+ }
+
+ fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
+
+ fun removeAllAdditionalBodyProperties(keys: Set) = apply {
+ body.removeAllAdditionalProperties(keys)
+ }
+
+ fun additionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun additionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun putAdditionalHeader(name: String, value: String) = apply {
+ additionalHeaders.put(name, value)
+ }
+
+ fun putAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.put(name, values)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun replaceAdditionalHeaders(name: String, value: String) = apply {
+ additionalHeaders.replace(name, value)
+ }
+
+ fun replaceAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.replace(name, values)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) }
+
+ fun removeAllAdditionalHeaders(names: Set) = apply {
+ additionalHeaders.removeAll(names)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: Map>) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun putAdditionalQueryParam(key: String, value: String) = apply {
+ additionalQueryParams.put(key, value)
+ }
+
+ fun putAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.put(key, values)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, value: String) = apply {
+ additionalQueryParams.replace(key, value)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.replace(key, values)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) }
+
+ fun removeAllAdditionalQueryParams(keys: Set) = apply {
+ additionalQueryParams.removeAll(keys)
+ }
+
+ fun build(): AudioSpeechCreateParams =
+ AudioSpeechCreateParams(
+ body.build(),
+ additionalHeaders.build(),
+ additionalQueryParams.build(),
+ )
+ }
+
+ /**
+ * The voice to use when generating the audio. Supported voices are `alloy`, `ash`, `coral`,
+ * `echo`, `fable`, `onyx`, `nova`, `sage` and `shimmer`. Previews of the voices are available
+ * in the
+ * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
+ */
+ class Voice @JsonCreator private constructor(private val value: JsonField) : Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is on an
+ * older version than the API, then the API may respond with new members that the SDK is
+ * unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val ALLOY = of("alloy")
+
+ @JvmField val ASH = of("ash")
+
+ @JvmField val CORAL = of("coral")
+
+ @JvmField val ECHO = of("echo")
+
+ @JvmField val FABLE = of("fable")
+
+ @JvmField val ONYX = of("onyx")
+
+ @JvmField val NOVA = of("nova")
+
+ @JvmField val SAGE = of("sage")
+
+ @JvmField val SHIMMER = of("shimmer")
+
+ @JvmStatic fun of(value: String) = Voice(JsonField.of(value))
+ }
+
+ /** An enum containing [Voice]'s known values. */
+ enum class Known {
+ ALLOY,
+ ASH,
+ CORAL,
+ ECHO,
+ FABLE,
+ ONYX,
+ NOVA,
+ SAGE,
+ SHIMMER,
+ }
+
+ /**
+ * An enum containing [Voice]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [Voice] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if the
+ * SDK is on an older version than the API, then the API may respond with new members that
+ * the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ ALLOY,
+ ASH,
+ CORAL,
+ ECHO,
+ FABLE,
+ ONYX,
+ NOVA,
+ SAGE,
+ SHIMMER,
+ /** An enum member indicating that [Voice] was instantiated with an unknown value. */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
+ * if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you want
+ * to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ ALLOY -> Value.ALLOY
+ ASH -> Value.ASH
+ CORAL -> Value.CORAL
+ ECHO -> Value.ECHO
+ FABLE -> Value.FABLE
+ ONYX -> Value.ONYX
+ NOVA -> Value.NOVA
+ SAGE -> Value.SAGE
+ SHIMMER -> Value.SHIMMER
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and don't
+ * want to throw for the unknown case.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ ALLOY -> Known.ALLOY
+ ASH -> Known.ASH
+ CORAL -> Known.CORAL
+ ECHO -> Known.ECHO
+ FABLE -> Known.FABLE
+ ONYX -> Known.ONYX
+ NOVA -> Known.NOVA
+ SAGE -> Known.SAGE
+ SHIMMER -> Known.SHIMMER
+ else -> throw OpenAIInvalidDataException("Unknown Voice: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for debugging
+ * and generally doesn't throw.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Voice && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ /**
+ * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
+ */
+ class ResponseFormat @JsonCreator private constructor(private val value: JsonField) :
+ Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is on an
+ * older version than the API, then the API may respond with new members that the SDK is
+ * unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val MP3 = of("mp3")
+
+ @JvmField val OPUS = of("opus")
+
+ @JvmField val AAC = of("aac")
+
+ @JvmField val FLAC = of("flac")
+
+ @JvmField val WAV = of("wav")
+
+ @JvmField val PCM = of("pcm")
+
+ @JvmStatic fun of(value: String) = ResponseFormat(JsonField.of(value))
+ }
+
+ /** An enum containing [ResponseFormat]'s known values. */
+ enum class Known {
+ MP3,
+ OPUS,
+ AAC,
+ FLAC,
+ WAV,
+ PCM,
+ }
+
+ /**
+ * An enum containing [ResponseFormat]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [ResponseFormat] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if the
+ * SDK is on an older version than the API, then the API may respond with new members that
+ * the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ MP3,
+ OPUS,
+ AAC,
+ FLAC,
+ WAV,
+ PCM,
+ /**
+ * An enum member indicating that [ResponseFormat] was instantiated with an unknown
+ * value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
+ * if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you want
+ * to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ MP3 -> Value.MP3
+ OPUS -> Value.OPUS
+ AAC -> Value.AAC
+ FLAC -> Value.FLAC
+ WAV -> Value.WAV
+ PCM -> Value.PCM
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and don't
+ * want to throw for the unknown case.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ MP3 -> Known.MP3
+ OPUS -> Known.OPUS
+ AAC -> Known.AAC
+ FLAC -> Known.FLAC
+ WAV -> Known.WAV
+ PCM -> Known.PCM
+ else -> throw OpenAIInvalidDataException("Unknown ResponseFormat: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for debugging
+ * and generally doesn't throw.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is ResponseFormat && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioSpeechCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+
+ override fun toString() =
+ "AudioSpeechCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateParams.kt
new file mode 100644
index 000000000..48a79d021
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateParams.kt
@@ -0,0 +1,836 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.openai.core.Enum
+import com.openai.core.JsonField
+import com.openai.core.MultipartField
+import com.openai.core.NoAutoDetect
+import com.openai.core.Params
+import com.openai.core.checkKnown
+import com.openai.core.checkRequired
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+import com.openai.core.toImmutable
+import com.openai.errors.OpenAIInvalidDataException
+import java.util.Objects
+import java.util.Optional
+
+/** Transcribes audio into the input language. */
+class AudioTranscriptionCreateParams
+private constructor(
+ private val body: Body,
+ private val additionalHeaders: Headers,
+ private val additionalQueryParams: QueryParams,
+) : Params {
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(): ByteArray = body.file()
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(): AudioModel = body.model()
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format will
+ * improve accuracy and latency.
+ */
+ fun language(): Optional = body.language()
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match the
+ * audio language.
+ */
+ fun prompt(): Optional = body.prompt()
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or
+ * `vtt`.
+ */
+ fun responseFormat(): Optional = body.responseFormat()
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more
+ * random, while lower values like 0.2 will make it more focused and deterministic. If set to 0,
+ * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to
+ * automatically increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(): Optional = body.temperature()
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be set
+ * `verbose_json` to use timestamp granularities. Either or both of these options are supported:
+ * `word`, or `segment`. Note: There is no additional latency for segment timestamps, but
+ * generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(): Optional> =
+ body.timestampGranularities()
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun _file(): MultipartField = body._file()
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun _model(): MultipartField = body._model()
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format will
+ * improve accuracy and latency.
+ */
+ fun _language(): MultipartField = body._language()
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match the
+ * audio language.
+ */
+ fun _prompt(): MultipartField = body._prompt()
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or
+ * `vtt`.
+ */
+ fun _responseFormat(): MultipartField = body._responseFormat()
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more
+ * random, while lower values like 0.2 will make it more focused and deterministic. If set to 0,
+ * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to
+ * automatically increase the temperature until certain thresholds are hit.
+ */
+ fun _temperature(): MultipartField = body._temperature()
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be set
+ * `verbose_json` to use timestamp granularities. Either or both of these options are supported:
+ * `word`, or `segment`. Note: There is no additional latency for segment timestamps, but
+ * generating word timestamps incurs additional latency.
+ */
+ fun _timestampGranularities(): MultipartField> =
+ body._timestampGranularities()
+
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ @JvmSynthetic
+ internal fun _body(): Map> =
+ mapOf(
+ "file" to _file(),
+ "model" to _model(),
+ "language" to _language(),
+ "prompt" to _prompt(),
+ "response_format" to _responseFormat(),
+ "temperature" to _temperature(),
+ "timestamp_granularities" to _timestampGranularities(),
+ )
+ .toImmutable()
+
+ override fun _headers(): Headers = additionalHeaders
+
+ override fun _queryParams(): QueryParams = additionalQueryParams
+
+ @NoAutoDetect
+ class Body
+ @JsonCreator
+ private constructor(
+ private val file: MultipartField,
+ private val model: MultipartField,
+ private val language: MultipartField,
+ private val prompt: MultipartField,
+ private val responseFormat: MultipartField,
+ private val temperature: MultipartField,
+ private val timestampGranularities: MultipartField>,
+ ) {
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(): ByteArray = file.value.getRequired("file")
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(): AudioModel = model.value.getRequired("model")
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun language(): Optional =
+ Optional.ofNullable(language.value.getNullable("language"))
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match
+ * the audio language.
+ */
+ fun prompt(): Optional = Optional.ofNullable(prompt.value.getNullable("prompt"))
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(): Optional =
+ Optional.ofNullable(responseFormat.value.getNullable("response_format"))
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(): Optional =
+ Optional.ofNullable(temperature.value.getNullable("temperature"))
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be
+ * set `verbose_json` to use timestamp granularities. Either or both of these options are
+ * supported: `word`, or `segment`. Note: There is no additional latency for segment
+ * timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(): Optional> =
+ Optional.ofNullable(timestampGranularities.value.getNullable("timestamp_granularities"))
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun _file(): MultipartField = file
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun _model(): MultipartField = model
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun _language(): MultipartField = language
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match
+ * the audio language.
+ */
+ fun _prompt(): MultipartField = prompt
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun _responseFormat(): MultipartField = responseFormat
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun _temperature(): MultipartField = temperature
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be
+ * set `verbose_json` to use timestamp granularities. Either or both of these options are
+ * supported: `word`, or `segment`. Note: There is no additional latency for segment
+ * timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun _timestampGranularities(): MultipartField> =
+ timestampGranularities
+
+ private var validated: Boolean = false
+
+ fun validate(): Body = apply {
+ if (validated) {
+ return@apply
+ }
+
+ file()
+ model()
+ language()
+ prompt()
+ responseFormat()
+ temperature()
+ timestampGranularities()
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Body]. */
+ class Builder internal constructor() {
+
+ private var file: MultipartField? = null
+ private var model: MultipartField? = null
+ private var language: MultipartField = MultipartField.of(null)
+ private var prompt: MultipartField = MultipartField.of(null)
+ private var responseFormat: MultipartField =
+ MultipartField.of(null)
+ private var temperature: MultipartField = MultipartField.of(null)
+ private var timestampGranularities: MultipartField>? =
+ null
+
+ @JvmSynthetic
+ internal fun from(body: Body) = apply {
+ file = body.file
+ model = body.model
+ language = body.language
+ prompt = body.prompt
+ responseFormat = body.responseFormat
+ temperature = body.temperature
+ timestampGranularities = body.timestampGranularities.map { it.toMutableList() }
+ }
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac,
+ * mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: ByteArray) = file(MultipartField.of(file))
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac,
+ * mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: MultipartField) = apply { this.file = file }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(model: AudioModel) = model(MultipartField.of(model))
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(model: MultipartField) = apply { this.model = model }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(value: String) = model(AudioModel.of(value))
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun language(language: String) = language(MultipartField.of(language))
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun language(language: MultipartField) = apply { this.language = language }
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should
+ * match the audio language.
+ */
+ fun prompt(prompt: String) = prompt(MultipartField.of(prompt))
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should
+ * match the audio language.
+ */
+ fun prompt(prompt: MultipartField) = apply { this.prompt = prompt }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`,
+ * `verbose_json`, or `vtt`.
+ */
+ fun responseFormat(responseFormat: AudioResponseFormat) =
+ responseFormat(MultipartField.of(responseFormat))
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`,
+ * `verbose_json`, or `vtt`.
+ */
+ fun responseFormat(responseFormat: MultipartField) = apply {
+ this.responseFormat = responseFormat
+ }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and
+ * deterministic. If set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: Double) = temperature(MultipartField.of(temperature))
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and
+ * deterministic. If set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: MultipartField) = apply {
+ this.temperature = temperature
+ }
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format`
+ * must be set `verbose_json` to use timestamp granularities. Either or both of these
+ * options are supported: `word`, or `segment`. Note: There is no additional latency for
+ * segment timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(timestampGranularities: List) =
+ timestampGranularities(MultipartField.of(timestampGranularities))
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format`
+ * must be set `verbose_json` to use timestamp granularities. Either or both of these
+ * options are supported: `word`, or `segment`. Note: There is no additional latency for
+ * segment timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(
+ timestampGranularities: MultipartField>
+ ) = apply {
+ this.timestampGranularities = timestampGranularities.map { it.toMutableList() }
+ }
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format`
+ * must be set `verbose_json` to use timestamp granularities. Either or both of these
+ * options are supported: `word`, or `segment`. Note: There is no additional latency for
+ * segment timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun addTimestampGranularity(timestampGranularity: TimestampGranularity) = apply {
+ timestampGranularities =
+ (timestampGranularities ?: MultipartField.of(mutableListOf())).also {
+ checkKnown("timestampGranularities", it).add(timestampGranularity)
+ }
+ }
+
+ fun build(): Body =
+ Body(
+ checkRequired("file", file),
+ checkRequired("model", model),
+ language,
+ prompt,
+ responseFormat,
+ temperature,
+ (timestampGranularities ?: MultipartField.of(null)).map { it.toImmutable() },
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Body && file == other.file && model == other.model && language == other.language && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature && timestampGranularities == other.timestampGranularities /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(file, model, language, prompt, responseFormat, temperature, timestampGranularities) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "Body{file=$file, model=$model, language=$language, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature, timestampGranularities=$timestampGranularities}"
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AudioTranscriptionCreateParams]. */
+ @NoAutoDetect
+ class Builder internal constructor() {
+
+ private var body: Body.Builder = Body.builder()
+ private var additionalHeaders: Headers.Builder = Headers.builder()
+ private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
+
+ @JvmSynthetic
+ internal fun from(audioTranscriptionCreateParams: AudioTranscriptionCreateParams) = apply {
+ body = audioTranscriptionCreateParams.body.toBuilder()
+ additionalHeaders = audioTranscriptionCreateParams.additionalHeaders.toBuilder()
+ additionalQueryParams = audioTranscriptionCreateParams.additionalQueryParams.toBuilder()
+ }
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: ByteArray) = apply { body.file(file) }
+
+ /**
+ * The audio file object (not file name) to transcribe, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: MultipartField) = apply { body.file(file) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(model: AudioModel) = apply { body.model(model) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(model: MultipartField) = apply { body.model(model) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(value: String) = apply { body.model(value) }
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun language(language: String) = apply { body.language(language) }
+
+ /**
+ * The language of the input audio. Supplying the input language in
+ * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format
+ * will improve accuracy and latency.
+ */
+ fun language(language: MultipartField) = apply { body.language(language) }
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match
+ * the audio language.
+ */
+ fun prompt(prompt: String) = apply { body.prompt(prompt) }
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should match
+ * the audio language.
+ */
+ fun prompt(prompt: MultipartField) = apply { body.prompt(prompt) }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(responseFormat: AudioResponseFormat) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(responseFormat: MultipartField) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: Double) = apply { body.temperature(temperature) }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: MultipartField) = apply {
+ body.temperature(temperature)
+ }
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be
+ * set `verbose_json` to use timestamp granularities. Either or both of these options are
+ * supported: `word`, or `segment`. Note: There is no additional latency for segment
+ * timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(timestampGranularities: List) = apply {
+ body.timestampGranularities(timestampGranularities)
+ }
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be
+ * set `verbose_json` to use timestamp granularities. Either or both of these options are
+ * supported: `word`, or `segment`. Note: There is no additional latency for segment
+ * timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun timestampGranularities(
+ timestampGranularities: MultipartField>
+ ) = apply { body.timestampGranularities(timestampGranularities) }
+
+ /**
+ * The timestamp granularities to populate for this transcription. `response_format` must be
+ * set `verbose_json` to use timestamp granularities. Either or both of these options are
+ * supported: `word`, or `segment`. Note: There is no additional latency for segment
+ * timestamps, but generating word timestamps incurs additional latency.
+ */
+ fun addTimestampGranularity(timestampGranularity: TimestampGranularity) = apply {
+ body.addTimestampGranularity(timestampGranularity)
+ }
+
+ fun additionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun additionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun putAdditionalHeader(name: String, value: String) = apply {
+ additionalHeaders.put(name, value)
+ }
+
+ fun putAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.put(name, values)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun replaceAdditionalHeaders(name: String, value: String) = apply {
+ additionalHeaders.replace(name, value)
+ }
+
+ fun replaceAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.replace(name, values)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) }
+
+ fun removeAllAdditionalHeaders(names: Set) = apply {
+ additionalHeaders.removeAll(names)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: Map>) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun putAdditionalQueryParam(key: String, value: String) = apply {
+ additionalQueryParams.put(key, value)
+ }
+
+ fun putAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.put(key, values)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, value: String) = apply {
+ additionalQueryParams.replace(key, value)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.replace(key, values)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) }
+
+ fun removeAllAdditionalQueryParams(keys: Set) = apply {
+ additionalQueryParams.removeAll(keys)
+ }
+
+ fun build(): AudioTranscriptionCreateParams =
+ AudioTranscriptionCreateParams(
+ body.build(),
+ additionalHeaders.build(),
+ additionalQueryParams.build(),
+ )
+ }
+
+ class TimestampGranularity
+ @JsonCreator
+ private constructor(private val value: JsonField) : Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is on an
+ * older version than the API, then the API may respond with new members that the SDK is
+ * unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val WORD = of("word")
+
+ @JvmField val SEGMENT = of("segment")
+
+ @JvmStatic fun of(value: String) = TimestampGranularity(JsonField.of(value))
+ }
+
+ /** An enum containing [TimestampGranularity]'s known values. */
+ enum class Known {
+ WORD,
+ SEGMENT,
+ }
+
+ /**
+ * An enum containing [TimestampGranularity]'s known values, as well as an [_UNKNOWN]
+ * member.
+ *
+ * An instance of [TimestampGranularity] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if the
+ * SDK is on an older version than the API, then the API may respond with new members that
+ * the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ WORD,
+ SEGMENT,
+ /**
+ * An enum member indicating that [TimestampGranularity] was instantiated with an
+ * unknown value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
+ * if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you want
+ * to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ WORD -> Value.WORD
+ SEGMENT -> Value.SEGMENT
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and don't
+ * want to throw for the unknown case.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ WORD -> Known.WORD
+ SEGMENT -> Known.SEGMENT
+ else -> throw OpenAIInvalidDataException("Unknown TimestampGranularity: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for debugging
+ * and generally doesn't throw.
+ *
+ * @throws OpenAIInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is TimestampGranularity && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioTranscriptionCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+
+ override fun toString() =
+ "AudioTranscriptionCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateResponse.kt
new file mode 100644
index 000000000..60099d3e5
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranscriptionCreateResponse.kt
@@ -0,0 +1,189 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
+import com.openai.core.BaseDeserializer
+import com.openai.core.BaseSerializer
+import com.openai.core.JsonValue
+import com.openai.core.getOrThrow
+import com.openai.errors.OpenAIInvalidDataException
+import java.util.Objects
+import java.util.Optional
+
+/** Represents a transcription response returned by model, based on the provided input. */
+@JsonDeserialize(using = AudioTranscriptionCreateResponse.Deserializer::class)
+@JsonSerialize(using = AudioTranscriptionCreateResponse.Serializer::class)
+class AudioTranscriptionCreateResponse
+private constructor(
+ private val transcription: Transcription? = null,
+ private val transcriptionVerbose: TranscriptionVerbose? = null,
+ private val _json: JsonValue? = null,
+) {
+
+ /** Represents a transcription response returned by model, based on the provided input. */
+ fun transcription(): Optional = Optional.ofNullable(transcription)
+
+ /**
+ * Represents a verbose json transcription response returned by model, based on the provided
+ * input.
+ */
+ fun transcriptionVerbose(): Optional =
+ Optional.ofNullable(transcriptionVerbose)
+
+ fun isTranscription(): Boolean = transcription != null
+
+ fun isTranscriptionVerbose(): Boolean = transcriptionVerbose != null
+
+ /** Represents a transcription response returned by model, based on the provided input. */
+ fun asTranscription(): Transcription = transcription.getOrThrow("transcription")
+
+ /**
+ * Represents a verbose json transcription response returned by model, based on the provided
+ * input.
+ */
+ fun asTranscriptionVerbose(): TranscriptionVerbose =
+ transcriptionVerbose.getOrThrow("transcriptionVerbose")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T {
+ return when {
+ transcription != null -> visitor.visitTranscription(transcription)
+ transcriptionVerbose != null -> visitor.visitTranscriptionVerbose(transcriptionVerbose)
+ else -> visitor.unknown(_json)
+ }
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): AudioTranscriptionCreateResponse = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitTranscription(transcription: Transcription) {
+ transcription.validate()
+ }
+
+ override fun visitTranscriptionVerbose(transcriptionVerbose: TranscriptionVerbose) {
+ transcriptionVerbose.validate()
+ }
+ }
+ )
+ validated = true
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioTranscriptionCreateResponse && transcription == other.transcription && transcriptionVerbose == other.transcriptionVerbose /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(transcription, transcriptionVerbose) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ transcription != null ->
+ "AudioTranscriptionCreateResponse{transcription=$transcription}"
+ transcriptionVerbose != null ->
+ "AudioTranscriptionCreateResponse{transcriptionVerbose=$transcriptionVerbose}"
+ _json != null -> "AudioTranscriptionCreateResponse{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid AudioTranscriptionCreateResponse")
+ }
+
+ companion object {
+
+ /** Represents a transcription response returned by model, based on the provided input. */
+ @JvmStatic
+ fun ofTranscription(transcription: Transcription) =
+ AudioTranscriptionCreateResponse(transcription = transcription)
+
+ /**
+ * Represents a verbose json transcription response returned by model, based on the provided
+ * input.
+ */
+ @JvmStatic
+ fun ofTranscriptionVerbose(transcriptionVerbose: TranscriptionVerbose) =
+ AudioTranscriptionCreateResponse(transcriptionVerbose = transcriptionVerbose)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [AudioTranscriptionCreateResponse] to a
+ * value of type [T].
+ */
+ interface Visitor {
+
+ /** Represents a transcription response returned by model, based on the provided input. */
+ fun visitTranscription(transcription: Transcription): T
+
+ /**
+ * Represents a verbose json transcription response returned by model, based on the provided
+ * input.
+ */
+ fun visitTranscriptionVerbose(transcriptionVerbose: TranscriptionVerbose): T
+
+ /**
+ * Maps an unknown variant of [AudioTranscriptionCreateResponse] to a value of type [T].
+ *
+ * An instance of [AudioTranscriptionCreateResponse] can contain an unknown variant if it
+ * was deserialized from data that doesn't match any known variant. For example, if the SDK
+ * is on an older version than the API, then the API may respond with new variants that the
+ * SDK is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown AudioTranscriptionCreateResponse: $json")
+ }
+ }
+
+ internal class Deserializer :
+ BaseDeserializer(
+ AudioTranscriptionCreateResponse::class
+ ) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): AudioTranscriptionCreateResponse {
+ val json = JsonValue.fromJsonNode(node)
+
+ tryDeserialize(node, jacksonTypeRef()) { it.validate() }
+ ?.let {
+ return AudioTranscriptionCreateResponse(transcription = it, _json = json)
+ }
+ tryDeserialize(node, jacksonTypeRef()) { it.validate() }
+ ?.let {
+ return AudioTranscriptionCreateResponse(transcriptionVerbose = it, _json = json)
+ }
+
+ return AudioTranscriptionCreateResponse(_json = json)
+ }
+ }
+
+ internal class Serializer :
+ BaseSerializer(AudioTranscriptionCreateResponse::class) {
+
+ override fun serialize(
+ value: AudioTranscriptionCreateResponse,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.transcription != null -> generator.writeObject(value.transcription)
+ value.transcriptionVerbose != null ->
+ generator.writeObject(value.transcriptionVerbose)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid AudioTranscriptionCreateResponse")
+ }
+ }
+ }
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateParams.kt
new file mode 100644
index 000000000..fe1ea3cfd
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateParams.kt
@@ -0,0 +1,558 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.openai.core.MultipartField
+import com.openai.core.NoAutoDetect
+import com.openai.core.Params
+import com.openai.core.checkRequired
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+import com.openai.core.toImmutable
+import java.util.Objects
+import java.util.Optional
+
+/** Translates audio into English. */
+class AudioTranslationCreateParams
+private constructor(
+ private val body: Body,
+ private val additionalHeaders: Headers,
+ private val additionalQueryParams: QueryParams,
+) : Params {
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(): ByteArray = body.file()
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(): AudioModel = body.model()
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun prompt(): Optional = body.prompt()
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or
+ * `vtt`.
+ */
+ fun responseFormat(): Optional = body.responseFormat()
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more
+ * random, while lower values like 0.2 will make it more focused and deterministic. If set to 0,
+ * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to
+ * automatically increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(): Optional = body.temperature()
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun _file(): MultipartField = body._file()
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun _model(): MultipartField = body._model()
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun _prompt(): MultipartField = body._prompt()
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or
+ * `vtt`.
+ */
+ fun _responseFormat(): MultipartField = body._responseFormat()
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more
+ * random, while lower values like 0.2 will make it more focused and deterministic. If set to 0,
+ * the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to
+ * automatically increase the temperature until certain thresholds are hit.
+ */
+ fun _temperature(): MultipartField = body._temperature()
+
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ @JvmSynthetic
+ internal fun _body(): Map> =
+ mapOf(
+ "file" to _file(),
+ "model" to _model(),
+ "prompt" to _prompt(),
+ "response_format" to _responseFormat(),
+ "temperature" to _temperature(),
+ )
+ .toImmutable()
+
+ override fun _headers(): Headers = additionalHeaders
+
+ override fun _queryParams(): QueryParams = additionalQueryParams
+
+ @NoAutoDetect
+ class Body
+ @JsonCreator
+ private constructor(
+ private val file: MultipartField,
+ private val model: MultipartField,
+ private val prompt: MultipartField,
+ private val responseFormat: MultipartField,
+ private val temperature: MultipartField,
+ ) {
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(): ByteArray = file.value.getRequired("file")
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(): AudioModel = model.value.getRequired("model")
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun prompt(): Optional = Optional.ofNullable(prompt.value.getNullable("prompt"))
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(): Optional =
+ Optional.ofNullable(responseFormat.value.getNullable("response_format"))
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(): Optional =
+ Optional.ofNullable(temperature.value.getNullable("temperature"))
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun _file(): MultipartField = file
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun _model(): MultipartField = model
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun _prompt(): MultipartField = prompt
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun _responseFormat(): MultipartField = responseFormat
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun _temperature(): MultipartField = temperature
+
+ private var validated: Boolean = false
+
+ fun validate(): Body = apply {
+ if (validated) {
+ return@apply
+ }
+
+ file()
+ model()
+ prompt()
+ responseFormat()
+ temperature()
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Body]. */
+ class Builder internal constructor() {
+
+ private var file: MultipartField? = null
+ private var model: MultipartField? = null
+ private var prompt: MultipartField = MultipartField.of(null)
+ private var responseFormat: MultipartField =
+ MultipartField.of(null)
+ private var temperature: MultipartField = MultipartField.of(null)
+
+ @JvmSynthetic
+ internal fun from(body: Body) = apply {
+ file = body.file
+ model = body.model
+ prompt = body.prompt
+ responseFormat = body.responseFormat
+ temperature = body.temperature
+ }
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: ByteArray) = file(MultipartField.of(file))
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3,
+ * mp4, mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: MultipartField) = apply { this.file = file }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(model: AudioModel) = model(MultipartField.of(model))
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(model: MultipartField) = apply { this.model = model }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper
+ * V2 model) is currently available.
+ */
+ fun model(value: String) = model(AudioModel.of(value))
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be
+ * in English.
+ */
+ fun prompt(prompt: String) = prompt(MultipartField.of(prompt))
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be
+ * in English.
+ */
+ fun prompt(prompt: MultipartField) = apply { this.prompt = prompt }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`,
+ * `verbose_json`, or `vtt`.
+ */
+ fun responseFormat(responseFormat: AudioResponseFormat) =
+ responseFormat(MultipartField.of(responseFormat))
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`,
+ * `verbose_json`, or `vtt`.
+ */
+ fun responseFormat(responseFormat: MultipartField) = apply {
+ this.responseFormat = responseFormat
+ }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and
+ * deterministic. If set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: Double) = temperature(MultipartField.of(temperature))
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the
+ * output more random, while lower values like 0.2 will make it more focused and
+ * deterministic. If set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: MultipartField) = apply {
+ this.temperature = temperature
+ }
+
+ fun build(): Body =
+ Body(
+ checkRequired("file", file),
+ checkRequired("model", model),
+ prompt,
+ responseFormat,
+ temperature,
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Body && file == other.file && model == other.model && prompt == other.prompt && responseFormat == other.responseFormat && temperature == other.temperature /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(file, model, prompt, responseFormat, temperature) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "Body{file=$file, model=$model, prompt=$prompt, responseFormat=$responseFormat, temperature=$temperature}"
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AudioTranslationCreateParams]. */
+ @NoAutoDetect
+ class Builder internal constructor() {
+
+ private var body: Body.Builder = Body.builder()
+ private var additionalHeaders: Headers.Builder = Headers.builder()
+ private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
+
+ @JvmSynthetic
+ internal fun from(audioTranslationCreateParams: AudioTranslationCreateParams) = apply {
+ body = audioTranslationCreateParams.body.toBuilder()
+ additionalHeaders = audioTranslationCreateParams.additionalHeaders.toBuilder()
+ additionalQueryParams = audioTranslationCreateParams.additionalQueryParams.toBuilder()
+ }
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: ByteArray) = apply { body.file(file) }
+
+ /**
+ * The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
+ * mpeg, mpga, m4a, ogg, wav, or webm.
+ */
+ fun file(file: MultipartField) = apply { body.file(file) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(model: AudioModel) = apply { body.model(model) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(model: MultipartField) = apply { body.model(model) }
+
+ /**
+ * ID of the model to use. Only `whisper-1` (which is powered by our open source Whisper V2
+ * model) is currently available.
+ */
+ fun model(value: String) = apply { body.model(value) }
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun prompt(prompt: String) = apply { body.prompt(prompt) }
+
+ /**
+ * An optional text to guide the model's style or continue a previous audio segment. The
+ * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting) should be in
+ * English.
+ */
+ fun prompt(prompt: MultipartField) = apply { body.prompt(prompt) }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(responseFormat: AudioResponseFormat) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`,
+ * or `vtt`.
+ */
+ fun responseFormat(responseFormat: MultipartField) = apply {
+ body.responseFormat(responseFormat)
+ }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: Double) = apply { body.temperature(temperature) }
+
+ /**
+ * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output
+ * more random, while lower values like 0.2 will make it more focused and deterministic. If
+ * set to 0, the model will use
+ * [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically
+ * increase the temperature until certain thresholds are hit.
+ */
+ fun temperature(temperature: MultipartField) = apply {
+ body.temperature(temperature)
+ }
+
+ fun additionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun additionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun putAdditionalHeader(name: String, value: String) = apply {
+ additionalHeaders.put(name, value)
+ }
+
+ fun putAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.put(name, values)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun replaceAdditionalHeaders(name: String, value: String) = apply {
+ additionalHeaders.replace(name, value)
+ }
+
+ fun replaceAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.replace(name, values)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) }
+
+ fun removeAllAdditionalHeaders(names: Set) = apply {
+ additionalHeaders.removeAll(names)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: Map>) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun putAdditionalQueryParam(key: String, value: String) = apply {
+ additionalQueryParams.put(key, value)
+ }
+
+ fun putAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.put(key, values)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, value: String) = apply {
+ additionalQueryParams.replace(key, value)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.replace(key, values)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) }
+
+ fun removeAllAdditionalQueryParams(keys: Set) = apply {
+ additionalQueryParams.removeAll(keys)
+ }
+
+ fun build(): AudioTranslationCreateParams =
+ AudioTranslationCreateParams(
+ body.build(),
+ additionalHeaders.build(),
+ additionalQueryParams.build(),
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioTranslationCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+
+ override fun toString() =
+ "AudioTranslationCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateResponse.kt
new file mode 100644
index 000000000..4486c04e0
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AudioTranslationCreateResponse.kt
@@ -0,0 +1,163 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
+import com.openai.core.BaseDeserializer
+import com.openai.core.BaseSerializer
+import com.openai.core.JsonValue
+import com.openai.core.getOrThrow
+import com.openai.errors.OpenAIInvalidDataException
+import java.util.Objects
+import java.util.Optional
+
+@JsonDeserialize(using = AudioTranslationCreateResponse.Deserializer::class)
+@JsonSerialize(using = AudioTranslationCreateResponse.Serializer::class)
+class AudioTranslationCreateResponse
+private constructor(
+ private val translation: Translation? = null,
+ private val translationVerbose: TranslationVerbose? = null,
+ private val _json: JsonValue? = null,
+) {
+
+ fun translation(): Optional = Optional.ofNullable(translation)
+
+ fun translationVerbose(): Optional = Optional.ofNullable(translationVerbose)
+
+ fun isTranslation(): Boolean = translation != null
+
+ fun isTranslationVerbose(): Boolean = translationVerbose != null
+
+ fun asTranslation(): Translation = translation.getOrThrow("translation")
+
+ fun asTranslationVerbose(): TranslationVerbose =
+ translationVerbose.getOrThrow("translationVerbose")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T {
+ return when {
+ translation != null -> visitor.visitTranslation(translation)
+ translationVerbose != null -> visitor.visitTranslationVerbose(translationVerbose)
+ else -> visitor.unknown(_json)
+ }
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): AudioTranslationCreateResponse = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitTranslation(translation: Translation) {
+ translation.validate()
+ }
+
+ override fun visitTranslationVerbose(translationVerbose: TranslationVerbose) {
+ translationVerbose.validate()
+ }
+ }
+ )
+ validated = true
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AudioTranslationCreateResponse && translation == other.translation && translationVerbose == other.translationVerbose /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(translation, translationVerbose) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ translation != null -> "AudioTranslationCreateResponse{translation=$translation}"
+ translationVerbose != null ->
+ "AudioTranslationCreateResponse{translationVerbose=$translationVerbose}"
+ _json != null -> "AudioTranslationCreateResponse{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid AudioTranslationCreateResponse")
+ }
+
+ companion object {
+
+ @JvmStatic
+ fun ofTranslation(translation: Translation) =
+ AudioTranslationCreateResponse(translation = translation)
+
+ @JvmStatic
+ fun ofTranslationVerbose(translationVerbose: TranslationVerbose) =
+ AudioTranslationCreateResponse(translationVerbose = translationVerbose)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [AudioTranslationCreateResponse] to a
+ * value of type [T].
+ */
+ interface Visitor {
+
+ fun visitTranslation(translation: Translation): T
+
+ fun visitTranslationVerbose(translationVerbose: TranslationVerbose): T
+
+ /**
+ * Maps an unknown variant of [AudioTranslationCreateResponse] to a value of type [T].
+ *
+ * An instance of [AudioTranslationCreateResponse] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example, if the SDK is
+ * on an older version than the API, then the API may respond with new variants that the SDK
+ * is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown AudioTranslationCreateResponse: $json")
+ }
+ }
+
+ internal class Deserializer :
+ BaseDeserializer(AudioTranslationCreateResponse::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): AudioTranslationCreateResponse {
+ val json = JsonValue.fromJsonNode(node)
+
+ tryDeserialize(node, jacksonTypeRef()) { it.validate() }
+ ?.let {
+ return AudioTranslationCreateResponse(translation = it, _json = json)
+ }
+ tryDeserialize(node, jacksonTypeRef()) { it.validate() }
+ ?.let {
+ return AudioTranslationCreateResponse(translationVerbose = it, _json = json)
+ }
+
+ return AudioTranslationCreateResponse(_json = json)
+ }
+ }
+
+ internal class Serializer :
+ BaseSerializer(AudioTranslationCreateResponse::class) {
+
+ override fun serialize(
+ value: AudioTranslationCreateResponse,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.translation != null -> generator.writeObject(value.translation)
+ value.translationVerbose != null -> generator.writeObject(value.translationVerbose)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid AudioTranslationCreateResponse")
+ }
+ }
+ }
+}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt b/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt
index 3490df2de..902e1187a 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -720,14 +721,8 @@ private constructor(
fun addData(data: BatchError) = apply {
this.data =
- (this.data ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(data)
+ (this.data ?: JsonField.of(mutableListOf())).also {
+ checkKnown("data", it).add(data)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt
index 954b422c5..24948a0ae 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt
@@ -13,6 +13,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -890,14 +891,8 @@ private constructor(
*/
fun addTool(tool: AssistantTool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -1881,14 +1876,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -2055,14 +2044,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
@@ -2093,14 +2076,8 @@ private constructor(
*/
fun addVectorStore(vectorStore: VectorStore) = apply {
vectorStores =
- (vectorStores ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStore)
+ (vectorStores ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStores", it).add(vectorStore)
}
}
@@ -2308,14 +2285,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt
index b5f6d7448..324c5d930 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt
@@ -13,6 +13,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -900,14 +901,8 @@ private constructor(
*/
fun addTool(tool: AssistantTool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -2171,14 +2166,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -2320,14 +2309,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt
index cfb5915fd..1916afbf1 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt
@@ -22,6 +22,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.http.Headers
@@ -1206,14 +1207,8 @@ private constructor(
*/
fun addTool(tool: Tool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -2185,14 +2180,8 @@ private constructor(
*/
fun addMessage(message: Message) = apply {
messages =
- (messages ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(message)
+ (messages ?: JsonField.of(mutableListOf())).also {
+ checkKnown("messages", it).add(message)
}
}
@@ -2461,14 +2450,8 @@ private constructor(
*/
fun addAttachment(attachment: Attachment) = apply {
attachments =
- (attachments ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(attachment)
+ (attachments ?: JsonField.of(mutableListOf())).also {
+ checkKnown("attachments", it).add(attachment)
}
}
@@ -2898,14 +2881,8 @@ private constructor(
/** The tools to add this file to. */
fun addTool(tool: Tool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -3352,14 +3329,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -3526,14 +3497,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
@@ -3564,14 +3529,8 @@ private constructor(
*/
fun addVectorStore(vectorStore: VectorStore) = apply {
vectorStores =
- (vectorStores ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStore)
+ (vectorStores ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStores", it).add(vectorStore)
}
}
@@ -3783,14 +3742,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -4120,14 +4073,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -4269,14 +4216,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt
index 0c72cf4d9..5426215d4 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt
@@ -22,6 +22,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.http.Headers
@@ -234,14 +235,8 @@ private constructor(
*/
fun addMessage(message: Message) = apply {
messages =
- (messages ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(message)
+ (messages ?: JsonField.of(mutableListOf())).also {
+ checkKnown("messages", it).add(message)
}
}
@@ -740,14 +735,8 @@ private constructor(
/** A list of files attached to the message, and the tools they should be added to. */
fun addAttachment(attachment: Attachment) = apply {
attachments =
- (attachments ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(attachment)
+ (attachments ?: JsonField.of(mutableListOf())).also {
+ checkKnown("attachments", it).add(attachment)
}
}
@@ -1167,14 +1156,8 @@ private constructor(
/** The tools to add this file to. */
fun addTool(tool: Tool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -1613,14 +1596,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -1787,14 +1764,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
@@ -1825,14 +1796,8 @@ private constructor(
*/
fun addVectorStore(vectorStore: VectorStore) = apply {
vectorStores =
- (vectorStores ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStore)
+ (vectorStores ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStores", it).add(vectorStore)
}
}
@@ -2040,14 +2005,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt
index cf9a18987..c18f842b2 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt
@@ -22,6 +22,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.http.Headers
@@ -278,14 +279,8 @@ private constructor(
/** A list of files attached to the message, and the tools they should be added to. */
fun addAttachment(attachment: Attachment) = apply {
attachments =
- (attachments ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(attachment)
+ (attachments ?: JsonField.of(mutableListOf())).also {
+ checkKnown("attachments", it).add(attachment)
}
}
@@ -952,14 +947,8 @@ private constructor(
/** The tools to add this file to. */
fun addTool(tool: Tool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt
index 24af9ed10..366e0609a 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt
@@ -22,6 +22,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.http.Headers
@@ -833,14 +834,8 @@ private constructor(
/** Adds additional messages to the thread before creating the run. */
fun addAdditionalMessage(additionalMessage: AdditionalMessage) = apply {
additionalMessages =
- (additionalMessages ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(additionalMessage)
+ (additionalMessages ?: JsonField.of(mutableListOf())).also {
+ checkKnown("additionalMessages", it).add(additionalMessage)
}
}
@@ -1327,14 +1322,8 @@ private constructor(
*/
fun addTool(tool: AssistantTool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
@@ -2441,14 +2430,8 @@ private constructor(
/** A list of files attached to the message, and the tools they should be added to. */
fun addAttachment(attachment: Attachment) = apply {
attachments =
- (attachments ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(attachment)
+ (attachments ?: JsonField.of(mutableListOf())).also {
+ checkKnown("attachments", it).add(attachment)
}
}
@@ -2868,14 +2851,8 @@ private constructor(
/** The tools to add this file to. */
fun addTool(tool: Tool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt
index 053eabf0a..a6bdea965 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -128,14 +129,8 @@ private constructor(
/** A list of tools for which the outputs are being submitted. */
fun addToolOutput(toolOutput: ToolOutput) = apply {
toolOutputs =
- (toolOutputs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(toolOutput)
+ (toolOutputs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("toolOutputs", it).add(toolOutput)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt
index eeebc3f69..ba4e3a291 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -674,14 +675,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
@@ -823,14 +818,8 @@ private constructor(
*/
fun addVectorStoreId(vectorStoreId: String) = apply {
vectorStoreIds =
- (vectorStoreIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(vectorStoreId)
+ (vectorStoreIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("vectorStoreIds", it).add(vectorStoreId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt
index b7a68e1f6..f4583b246 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -294,14 +295,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt
index 54f0534c8..d94d823cd 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.http.Headers
import com.openai.core.http.QueryParams
@@ -172,14 +173,8 @@ private constructor(
*/
fun addFileId(fileId: String) = apply {
fileIds =
- (fileIds ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(fileId)
+ (fileIds ?: JsonField.of(mutableListOf())).also {
+ checkKnown("fileIds", it).add(fileId)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt
index 53865268f..9d6a542ba 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -182,14 +183,8 @@ private constructor(
/** A list of chat completion choices. Can be more than one if `n` is greater than 1. */
fun addChoice(choice: Choice) = apply {
choices =
- (choices ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(choice)
+ (choices ?: JsonField.of(mutableListOf())).also {
+ checkKnown("choices", it).add(choice)
}
}
@@ -667,14 +662,8 @@ private constructor(
/** A list of message content tokens with log probability information. */
fun addContent(content: ChatCompletionTokenLogprob) = apply {
this.content =
- (this.content ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(content)
+ (this.content ?: JsonField.of(mutableListOf())).also {
+ checkKnown("content", it).add(content)
}
}
@@ -694,14 +683,8 @@ private constructor(
/** A list of message refusal tokens with log probability information. */
fun addRefusal(refusal: ChatCompletionTokenLogprob) = apply {
this.refusal =
- (this.refusal ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(refusal)
+ (this.refusal ?: JsonField.of(mutableListOf())).also {
+ checkKnown("refusal", it).add(refusal)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt
index 20ae74e30..312d18902 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt
@@ -20,6 +20,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.immutableEmptyMap
@@ -290,14 +291,8 @@ private constructor(
/** The tool calls generated by the model, such as function calls. */
fun addToolCall(toolCall: ChatCompletionMessageToolCall) = apply {
toolCalls =
- (toolCalls ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(toolCall)
+ (toolCalls ?: JsonField.of(mutableListOf())).also {
+ checkKnown("toolCalls", it).add(toolCall)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt
index cd584e5f7..f84f58828 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -217,14 +218,8 @@ private constructor(
*/
fun addChoice(choice: Choice) = apply {
choices =
- (choices ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(choice)
+ (choices ?: JsonField.of(mutableListOf())).also {
+ checkKnown("choices", it).add(choice)
}
}
@@ -675,14 +670,8 @@ private constructor(
fun addToolCall(toolCall: ToolCall) = apply {
toolCalls =
- (toolCalls ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(toolCall)
+ (toolCalls ?: JsonField.of(mutableListOf())).also {
+ checkKnown("toolCalls", it).add(toolCall)
}
}
@@ -1624,14 +1613,8 @@ private constructor(
/** A list of message content tokens with log probability information. */
fun addContent(content: ChatCompletionTokenLogprob) = apply {
this.content =
- (this.content ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(content)
+ (this.content ?: JsonField.of(mutableListOf())).also {
+ checkKnown("content", it).add(content)
}
}
@@ -1651,14 +1634,8 @@ private constructor(
/** A list of message refusal tokens with log probability information. */
fun addRefusal(refusal: ChatCompletionTokenLogprob) = apply {
this.refusal =
- (this.refusal ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(refusal)
+ (this.refusal ?: JsonField.of(mutableListOf())).also {
+ checkKnown("refusal", it).add(refusal)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt
index 6bb970afd..65fbe332e 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt
@@ -22,6 +22,7 @@ import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
import com.openai.core.Params
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.http.Headers
@@ -1366,14 +1367,8 @@ private constructor(
*/
fun addMessage(message: ChatCompletionMessageParam) = apply {
messages =
- (messages ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(message)
+ (messages ?: JsonField.of(mutableListOf())).also {
+ checkKnown("messages", it).add(message)
}
}
@@ -1655,14 +1650,8 @@ private constructor(
@Deprecated("deprecated")
fun addFunction(function: Function) = apply {
functions =
- (functions ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(function)
+ (functions ?: JsonField.of(mutableListOf())).also {
+ checkKnown("functions", it).add(function)
}
}
@@ -1899,14 +1888,8 @@ private constructor(
*/
fun addModality(modality: ChatCompletionModality) = apply {
modalities =
- (modalities ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(modality)
+ (modalities ?: JsonField.of(mutableListOf())).also {
+ checkKnown("modalities", it).add(modality)
}
}
@@ -2382,14 +2365,8 @@ private constructor(
*/
fun addTool(tool: ChatCompletionTool) = apply {
tools =
- (tools ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tool)
+ (tools ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tools", it).add(tool)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt
index 1edec00b7..d7da00c38 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -235,14 +236,8 @@ private constructor(
/** The tool calls generated by the model, such as function calls. */
fun addToolCall(toolCall: ChatCompletionMessageToolCall) = apply {
toolCalls =
- (toolCalls ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(toolCall)
+ (toolCalls ?: JsonField.of(mutableListOf())).also {
+ checkKnown("toolCalls", it).add(toolCall)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStoreMessage.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStoreMessage.kt
index d3615cfba..3d2755641 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStoreMessage.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStoreMessage.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -236,14 +237,8 @@ private constructor(
/** The tool calls generated by the model, such as function calls. */
fun addToolCall(toolCall: ChatCompletionMessageToolCall) = apply {
toolCalls =
- (toolCalls ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(toolCall)
+ (toolCalls ?: JsonField.of(mutableListOf())).also {
+ checkKnown("toolCalls", it).add(toolCall)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt
index 87648b585..6a43736c7 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -165,15 +166,7 @@ private constructor(
*/
fun addByte(byte_: Long) = apply {
bytes =
- (bytes ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(byte_)
- }
+ (bytes ?: JsonField.of(mutableListOf())).also { checkKnown("bytes", it).add(byte_) }
}
/**
@@ -208,14 +201,8 @@ private constructor(
*/
fun addTopLogprob(topLogprob: TopLogprob) = apply {
topLogprobs =
- (topLogprobs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(topLogprob)
+ (topLogprobs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("topLogprobs", it).add(topLogprob)
}
}
@@ -379,14 +366,8 @@ private constructor(
*/
fun addByte(byte_: Long) = apply {
bytes =
- (bytes ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(byte_)
+ (bytes ?: JsonField.of(mutableListOf())).also {
+ checkKnown("bytes", it).add(byte_)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCall.kt b/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCall.kt
index 1210b30f0..ca1b5a981 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCall.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCall.kt
@@ -20,6 +20,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.immutableEmptyMap
@@ -256,14 +257,8 @@ private constructor(
*/
fun addOutput(output: Output) = apply {
outputs =
- (outputs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(output)
+ (outputs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("outputs", it).add(output)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCallDelta.kt b/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCallDelta.kt
index 0ea5289eb..bd43e7fba 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCallDelta.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/CodeInterpreterToolCallDelta.kt
@@ -20,6 +20,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
import com.openai.core.immutableEmptyMap
@@ -274,14 +275,8 @@ private constructor(
*/
fun addOutput(output: Output) = apply {
outputs =
- (outputs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(output)
+ (outputs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("outputs", it).add(output)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt b/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt
index 0e9db0105..0a1563927 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -171,14 +172,8 @@ private constructor(
/** The list of completion choices the model generated for the input prompt. */
fun addChoice(choice: CompletionChoice) = apply {
choices =
- (choices ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(choice)
+ (choices ?: JsonField.of(mutableListOf())).also {
+ checkKnown("choices", it).add(choice)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt b/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt
index 3008a794d..db481b2e8 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt
@@ -12,6 +12,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -377,14 +378,8 @@ private constructor(
fun addTextOffset(textOffset: Long) = apply {
this.textOffset =
- (this.textOffset ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(textOffset)
+ (this.textOffset ?: JsonField.of(mutableListOf())).also {
+ checkKnown("textOffset", it).add(textOffset)
}
}
@@ -397,14 +392,8 @@ private constructor(
fun addTokenLogprob(tokenLogprob: Double) = apply {
tokenLogprobs =
- (tokenLogprobs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(tokenLogprob)
+ (tokenLogprobs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tokenLogprobs", it).add(tokenLogprob)
}
}
@@ -416,14 +405,8 @@ private constructor(
fun addToken(token: String) = apply {
tokens =
- (tokens ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(token)
+ (tokens ?: JsonField.of(mutableListOf())).also {
+ checkKnown("tokens", it).add(token)
}
}
@@ -435,14 +418,8 @@ private constructor(
fun addTopLogprob(topLogprob: TopLogprob) = apply {
topLogprobs =
- (topLogprobs ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(topLogprob)
+ (topLogprobs ?: JsonField.of(mutableListOf())).also {
+ checkKnown("topLogprobs", it).add(topLogprob)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt
index 48bc376e1..9680ca910 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -109,14 +110,8 @@ private constructor(
/** The list of embeddings generated by the model. */
fun addData(data: Embedding) = apply {
this.data =
- (this.data ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(data)
+ (this.data ?: JsonField.of(mutableListOf())).also {
+ checkKnown("data", it).add(data)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt b/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt
index 5d64ae936..171317c65 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
import com.openai.core.NoAutoDetect
+import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
@@ -118,14 +119,8 @@ private constructor(
*/
fun addEmbedding(embedding: Double) = apply {
this.embedding =
- (this.embedding ?: JsonField.of(mutableListOf())).apply {
- asKnown()
- .orElseThrow {
- IllegalStateException(
- "Field was set to non-list type: ${javaClass.simpleName}"
- )
- }
- .add(embedding)
+ (this.embedding ?: JsonField.of(mutableListOf())).also {
+ checkKnown("embedding", it).add(embedding)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FileCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/FileCreateParams.kt
new file mode 100644
index 000000000..6a50b282a
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/FileCreateParams.kt
@@ -0,0 +1,364 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models
+
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.openai.core.MultipartField
+import com.openai.core.NoAutoDetect
+import com.openai.core.Params
+import com.openai.core.checkRequired
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+import com.openai.core.toImmutable
+import java.util.Objects
+
+/**
+ * Upload a file that can be used across various endpoints. Individual files can be up to 512 MB,
+ * and the size of all files uploaded by one organization can be up to 100 GB.
+ *
+ * The Assistants API supports files up to 2 million tokens and of specific file types. See the
+ * [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for details.
+ *
+ * The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for
+ * fine-tuning [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
+ * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
+ * models.
+ *
+ * The Batch API only supports `.jsonl` files up to 200 MB in size. The input also has a specific
+ * required [format](https://platform.openai.com/docs/api-reference/batch/request-input).
+ *
+ * Please [contact us](https://help.openai.com/) if you need to increase these storage limits.
+ */
+class FileCreateParams
+private constructor(
+ private val body: Body,
+ private val additionalHeaders: Headers,
+ private val additionalQueryParams: QueryParams,
+) : Params {
+
+ /** The File object (not file name) to be uploaded. */
+ fun file(): ByteArray = body.file()
+
+ /**
+ * The intended purpose of the uploaded file.
+ *
+ * Use "assistants" for [Assistants](https://platform.openai.com/docs/api-reference/assistants)
+ * and [Message](https://platform.openai.com/docs/api-reference/messages) files, "vision" for
+ * Assistants image file inputs, "batch" for
+ * [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
+ * [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
+ */
+ fun purpose(): FilePurpose = body.purpose()
+
+ /** The File object (not file name) to be uploaded. */
+ fun _file(): MultipartField = body._file()
+
+ /**
+ * The intended purpose of the uploaded file.
+ *
+ * Use "assistants" for [Assistants](https://platform.openai.com/docs/api-reference/assistants)
+ * and [Message](https://platform.openai.com/docs/api-reference/messages) files, "vision" for
+ * Assistants image file inputs, "batch" for
+ * [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
+ * [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
+ */
+ fun _purpose(): MultipartField = body._purpose()
+
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ @JvmSynthetic
+ internal fun _body(): Map