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

## 0.12.0 (2025-01-22)

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

### Features

* **client:** make it easy to roundtrip messages ([#148](https://github.com/openai/openai-java/issues/148)) ([f4a1617](https://github.com/openai/openai-java/commit/f4a1617148ffc276a324ed9a59654091f57222d2))


### Bug Fixes

* **client:** bad assistants v2 deserialization ([#146](https://github.com/openai/openai-java/issues/146)) ([59d6de8](https://github.com/openai/openai-java/commit/59d6de8cf5857a4b46eeece4f3c8d930d67103d6))

## 0.11.10 (2025-01-21)

Full Changelog: [v0.11.9...v0.11.10](https://github.com/openai/openai-java/compare/v0.11.9...v0.11.10)
Expand Down
8 changes: 4 additions & 4 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.11.10)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.11.10/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.11.10)
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.12.0)
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.12.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.12.0)

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

Expand All @@ -31,7 +31,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.10")
implementation("com.openai:openai-java:0.12.0")
```

#### Maven
Expand All @@ -40,7 +40,7 @@ implementation("com.openai:openai-java:0.11.10")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>0.11.10</version>
<version>0.12.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.11.10" // x-release-please-version
version = "0.12.0" // x-release-please-version
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// File generated from our OpenAPI spec by Stainless.

@file:JvmName("SseHandler")

package com.openai.core.handlers
Expand Down Expand Up @@ -117,13 +119,14 @@ private class SseState(
}

@JvmSynthetic
internal inline fun <reified T> Handler<StreamResponse<SseMessage>>.mapJson():
Handler<StreamResponse<T>> =
internal inline fun <reified T> Handler<StreamResponse<SseMessage>>.mapJson(
includeEventAndData: Boolean = false
): Handler<StreamResponse<T>> =
object : Handler<StreamResponse<T>> {
override fun handle(response: HttpResponse): StreamResponse<T> =
[email protected](response).map {
try {
it.json<T>()
it.json<T>(includeEventAndData)
} catch (e: Exception) {
throw OpenAIException("Error reading response", e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// File generated from our OpenAPI spec by Stainless.

package com.openai.core.http

import com.fasterxml.jackson.databind.json.JsonMapper
Expand Down Expand Up @@ -39,7 +41,17 @@ private constructor(
fun build(): SseMessage = SseMessage(jsonMapper!!, event, data, id, retry)
}

inline fun <reified T> json(): T = jsonMapper.readerFor(jacksonTypeRef<T>()).readValue(jsonNode)
inline fun <reified T> json(includeEventAndData: Boolean = false): T {
var jsonNode = jsonNode
if (includeEventAndData) {
val newJsonNode = jsonMapper.createObjectNode()
event?.let { newJsonNode.put("event", event) }
newJsonNode.replace("data", jsonNode)
jsonNode = newJsonNode
}

return jsonMapper.readerFor(jacksonTypeRef<T>()).readValue(jsonNode)
}

private val jsonNode by lazy {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,10 @@ constructor(
)
)

/** Messages sent by the model in response to user messages. */
fun addMessage(chatCompletionAssistantMessageParam: ChatCompletionMessage) =
addMessage(chatCompletionAssistantMessageParam.toParam())

/**
* A list of messages comprising the conversation so far. Depending on the
* [model](https://platform.openai.com/docs/models) you use, different message types
Expand Down Expand Up @@ -2558,6 +2562,11 @@ constructor(
body.addMessage(chatCompletionAssistantMessageParam)
}

/** Messages sent by the model in response to user messages. */
fun addMessage(chatCompletionAssistantMessageParam: ChatCompletionMessage) = apply {
body.addMessage(chatCompletionAssistantMessageParam)
}

/**
* A list of messages comprising the conversation so far. Depending on the
* [model](https://platform.openai.com/docs/models) you use, different message types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ private constructor(
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties

fun toParam(): ChatCompletionAssistantMessageParam =
ChatCompletionAssistantMessageParam.builder()
.role(_role().map { ChatCompletionAssistantMessageParam.Role.of(it.toString()) })
.audio(
_audio().map {
ChatCompletionAssistantMessageParam.Audio.builder().id(it._id()).build()
}
)
.content(
_content().map { ChatCompletionAssistantMessageParam.Content.ofTextContent(it) }
)
.functionCall(
_functionCall().map {
ChatCompletionAssistantMessageParam.FunctionCall.builder()
.arguments(it._arguments())
.name(it._name())
.build()
}
)
.refusal(_refusal())
.toolCalls(_toolCalls())
.build()

private var validated: Boolean = false

fun validate(): ChatCompletionMessage = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ internal constructor(

private val createAndRunStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/** Create a thread and run it in one request. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal constructor(

private val createStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/** Create a run. */
Expand Down Expand Up @@ -299,7 +299,7 @@ internal constructor(

private val submitToolOutputsStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ internal constructor(

private val createAndRunStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/** Create a thread and run it in one request. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal constructor(

private val createStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/** Create a run. */
Expand Down Expand Up @@ -278,7 +278,7 @@ internal constructor(

private val submitToolOutputsStreamingHandler: Handler<StreamResponse<AssistantStreamEvent>> =
sseHandler(clientOptions.jsonMapper)
.mapJson<AssistantStreamEvent>()
.mapJson<AssistantStreamEvent>(includeEventAndData = true)
.withErrorHandler(errorHandler)

/**
Expand Down
Loading