Skip to content
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.11.3"
".": "0.11.4"
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 0.11.4 (2025-01-16)

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

### Chores

* **internal:** add and tweak check functions ([#117](https://github.com/openai/openai-java/issues/117)) ([627cb56](https://github.com/openai/openai-java/commit/627cb568af9ff28a570de4d9ebae04a2ba5c46d7))
* **internal:** extract a `checkRequired` function ([#113](https://github.com/openai/openai-java/issues/113)) ([b63b2b1](https://github.com/openai/openai-java/commit/b63b2b159bd6c9d01d22a64980a13bfcc3f64863))
* **internal:** fix tests ([61ada05](https://github.com/openai/openai-java/commit/61ada05fe8d4a3509fc59c6626611e5dbc308aff))
* **internal:** remove space ([#125](https://github.com/openai/openai-java/issues/125)) ([27bfcec](https://github.com/openai/openai-java/commit/27bfcec6deccf7d000a305e630b4eda012154222))
* **internal:** remove unused gradle task ([#121](https://github.com/openai/openai-java/issues/121)) ([0b4e59a](https://github.com/openai/openai-java/commit/0b4e59abac5343abe8cda697864fe8afa9fe1774))
* **internal:** tweak client options nullability handling ([627cb56](https://github.com/openai/openai-java/commit/627cb568af9ff28a570de4d9ebae04a2ba5c46d7))
* simplify examples involving lists ([#118](https://github.com/openai/openai-java/issues/118)) ([557c071](https://github.com/openai/openai-java/commit/557c0713590c7e0556dd68e77e4179fde8923c86))
* simplify examples involving unions ([#119](https://github.com/openai/openai-java/issues/119)) ([7c7795c](https://github.com/openai/openai-java/commit/7c7795c852c09bca6ab23b22435fd7846730e95c))
* **types:** rename vector store chunking strategy ([#116](https://github.com/openai/openai-java/issues/116)) ([387935f](https://github.com/openai/openai-java/commit/387935fa16873ae252522aa926d3ed701186a292))


### Documentation

* don't mention a non-existent SDK ([#120](https://github.com/openai/openai-java/issues/120)) ([23eb658](https://github.com/openai/openai-java/commit/23eb6584b4ba7dfd8e5a9147d815ab01e364726e))

## 0.11.3 (2025-01-14)

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

<!-- 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.11.3)
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.11.4)

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

The OpenAI Java SDK provides convenient access to the OpenAI REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property.

The OpenAI Java SDK is similar to the OpenAI Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions.

## Documentation

The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs).
Expand All @@ -32,7 +30,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfo
<!-- x-release-please-start-version -->

```kotlin
implementation("com.openai:openai-java:0.11.3")
implementation("com.openai:openai-java:0.11.4")
```

#### Maven
Expand All @@ -41,7 +39,7 @@ implementation("com.openai:openai-java:0.11.3")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>0.11.3</version>
<version>0.11.4</version>
</dependency>
```

Expand Down Expand Up @@ -92,16 +90,14 @@ To create a new chat completion, first use the `ChatCompletionCreateParams` buil
```java
import com.openai.models.ChatCompletion;
import com.openai.models.ChatCompletionCreateParams;
import com.openai.models.ChatCompletionMessageParam;
import com.openai.models.ChatCompletionUserMessageParam;
import com.openai.models.ChatModel;
import java.util.List;

ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
.messages(List.of(ChatCompletionMessageParam.ofChatCompletionUserMessageParam(ChatCompletionUserMessageParam.builder()
.addMessage(ChatCompletionUserMessageParam.builder()
.role(ChatCompletionUserMessageParam.Role.USER)
.content(ChatCompletionUserMessageParam.Content.ofTextContent("Say this is a test"))
.build())))
.content("Say this is a test")
.build())
.model(ChatModel.O1)
.build();
ChatCompletion chatCompletion = client.chat().completions().create(params);
Expand Down
8 changes: 1 addition & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ plugins {

allprojects {
group = "com.openai"
version = "0.11.3" // x-release-please-version
version = "0.11.4" // x-release-please-version
}

subprojects {
apply(plugin = "org.jetbrains.dokka")
}

tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
30 changes: 30 additions & 0 deletions openai-java-core/src/main/kotlin/com/openai/core/Check.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@file:JvmName("Check")

package com.openai.core

@JvmSynthetic
internal fun <T : Any> checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required, but was not set" }

@JvmSynthetic
internal fun checkLength(name: String, value: String, length: Int): String =
value.also {
check(it.length == length) { "`$name` must have length $length, but was ${it.length}" }
}

@JvmSynthetic
internal fun checkMinLength(name: String, value: String, minLength: Int): String =
value.also {
check(it.length >= minLength) {
if (minLength == 1) "`$name` must be non-empty, but was empty"
else "`$name` must have at least length $minLength, but was ${it.length}"
}
}

@JvmSynthetic
internal fun checkMaxLength(name: String, value: String, maxLength: Int): String =
value.also {
check(it.length <= maxLength) {
"`$name` must have at most length $maxLength, but was ${it.length}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private constructor(
}

fun build(): ClientOptions {
checkNotNull(httpClient) { "`httpClient` is required but was not set" }
checkNotNull(credential) { "`credential` is required but was not set" }
val httpClient = checkRequired("httpClient", httpClient)
val credential = checkRequired("credential", credential)

val headers = Headers.builder()
val queryParams = QueryParams.builder()
Expand All @@ -245,12 +245,12 @@ private constructor(
organization?.let { headers.put("OpenAI-Organization", it) }
project?.let { headers.put("OpenAI-Project", it) }

when (val currentCredential = credential) {
when (credential) {
is AzureApiKeyCredential -> {
headers.put("api-key", currentCredential.apiKey())
headers.put("api-key", credential.apiKey())
}
is BearerTokenCredential -> {
headers.put("Authorization", "Bearer ${currentCredential.token()}")
headers.put("Authorization", "Bearer ${credential.token()}")
}
else -> {
throw IllegalArgumentException("Invalid credential type")
Expand All @@ -268,10 +268,10 @@ private constructor(
queryParams.replaceAll(this.queryParams.build())

return ClientOptions(
httpClient!!,
httpClient,
PhantomReachableClosingHttpClient(
RetryingHttpClient.builder()
.httpClient(httpClient!!)
.httpClient(httpClient)
.clock(clock)
.maxRetries(maxRetries)
.build()
Expand All @@ -298,7 +298,7 @@ private constructor(
queryParams.build(),
responseValidation,
maxRetries,
credential!!,
credential,
organization,
project,
)
Expand Down
2 changes: 2 additions & 0 deletions openai-java-core/src/main/kotlin/com/openai/core/Values.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ sealed class JsonField<out T : Any> {
is JsonValue -> this
}

@JvmSynthetic fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume)

fun <R> accept(visitor: Visitor<T, R>): R =
when (this) {
is KnownValue -> visitor.visitKnown(value)
Expand Down
20 changes: 10 additions & 10 deletions openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
import com.openai.errors.OpenAIInvalidDataException
Expand Down Expand Up @@ -688,16 +689,15 @@ private constructor(

fun build(): Assistant =
Assistant(
checkNotNull(id) { "`id` is required but was not set" },
checkNotNull(createdAt) { "`createdAt` is required but was not set" },
checkNotNull(description) { "`description` is required but was not set" },
checkNotNull(instructions) { "`instructions` is required but was not set" },
checkNotNull(metadata) { "`metadata` is required but was not set" },
checkNotNull(model) { "`model` is required but was not set" },
checkNotNull(name) { "`name` is required but was not set" },
checkNotNull(object_) { "`object_` is required but was not set" },
checkNotNull(tools) { "`tools` is required but was not set" }
.map { it.toImmutable() },
checkRequired("id", id),
checkRequired("createdAt", createdAt),
checkRequired("description", description),
checkRequired("instructions", instructions),
checkRequired("metadata", metadata),
checkRequired("model", model),
checkRequired("name", name),
checkRequired("object_", object_),
checkRequired("tools", tools).map { it.toImmutable() },
responseFormat,
temperature,
toolResources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.checkRequired
import com.openai.core.immutableEmptyMap
import com.openai.core.toImmutable
import com.openai.errors.OpenAIInvalidDataException
Expand Down Expand Up @@ -115,9 +116,9 @@ private constructor(

fun build(): AssistantDeleted =
AssistantDeleted(
checkNotNull(id) { "`id` is required but was not set" },
checkNotNull(deleted) { "`deleted` is required but was not set" },
checkNotNull(object_) { "`object_` is required but was not set" },
checkRequired("id", id),
checkRequired("deleted", deleted),
checkRequired("object_", object_),
additionalProperties.toImmutable(),
)
}
Expand Down
Loading
Loading