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

## 0.11.2 (2025-01-10)

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

### Bug Fixes

* **client:** add some missing `validate()` calls ([#101](https://github.com/openai/openai-java/issues/101)) ([dec2d6b](https://github.com/openai/openai-java/commit/dec2d6b25cccc2547e576c8658116d2bba12f100))


### Chores

* **internal:** refactor `validate` methods ([dec2d6b](https://github.com/openai/openai-java/commit/dec2d6b25cccc2547e576c8658116d2bba12f100))

## 0.11.1 (2025-01-09)

Full Changelog: [v0.11.0...v0.11.1](https://github.com/openai/openai-java/compare/v0.11.0...v0.11.1)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

Expand All @@ -32,7 +32,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.1")
implementation("com.openai:openai-java:0.11.2")
```

#### Maven
Expand All @@ -41,7 +41,7 @@ implementation("com.openai:openai-java:0.11.1")
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>0.11.1</version>
<version>0.11.2</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 @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "com.openai"
version = "0.11.1" // x-release-please-version
version = "0.11.2" // x-release-please-version
}


Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ private constructor(
private val _json: JsonValue? = null,
) {

private var validated: Boolean = false

/**
* A citation within the message that points to a specific quote from a specific File associated
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
Expand Down Expand Up @@ -78,15 +76,27 @@ private constructor(
}
}

private var validated: Boolean = false

fun validate(): Annotation = apply {
if (!validated) {
if (fileCitationAnnotation == null && filePathAnnotation == null) {
throw OpenAIInvalidDataException("Unknown Annotation: $_json")
}
fileCitationAnnotation?.validate()
filePathAnnotation?.validate()
validated = true
if (validated) {
return@apply
}

accept(
object : Visitor<Unit> {
override fun visitFileCitationAnnotation(
fileCitationAnnotation: FileCitationAnnotation
) {
fileCitationAnnotation.validate()
}

override fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation) {
filePathAnnotation.validate()
}
}
)
validated = true
}

override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ private constructor(
private val _json: JsonValue? = null,
) {

private var validated: Boolean = false

/**
* A citation within the message that points to a specific quote from a specific File associated
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
Expand Down Expand Up @@ -80,15 +78,29 @@ private constructor(
}
}

private var validated: Boolean = false

fun validate(): AnnotationDelta = apply {
if (!validated) {
if (fileCitationDeltaAnnotation == null && filePathDeltaAnnotation == null) {
throw OpenAIInvalidDataException("Unknown AnnotationDelta: $_json")
}
fileCitationDeltaAnnotation?.validate()
filePathDeltaAnnotation?.validate()
validated = true
if (validated) {
return@apply
}

accept(
object : Visitor<Unit> {
override fun visitFileCitationDeltaAnnotation(
fileCitationDeltaAnnotation: FileCitationDeltaAnnotation
) {
fileCitationDeltaAnnotation.validate()
}

override fun visitFilePathDeltaAnnotation(
filePathDeltaAnnotation: FilePathDeltaAnnotation
) {
filePathDeltaAnnotation.validate()
}
}
)
validated = true
}

override fun equals(other: Any?): Boolean {
Expand Down
56 changes: 32 additions & 24 deletions openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,23 @@ private constructor(
private var validated: Boolean = false

fun validate(): Assistant = apply {
if (!validated) {
id()
createdAt()
description()
instructions()
model()
name()
object_()
tools()
responseFormat()
temperature()
toolResources().map { it.validate() }
topP()
validated = true
if (validated) {
return@apply
}

id()
createdAt()
description()
instructions()
model()
name()
object_()
tools().forEach { it.validate() }
responseFormat().ifPresent { it.validate() }
temperature()
toolResources().ifPresent { it.validate() }
topP()
validated = true
}

fun toBuilder() = Builder().from(this)
Expand Down Expand Up @@ -795,11 +797,13 @@ private constructor(
private var validated: Boolean = false

fun validate(): ToolResources = apply {
if (!validated) {
codeInterpreter().map { it.validate() }
fileSearch().map { it.validate() }
validated = true
if (validated) {
return@apply
}

codeInterpreter().ifPresent { it.validate() }
fileSearch().ifPresent { it.validate() }
validated = true
}

fun toBuilder() = Builder().from(this)
Expand Down Expand Up @@ -897,10 +901,12 @@ private constructor(
private var validated: Boolean = false

fun validate(): CodeInterpreter = apply {
if (!validated) {
fileIds()
validated = true
if (validated) {
return@apply
}

fileIds()
validated = true
}

fun toBuilder() = Builder().from(this)
Expand Down Expand Up @@ -1039,10 +1045,12 @@ private constructor(
private var validated: Boolean = false

fun validate(): FileSearch = apply {
if (!validated) {
vectorStoreIds()
validated = true
if (validated) {
return@apply
}

vectorStoreIds()
validated = true
}

fun toBuilder() = Builder().from(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ private constructor(
private var validated: Boolean = false

fun validate(): AssistantDeleted = apply {
if (!validated) {
id()
deleted()
object_()
validated = true
if (validated) {
return@apply
}

id()
deleted()
object_()
validated = true
}

fun toBuilder() = Builder().from(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ private constructor(
private val _json: JsonValue? = null,
) {

private var validated: Boolean = false

/** `auto` is the default value */
fun behavior(): Optional<Behavior> = Optional.ofNullable(behavior)

Expand Down Expand Up @@ -98,21 +96,35 @@ private constructor(
}
}

private var validated: Boolean = false

fun validate(): AssistantResponseFormatOption = apply {
if (!validated) {
if (
behavior == null &&
responseFormatText == null &&
responseFormatJsonObject == null &&
responseFormatJsonSchema == null
) {
throw OpenAIInvalidDataException("Unknown AssistantResponseFormatOption: $_json")
}
responseFormatText?.validate()
responseFormatJsonObject?.validate()
responseFormatJsonSchema?.validate()
validated = true
if (validated) {
return@apply
}

accept(
object : Visitor<Unit> {
override fun visitBehavior(behavior: Behavior) {}

override fun visitResponseFormatText(responseFormatText: ResponseFormatText) {
responseFormatText.validate()
}

override fun visitResponseFormatJsonObject(
responseFormatJsonObject: ResponseFormatJsonObject
) {
responseFormatJsonObject.validate()
}

override fun visitResponseFormatJsonSchema(
responseFormatJsonSchema: ResponseFormatJsonSchema
) {
responseFormatJsonSchema.validate()
}
}
)
validated = true
}

override fun equals(other: Any?): Boolean {
Expand Down
Loading
Loading