Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ NOTES:
* There is https://github.com/openai/openai-java, which OpenAI describes as
"The official Java library for the OpenAI API", but:
1. That "official" library lags behind https://github.com/openai/openai-openapi/blob/master/openapi.yaml
For example, as of 2025/02/12 is is **STILL** lacking OpenAI's Realtime API (https://platform.openai.com/docs/api-reference/realtime), which is my main use case.
For example: OpenAI's Realtime API (https://platform.openai.com/docs/api-reference/realtime),
which is my main use case, is in https://github.com/openai/openai-openapi/blob/master/openapi.yaml,
but as of 2025/03/28 it is **STILL** not in https://github.com/openai/openai-java. :/
2. `openai-java` is actually a nearly fully modernized Kotlin library, so the name
`openai-java` is legacy;
it really should be named `openai-kotlin`.
Expand Down Expand Up @@ -60,6 +62,13 @@ All of my changes can be seen at:
https://github.com/swooby/openai-openapi-kotlin/pull/1/files

## Updates
Very similar to original generation.

It usually takes me 1-2 hours to do this.
More if there are more changes.
Less is there are less changes.
Keep in mind that some of this time is verifying/updating the below documentation of any changes.

When a new spec comes out:
1. Make sure to start from a fresh/stashed checkout.
2. `rm -r ./lib/src`
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kotlin = "2.0.21"
kotlintestRunnerJunit5 = "3.4.2"
squareupMoshiKotlin = "1.15.1"
squareupOkhttpBom = "4.12.0"
spotless = "7.0.2"

[libraries]
kotlintest-runner-junit5 = { module = "io.kotlintest:kotlintest-runner-junit5", version.ref = "kotlintestRunnerJunit5" }
Expand All @@ -12,3 +13,4 @@ squareup-okhttp3 = { module = "com.squareup.okhttp3:okhttp" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sun Dec 15 17:37:56 PST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
217 changes: 201 additions & 16 deletions lib/README.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
alias(libs.plugins.kotlin.jvm)
id("com.diffplug.spotless") version "7.0.2"
// id("maven-publish")
alias(libs.plugins.spotless)
}

group = "com.openai"
Expand Down Expand Up @@ -32,6 +32,9 @@ dependencies {
testImplementation(libs.kotlintest.runner.junit5)
}

// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
spotless {
kotlin {
ktfmt("0.54").googleStyle().configure {
Expand Down
23 changes: 23 additions & 0 deletions lib/docs/Annotation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Annotation

## Properties
| Name | Type | Description | Notes |
| ------------ | ------------- | ------------- | ------------- |
| **type** | [**inline**](#Type) | The type of the file citation. Always `file_citation`. | |
| **index** | **kotlin.Int** | The index of the file in the list of files. | |
| **fileId** | **kotlin.String** | The ID of the file. | |
| **url** | **kotlin.String** | The URL of the web resource. | |
| **title** | **kotlin.String** | The title of the web resource. | |
| **startIndex** | **kotlin.Int** | The index of the first character of the URL citation in the message. | |
| **endIndex** | **kotlin.Int** | The index of the last character of the URL citation in the message. | |


<a id="Type"></a>
## Enum: type
| Name | Value |
| ---- | ----- |
| type | file_citation, url_citation, file_path |



2 changes: 1 addition & 1 deletion lib/docs/AssistantObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| **toolResources** | [**AssistantObjectToolResources**](AssistantObjectToolResources.md) | | [optional] |
| **temperature** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. | [optional] |
| **topP** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. | [optional] |
| **responseFormat** | [**AssistantObjectResponseFormat**](AssistantObjectResponseFormat.md) | | [optional] |
| **responseFormat** | [**AssistantsApiResponseFormatOption**](AssistantsApiResponseFormatOption.md) | | [optional] |


<a id="`Object`"></a>
Expand Down
4 changes: 4 additions & 0 deletions lib/docs/AssistantSupportedModels.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

* `gptMinus4oMinusMiniMinus2024Minus07Minus18` (value: `"gpt-4o-mini-2024-07-18"`)

* `gptMinus4Period5MinusPreview` (value: `"gpt-4.5-preview"`)

* `gptMinus4Period5MinusPreviewMinus2025Minus02Minus27` (value: `"gpt-4.5-preview-2025-02-27"`)

* `gptMinus4MinusTurbo` (value: `"gpt-4-turbo"`)

* `gptMinus4MinusTurboMinus2024Minus04Minus09` (value: `"gpt-4-turbo-2024-04-09"`)
Expand Down
4 changes: 2 additions & 2 deletions lib/docs/AssistantsApiResponseFormatOption.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## Properties
| Name | Type | Description | Notes |
| ------------ | ------------- | ------------- | ------------- |
| **type** | [**inline**](#Type) | The type of response format being defined: &#x60;text&#x60; | |
| **jsonSchema** | [**ResponseFormatJsonSchemaJsonSchema**](ResponseFormatJsonSchemaJsonSchema.md) | | |
| **type** | [**inline**](#Type) | The type of response format being defined. Always &#x60;text&#x60;. | |
| **jsonSchema** | [**JSONSchema**](JSONSchema.md) | | |


<a id="Type"></a>
Expand Down
18 changes: 11 additions & 7 deletions lib/docs/AudioApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Configure ApiKeyAuth:

<a id="createTranscription"></a>
# **createTranscription**
> CreateTranscription200Response createTranscription(file, model, language, prompt, responseFormat, temperature, timestampGranularities)
> CreateTranscription200Response createTranscription(file, model, language, prompt, responseFormat, temperature, include, timestampGranularities, stream)

Transcribes audio into the input language.

Expand All @@ -74,9 +74,11 @@ val language : kotlin.String = language_example // kotlin.String | The language
val prompt : kotlin.String = prompt_example // kotlin.String | An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text#prompting) should match the audio language.
val responseFormat : AudioResponseFormat = // AudioResponseFormat |
val temperature : java.math.BigDecimal = 8.14 // java.math.BigDecimal | 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.
val include : kotlin.collections.List<TranscriptionInclude> = // kotlin.collections.List<TranscriptionInclude> | Additional information to include in the transcription response. `logprobs` will return the log probabilities of the tokens in the response to understand the model's confidence in the transcription. `logprobs` only works with response_format set to `json` and only with the models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe`.
val timestampGranularities : kotlin.collections.List<kotlin.String> = // kotlin.collections.List<kotlin.String> | 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.
val stream : kotlin.Boolean = true // kotlin.Boolean | If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format). See the [Streaming section of the Speech-to-Text guide](/docs/guides/speech-to-text?lang=curl#streaming-transcriptions) for more information. Note: Streaming is not supported for the `whisper-1` model and will be ignored.
Copy link

Copilot AI Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for 'stream' is set to true in the code sample, yet the accompanying documentation notes a default of false. Consider aligning the default value to avoid potential confusion.

Suggested change
val stream : kotlin.Boolean = true // kotlin.Boolean | If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format). See the [Streaming section of the Speech-to-Text guide](/docs/guides/speech-to-text?lang=curl#streaming-transcriptions) for more information. Note: Streaming is not supported for the `whisper-1` model and will be ignored.
val stream : kotlin.Boolean = false // kotlin.Boolean | If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format). See the [Streaming section of the Speech-to-Text guide](/docs/guides/speech-to-text?lang=curl#streaming-transcriptions) for more information. Note: Streaming is not supported for the `whisper-1` model and will be ignored.

Copilot uses AI. Check for mistakes.
try {
val result : CreateTranscription200Response = apiInstance.createTranscription(file, model, language, prompt, responseFormat, temperature, timestampGranularities)
val result : CreateTranscription200Response = apiInstance.createTranscription(file, model, language, prompt, responseFormat, temperature, include, timestampGranularities, stream)
println(result)
} catch (e: ClientException) {
println("4xx response calling AudioApi#createTranscription")
Expand All @@ -94,9 +96,11 @@ try {
| **prompt** | **kotlin.String**| An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text#prompting) should match the audio language. | [optional] |
| **responseFormat** | [**AudioResponseFormat**](AudioResponseFormat.md)| | [optional] [default to json] [enum: json, text, srt, verbose_json, vtt] |
| **temperature** | **java.math.BigDecimal**| 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. | [optional] [default to 0] |
| **include** | [**kotlin.collections.List&lt;TranscriptionInclude&gt;**](TranscriptionInclude.md)| Additional information to include in the transcription response. &#x60;logprobs&#x60; will return the log probabilities of the tokens in the response to understand the model&#39;s confidence in the transcription. &#x60;logprobs&#x60; only works with response_format set to &#x60;json&#x60; and only with the models &#x60;gpt-4o-transcribe&#x60; and &#x60;gpt-4o-mini-transcribe&#x60;. | [optional] |
| **timestampGranularities** | [**kotlin.collections.List&lt;kotlin.String&gt;**](kotlin.String.md)| The timestamp granularities to populate for this transcription. &#x60;response_format&#x60; must be set &#x60;verbose_json&#x60; to use timestamp granularities. Either or both of these options are supported: &#x60;word&#x60;, or &#x60;segment&#x60;. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency. | [optional] [enum: word, segment] |
| Name | Type | Description | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **timestampGranularities** | [**kotlin.collections.List&lt;kotlin.String&gt;**](kotlin.String.md)| The timestamp granularities to populate for this transcription. &#x60;response_format&#x60; must be set &#x60;verbose_json&#x60; to use timestamp granularities. Either or both of these options are supported: &#x60;word&#x60;, or &#x60;segment&#x60;. Note: There is no additional latency for segment timestamps, but generating word timestamps incurs additional latency. | [optional] [enum: word, segment] |
| **stream** | **kotlin.Boolean**| If set to true, the model response data will be streamed to the client as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format). See the [Streaming section of the Speech-to-Text guide](/docs/guides/speech-to-text?lang&#x3D;curl#streaming-transcriptions) for more information. Note: Streaming is not supported for the &#x60;whisper-1&#x60; model and will be ignored. | [optional] [default to false] |

### Return type

Expand Down Expand Up @@ -127,9 +131,9 @@ Translates audio into English.

val apiInstance = AudioApi()
val file : java.io.File = BINARY_DATA_HERE // java.io.File | The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.
val model : CreateTranscriptionRequestModel = // CreateTranscriptionRequestModel |
val model : CreateTranslationRequestModel = // CreateTranslationRequestModel |
val prompt : kotlin.String = prompt_example // kotlin.String | An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text#prompting) should be in English.
val responseFormat : AudioResponseFormat = // AudioResponseFormat |
val responseFormat : kotlin.String = responseFormat_example // kotlin.String | The format of the output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`.
val temperature : java.math.BigDecimal = 8.14 // java.math.BigDecimal | 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.
try {
val result : CreateTranslation200Response = apiInstance.createTranslation(file, model, prompt, responseFormat, temperature)
Expand All @@ -145,9 +149,9 @@ try {

### Parameters
| **file** | **java.io.File**| The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. | |
| **model** | [**CreateTranscriptionRequestModel**](CreateTranscriptionRequestModel.md)| | |
| **model** | [**CreateTranslationRequestModel**](CreateTranslationRequestModel.md)| | |
| **prompt** | **kotlin.String**| An optional text to guide the model&#39;s style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text#prompting) should be in English. | [optional] |
| **responseFormat** | [**AudioResponseFormat**](AudioResponseFormat.md)| | [optional] [default to json] [enum: json, text, srt, verbose_json, vtt] |
| **responseFormat** | **kotlin.String**| The format of the output, in one of these options: &#x60;json&#x60;, &#x60;text&#x60;, &#x60;srt&#x60;, &#x60;verbose_json&#x60;, or &#x60;vtt&#x60;. | [optional] [default to json] [enum: json, text, srt, verbose_json, vtt] |
| Name | Type | Description | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **temperature** | **java.math.BigDecimal**| 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. | [optional] [default to 0] |
Expand Down
Loading
Loading