Skip to content

release: 0.43.0 #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2025
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.42.0"
".": "0.43.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 80
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-4bce8217a697c729ac98046d4caf2c9e826b54c427fb0ab4f98e549a2e0ce31c.yml
openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e
config_hash: 178ba1bfb1237bf6b94abb3408072aa7
config_hash: 578c5bff4208d560c0c280f13324409f
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.43.0 (2025-04-02)

Full Changelog: [v0.42.0...v0.43.0](https://github.com/openai/openai-java/compare/v0.42.0...v0.43.0)

### Features

* **api:** manual updates ([9679525](https://github.com/openai/openai-java/commit/967952553d5fd2e7f47cd7c82fac45cc9dcef43e))
* **client:** expose request body setter and getter ([#392](https://github.com/openai/openai-java/issues/392)) ([eaa0bc9](https://github.com/openai/openai-java/commit/eaa0bc96ba8898e064709a571e97d6b99f478597))


### Chores

* **internal:** codegen related update ([#389](https://github.com/openai/openai-java/issues/389)) ([b0e9d31](https://github.com/openai/openai-java/commit/b0e9d316bde7866f0d6c9381a5bec5a6667f46f6))

## 0.42.0 (2025-04-02)

Full Changelog: [v0.41.1...v0.42.0](https://github.com/openai/openai-java/compare/v0.41.1...v0.42.0)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.42.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.42.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.42.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.43.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.43.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.43.0)

<!-- x-release-please-end -->

The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https://platform.openai.com/docs) from applications written in Java.

<!-- x-release-please-start-version -->

The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.42.0).
The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.43.0).

<!-- x-release-please-end -->

Expand All @@ -29,7 +29,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
### Gradle

```kotlin
implementation("com.openai:openai-java:0.42.0")
implementation("com.openai:openai-java:0.43.0")
```

### Maven
Expand All @@ -38,7 +38,7 @@ implementation("com.openai:openai-java:0.42.0")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>0.42.0</version>
<version>0.43.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {

allprojects {
group = "com.openai"
version = "0.42.0" // x-release-please-version
version = "0.43.0" // x-release-please-version
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@ package com.openai.core

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.cfg.CoercionAction
import com.fasterxml.jackson.databind.cfg.CoercionInputShape
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.type.LogicalType
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.kotlinModule
import java.io.InputStream
import java.time.DateTimeException
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoField

fun jsonMapper(): JsonMapper =
JsonMapper.builder()
.addModule(kotlinModule())
.addModule(Jdk8Module())
.addModule(JavaTimeModule())
.addModule(SimpleModule().addSerializer(InputStreamJsonSerializer))
.addModule(
SimpleModule()
.addSerializer(InputStreamSerializer)
.addDeserializer(LocalDateTime::class.java, LenientLocalDateTimeDeserializer())
)
.withCoercionConfig(LogicalType.Boolean) {
it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
.setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
Expand Down Expand Up @@ -91,7 +105,10 @@ fun jsonMapper(): JsonMapper =
.disable(MapperFeature.AUTO_DETECT_SETTERS)
.build()

private object InputStreamJsonSerializer : BaseSerializer<InputStream>(InputStream::class) {
/** A serializer that serializes [InputStream] to bytes. */
private object InputStreamSerializer : BaseSerializer<InputStream>(InputStream::class) {

private fun readResolve(): Any = InputStreamSerializer

override fun serialize(
value: InputStream?,
Expand All @@ -105,3 +122,46 @@ private object InputStreamJsonSerializer : BaseSerializer<InputStream>(InputStre
}
}
}

/**
* A deserializer that can deserialize [LocalDateTime] from datetimes, dates, and zoned datetimes.
*/
private class LenientLocalDateTimeDeserializer :
StdDeserializer<LocalDateTime>(LocalDateTime::class.java) {

companion object {

private val DATE_TIME_FORMATTERS =
listOf(
DateTimeFormatter.ISO_LOCAL_DATE_TIME,
DateTimeFormatter.ISO_LOCAL_DATE,
DateTimeFormatter.ISO_ZONED_DATE_TIME,
)
}

override fun logicalType(): LogicalType = LogicalType.DateTime

override fun deserialize(p: JsonParser, context: DeserializationContext?): LocalDateTime {
val exceptions = mutableListOf<Exception>()

for (formatter in DATE_TIME_FORMATTERS) {
try {
val temporal = formatter.parse(p.text)

return when {
!temporal.isSupported(ChronoField.HOUR_OF_DAY) ->
LocalDate.from(temporal).atStartOfDay()
!temporal.isSupported(ChronoField.OFFSET_SECONDS) ->
LocalDateTime.from(temporal)
else -> ZonedDateTime.from(temporal).toLocalDateTime()
}
} catch (e: DateTimeException) {
exceptions.add(e)
}
}

throw JsonParseException(p, "Cannot parse `LocalDateTime` from value: ${p.text}").apply {
exceptions.forEach { addSuppressed(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ private constructor(
additionalQueryParams = speechCreateParams.additionalQueryParams.toBuilder()
}

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [input]
* - [model]
* - [voice]
* - [instructions]
* - [responseFormat]
* - etc.
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/** The text to generate audio for. The maximum length is 4096 characters. */
fun input(input: String) = apply { body.input(input) }

Expand Down Expand Up @@ -408,7 +422,7 @@ private constructor(
)
}

@JvmSynthetic internal fun _body(): Body = body
fun _body(): Body = body

override fun _headers(): Headers = additionalHeaders

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ private constructor(
additionalQueryParams = transcriptionCreateParams.additionalQueryParams.toBuilder()
}

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [file]
* - [model]
* - [include]
* - [language]
* - [prompt]
* - etc.
*/
fun body(body: Body) = apply { this.body = body.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.
Expand Down Expand Up @@ -503,8 +517,7 @@ private constructor(
)
}

@JvmSynthetic
internal fun _body(): Map<String, MultipartField<*>> =
fun _body(): Map<String, MultipartField<*>> =
mapOf(
"file" to _file(),
"model" to _model(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ private constructor(
additionalQueryParams = translationCreateParams.additionalQueryParams.toBuilder()
}

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [file]
* - [model]
* - [prompt]
* - [responseFormat]
* - [temperature]
* - etc.
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/**
* The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
Expand Down Expand Up @@ -372,8 +386,7 @@ private constructor(
)
}

@JvmSynthetic
internal fun _body(): Map<String, MultipartField<*>> =
fun _body(): Map<String, MultipartField<*>> =
mapOf(
"file" to _file(),
"model" to _model(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ private constructor(
)
}

@JvmSynthetic
internal fun _body(): Optional<Map<String, JsonValue>> =
fun _body(): Optional<Map<String, JsonValue>> =
Optional.ofNullable(additionalBodyProperties.ifEmpty { null })

fun _pathParam(index: Int): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ private constructor(
additionalQueryParams = batchCreateParams.additionalQueryParams.toBuilder()
}

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [completionWindow]
* - [endpoint]
* - [inputFileId]
* - [metadata]
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/**
* The time frame within which the batch should be processed. Currently only `24h` is
* supported.
Expand Down Expand Up @@ -363,7 +375,7 @@ private constructor(
)
}

@JvmSynthetic internal fun _body(): Body = body
fun _body(): Body = body

override fun _headers(): Headers = additionalHeaders

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,20 @@ private constructor(
additionalQueryParams = assistantCreateParams.additionalQueryParams.toBuilder()
}

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [model]
* - [description]
* - [instructions]
* - [metadata]
* - [name]
* - etc.
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/**
* ID of the model to use. You can use the
* [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all
Expand Down Expand Up @@ -728,7 +742,7 @@ private constructor(
)
}

@JvmSynthetic internal fun _body(): Body = body
fun _body(): Body = body

override fun _headers(): Headers = additionalHeaders

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ private constructor(
)
}

@JvmSynthetic
internal fun _body(): Optional<Map<String, JsonValue>> =
fun _body(): Optional<Map<String, JsonValue>> =
Optional.ofNullable(additionalBodyProperties.ifEmpty { null })

fun _pathParam(index: Int): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ private constructor(

fun assistantId(assistantId: String) = apply { this.assistantId = assistantId }

/**
* Sets the entire request body.
*
* This is generally only useful if you are already constructing the body separately.
* Otherwise, it's more convenient to use the top-level setters instead:
* - [description]
* - [instructions]
* - [metadata]
* - [model]
* - [name]
* - etc.
*/
fun body(body: Body) = apply { this.body = body.toBuilder() }

/** The description of the assistant. The maximum length is 512 characters. */
fun description(description: String?) = apply { body.description(description) }

Expand Down Expand Up @@ -726,7 +740,7 @@ private constructor(
)
}

@JvmSynthetic internal fun _body(): Body = body
fun _body(): Body = body

fun _pathParam(index: Int): String =
when (index) {
Expand Down
Loading