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.15.1"
".": "0.16.0"
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.16.0 (2025-01-28)

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

### Features

* **client:** add some more builder helpers ([#173](https://github.com/openai/openai-java/issues/173)) ([f314e68](https://github.com/openai/openai-java/commit/f314e68915560703970c9acc16e96030202de9d1))


### Chores

* **internal:** shorten `model` method impl ([f314e68](https://github.com/openai/openai-java/commit/f314e68915560703970c9acc16e96030202de9d1))


### Documentation

* mark more methods as deprecated ([f314e68](https://github.com/openai/openai-java/commit/f314e68915560703970c9acc16e96030202de9d1))
* more examples and cleanup ([#159](https://github.com/openai/openai-java/issues/159)) ([fa2a1fc](https://github.com/openai/openai-java/commit/fa2a1fc2983131bac40988049dd3b0e7c730442c))

## 0.15.1 (2025-01-27)

Full Changelog: [v0.15.0...v0.15.1](https://github.com/openai/openai-java/compare/v0.15.0...v0.15.1)
Expand Down
50 changes: 15 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<!-- 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.15.1)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.15.1/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.15.1)
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.16.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.16.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.16.0)

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

Expand All @@ -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.15.1")
implementation("com.openai:openai-java:0.16.0")
```

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

Expand All @@ -46,6 +46,8 @@ This library requires Java 8 or later.

## Usage

See the [`openai-java-example`](openai-java-example/src/main/java/com/openai/example) directory for complete and runnable examples.

### Configure the client

Use `OpenAIOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
Expand Down Expand Up @@ -290,41 +292,19 @@ This library throws exceptions in a single hierarchy for easy handling:
## Microsoft Azure OpenAI

To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the same
OpenAI client builder but with the Azure-specific configuration.
OpenAI client builder but with the Azure-specific configuration.

```java
OpenAIOkHttpClient.Builder clientBuilder = OpenAIOkHttpClient.builder();

/* Azure-specific code starts here */
// You can either set 'endpoint' directly in the builder.
// or set the env var "AZURE_OPENAI_ENDPOINT" and use fromEnv() method instead
clientBuilder
.baseUrl(System.getenv("AZURE_OPENAI_ENDPOINT"))
.credential(BearerTokenCredential.create(
AuthenticationUtil.getBearerTokenSupplier(
new DefaultAzureCredentialBuilder().build(), "https://cognitiveservices.azure.com/.default")
));
/* Azure-specific code ends here */

OpenAIClient client = clientBuilder.build();

ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
.addMessage(ChatCompletionMessageParam.ofChatCompletionUserMessageParam(
ChatCompletionUserMessageParam.builder()
.content(ChatCompletionUserMessageParam.Content.ofTextContent("Who won the world series in 2020?"))
.build()))
.model("gpt-4o")
.build();

ChatCompletion chatCompletion = client.chat().completions().create(params);

List<ChatCompletion.Choice> choices = chatCompletion.choices();
for (ChatCompletion.Choice choice : choices) {
System.out.println("Choice content: " + choice.message().content().get());
}
OpenAIClient client = OpenAIOkHttpClient.builder()
// Gets the API key from the `AZURE_OPENAI_KEY` environment variable
.fromEnv()
// Set the Azure Entra ID
.credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier(
new DefaultAzureCredentialBuilder().build(), "https://cognitiveservices.azure.com/.default")))
.build();
```

See the complete Azure OpenAI examples in the [Azure OpenAI example](https://github.com/openai/openai-java/tree/next/openai-azure-java-example/src/main/java/com.openai.azure.examples).
See the complete Azure OpenAI example in the [`openai-java-example`](openai-java-example/src/main/java/com/openai/example/AzureEntraIdExample.java) directory. The other examples in the directory also work with Azure as long as the client is configured to use it.

## Network options

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.15.1" // x-release-please-version
version = "0.16.0" // x-release-please-version
}

subprojects {
Expand Down
4 changes: 0 additions & 4 deletions examples/.keep

This file was deleted.

12 changes: 0 additions & 12 deletions openai-azure-java-example/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private constructor(
* all of your available models, or see our
* [Model overview](https://platform.openai.com/docs/models) for descriptions of them.
*/
fun model(value: String) = apply { model(ChatModel.of(value)) }
fun model(value: String) = model(ChatModel.of(value))

/** The description of the assistant. The maximum length is 512 characters. */
fun description(description: String?) = description(JsonField.ofNullable(description))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ private constructor(
* associated with the assistant. If not, the model associated with the assistant will
* be used.
*/
fun model(value: String) = apply { model(ChatModel.of(value)) }
fun model(value: String) = model(ChatModel.of(value))

/**
* Whether to enable
Expand Down Expand Up @@ -2728,6 +2728,9 @@ private constructor(
fun addTool(codeInterpreter: CodeInterpreterTool) =
addTool(Tool.ofCodeInterpreter(codeInterpreter))

/** The tools to add this file to. */
fun addToolFileSearch() = addTool(Tool.ofFileSearch())

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
putAllAdditionalProperties(additionalProperties)
Expand Down
Loading