diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index da59f99e..2aca35ae 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.4.0"
+ ".": "0.5.0"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9275574e..d71d4b52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,25 @@
# Changelog
+## 0.5.0 (2024-11-25)
+
+Full Changelog: [v0.4.0...v0.5.0](https://github.com/openai/openai-java/compare/v0.4.0...v0.5.0)
+
+### Features
+
+* **client:** add logging when debug env is set ([#18](https://github.com/openai/openai-java/issues/18)) ([017aae7](https://github.com/openai/openai-java/commit/017aae7a1795fe933e0ea9e8ee2c8d059c6746f4))
+
+
+### Documentation
+
+* add note that we're in alpha ([#19](https://github.com/openai/openai-java/issues/19)) ([d49cc28](https://github.com/openai/openai-java/commit/d49cc28f0a621df658a3c83a880735ebd7cc1acc))
+* **readme:** add Microsoft Azure section ([#17](https://github.com/openai/openai-java/issues/17)) ([8f8165f](https://github.com/openai/openai-java/commit/8f8165fd33780e3ee0609df7e7e171c8e7f10029))
+* swap example from `.completions()` to `.chat().completions()` ([#20](https://github.com/openai/openai-java/issues/20)) ([f0423a7](https://github.com/openai/openai-java/commit/f0423a7e9e20d5c1e528077fbb4e87baa822079a))
+
+
+### Styles
+
+* **internal:** reorder some params methods and improve consistency of implementations ([#15](https://github.com/openai/openai-java/issues/15)) ([8592cda](https://github.com/openai/openai-java/commit/8592cdad178325e3a8994ef44e854ee5b4853c45))
+
## 0.4.0 (2024-11-21)
Full Changelog: [v0.3.0...v0.4.0](https://github.com/openai/openai-java/compare/v0.3.0...v0.4.0)
diff --git a/README.md b/README.md
index 3afedcc8..662c37e4 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/0.4.0)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/0.5.0)
@@ -30,7 +30,7 @@ The REST API documentation can be foundĀ on [platform.openai.com](https://platfo
```kotlin
-implementation("com.openai:openai-java:0.4.0")
+implementation("com.openai:openai-java:0.5.0")
```
#### Maven
@@ -39,7 +39,7 @@ implementation("com.openai:openai-java:0.4.0")
com.openai
openai-java
- 0.4.0
+ 0.5.0
```
@@ -270,6 +270,46 @@ This library throws exceptions in a single hierarchy for easy handling:
- We failed to serialize the request body
- We failed to parse the response body (has access to response code and body)
+## 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.
+
+```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()
+ .role(ChatCompletionUserMessageParam.Role.USER)
+ .content(ChatCompletionUserMessageParam.Content.ofTextContent("Who won the world series in 2020?"))
+ .build()))
+ .model("gpt-4o")
+ .build();
+
+ChatCompletion chatCompletion = client.chat().completions().create(params);
+
+List choices = chatCompletion.choices();
+for (ChatCompletion.Choice choice : choices) {
+ System.out.println("Choice content: " + choice.message().content().get());
+}
+```
+
+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).
+
## Network options
### Retries
@@ -333,6 +373,22 @@ get a map of untyped fields of type `Map`. You can then acces
`._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class
to extract it to a desired type.
+## Logging
+
+We use the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor).
+
+You can enable logging by setting the environment variable `OPENAI_LOG` to `info`.
+
+```sh
+$ export OPENAI_LOG=info
+```
+
+Or to `debug` for more verbose logging.
+
+```sh
+$ export OPENAI_LOG=debug
+```
+
## Semantic versioning
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
diff --git a/build.gradle.kts b/build.gradle.kts
index 855ac122..bd927c56 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -4,7 +4,7 @@ plugins {
allprojects {
group = "com.openai"
- version = "0.4.0" // x-release-please-version
+ version = "0.5.0" // x-release-please-version
}
nexusPublishing {
diff --git a/openai-java-client-okhttp/build.gradle.kts b/openai-java-client-okhttp/build.gradle.kts
index d979cf9a..4f14e269 100644
--- a/openai-java-client-okhttp/build.gradle.kts
+++ b/openai-java-client-okhttp/build.gradle.kts
@@ -7,6 +7,7 @@ dependencies {
api(project(":openai-java-core"))
implementation("com.squareup.okhttp3:okhttp:4.12.0")
+ implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
testImplementation(kotlin("test"))
testImplementation("org.assertj:assertj-core:3.25.3")
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 f4a36a33..8862168e 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
@@ -23,6 +23,7 @@ import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
+import okhttp3.logging.HttpLoggingInterceptor
import okio.BufferedSink
class OkHttpClient
@@ -30,14 +31,30 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
HttpClient {
private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient {
- val timeout = requestOptions.timeout ?: return okHttpClient
- return okHttpClient
- .newBuilder()
- .connectTimeout(timeout)
- .readTimeout(timeout)
- .writeTimeout(timeout)
- .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
- .build()
+ val clientBuilder = okHttpClient.newBuilder()
+
+ val logLevel =
+ when (System.getenv("OPENAI_LOG")?.lowercase()) {
+ "info" -> HttpLoggingInterceptor.Level.BASIC
+ "debug" -> HttpLoggingInterceptor.Level.BODY
+ else -> null
+ }
+ if (logLevel != null) {
+ clientBuilder.addNetworkInterceptor(
+ HttpLoggingInterceptor().setLevel(logLevel).apply { redactHeader("Authorization") }
+ )
+ }
+
+ val timeout = requestOptions.timeout
+ if (timeout != null) {
+ clientBuilder
+ .connectTimeout(timeout)
+ .readTimeout(timeout)
+ .writeTimeout(timeout)
+ .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
+ }
+
+ return clientBuilder.build()
}
override fun execute(
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
index 0cbcd1e3..077f37ad 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt
@@ -21,6 +21,12 @@ constructor(
fun batchId(): String = batchId
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ fun _additionalBodyProperties(): Map = additionalBodyProperties
+
@JvmSynthetic
internal fun getBody(): Optional