Skip to content

Commit

Permalink
feat(client)!: better union variant method and variable names (#157)
Browse files Browse the repository at this point in the history
# Migration
Some union class method names have been shortened. To migrate, replace those method names with the shorter versions.
For example:
- `SomeClass.ofReallyLongName(...)` might become `SomeClass.ofShort(...)`
- `someObject.isReallyLongName()` might become `someObject.isShort()`
- etc.
  • Loading branch information
stainless-app[bot] authored Jan 24, 2025
1 parent bbf7f4a commit 49d6980
Show file tree
Hide file tree
Showing 69 changed files with 1,164 additions and 1,809 deletions.
64 changes: 27 additions & 37 deletions openai-java-core/src/main/kotlin/com/openai/models/Annotation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import kotlin.jvm.optionals.getOrNull
@JsonSerialize(using = Annotation.Serializer::class)
class Annotation
private constructor(
private val fileCitationAnnotation: FileCitationAnnotation? = null,
private val filePathAnnotation: FilePathAnnotation? = null,
private val fileCitation: FileCitationAnnotation? = null,
private val filePath: FilePathAnnotation? = null,
private val _json: JsonValue? = null,
) {

Expand All @@ -37,41 +37,37 @@ private constructor(
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
* to search files.
*/
fun fileCitationAnnotation(): Optional<FileCitationAnnotation> =
Optional.ofNullable(fileCitationAnnotation)
fun fileCitation(): Optional<FileCitationAnnotation> = Optional.ofNullable(fileCitation)

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
* generate a file.
*/
fun filePathAnnotation(): Optional<FilePathAnnotation> = Optional.ofNullable(filePathAnnotation)
fun filePath(): Optional<FilePathAnnotation> = Optional.ofNullable(filePath)

fun isFileCitationAnnotation(): Boolean = fileCitationAnnotation != null
fun isFileCitation(): Boolean = fileCitation != null

fun isFilePathAnnotation(): Boolean = filePathAnnotation != null
fun isFilePath(): Boolean = filePath != null

/**
* 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
* to search files.
*/
fun asFileCitationAnnotation(): FileCitationAnnotation =
fileCitationAnnotation.getOrThrow("fileCitationAnnotation")
fun asFileCitation(): FileCitationAnnotation = fileCitation.getOrThrow("fileCitation")

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
* generate a file.
*/
fun asFilePathAnnotation(): FilePathAnnotation =
filePathAnnotation.getOrThrow("filePathAnnotation")
fun asFilePath(): FilePathAnnotation = filePath.getOrThrow("filePath")

fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)

fun <T> accept(visitor: Visitor<T>): T {
return when {
fileCitationAnnotation != null ->
visitor.visitFileCitationAnnotation(fileCitationAnnotation)
filePathAnnotation != null -> visitor.visitFilePathAnnotation(filePathAnnotation)
fileCitation != null -> visitor.visitFileCitation(fileCitation)
filePath != null -> visitor.visitFilePath(filePath)
else -> visitor.unknown(_json)
}
}
Expand All @@ -85,14 +81,12 @@ private constructor(

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

override fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation) {
filePathAnnotation.validate()
override fun visitFilePath(filePath: FilePathAnnotation) {
filePath.validate()
}
}
)
Expand All @@ -104,16 +98,15 @@ private constructor(
return true
}

return /* spotless:off */ other is Annotation && fileCitationAnnotation == other.fileCitationAnnotation && filePathAnnotation == other.filePathAnnotation /* spotless:on */
return /* spotless:off */ other is Annotation && fileCitation == other.fileCitation && filePath == other.filePath /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitationAnnotation, filePathAnnotation) /* spotless:on */
override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitation, filePath) /* spotless:on */

override fun toString(): String =
when {
fileCitationAnnotation != null ->
"Annotation{fileCitationAnnotation=$fileCitationAnnotation}"
filePathAnnotation != null -> "Annotation{filePathAnnotation=$filePathAnnotation}"
fileCitation != null -> "Annotation{fileCitation=$fileCitation}"
filePath != null -> "Annotation{filePath=$filePath}"
_json != null -> "Annotation{_unknown=$_json}"
else -> throw IllegalStateException("Invalid Annotation")
}
Expand All @@ -126,16 +119,14 @@ private constructor(
* "file_search" tool to search files.
*/
@JvmStatic
fun ofFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation) =
Annotation(fileCitationAnnotation = fileCitationAnnotation)
fun ofFileCitation(fileCitation: FileCitationAnnotation) =
Annotation(fileCitation = fileCitation)

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
* to generate a file.
*/
@JvmStatic
fun ofFilePathAnnotation(filePathAnnotation: FilePathAnnotation) =
Annotation(filePathAnnotation = filePathAnnotation)
@JvmStatic fun ofFilePath(filePath: FilePathAnnotation) = Annotation(filePath = filePath)
}

interface Visitor<out T> {
Expand All @@ -145,13 +136,13 @@ private constructor(
* associated with the assistant or the message. Generated when the assistant uses the
* "file_search" tool to search files.
*/
fun visitFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation): T
fun visitFileCitation(fileCitation: FileCitationAnnotation): T

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
* to generate a file.
*/
fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation): T
fun visitFilePath(filePath: FilePathAnnotation): T

fun unknown(json: JsonValue?): T {
throw OpenAIInvalidDataException("Unknown Annotation: $json")
Expand All @@ -168,13 +159,13 @@ private constructor(
"file_citation" -> {
tryDeserialize(node, jacksonTypeRef<FileCitationAnnotation>()) { it.validate() }
?.let {
return Annotation(fileCitationAnnotation = it, _json = json)
return Annotation(fileCitation = it, _json = json)
}
}
"file_path" -> {
tryDeserialize(node, jacksonTypeRef<FilePathAnnotation>()) { it.validate() }
?.let {
return Annotation(filePathAnnotation = it, _json = json)
return Annotation(filePath = it, _json = json)
}
}
}
Expand All @@ -191,9 +182,8 @@ private constructor(
provider: SerializerProvider
) {
when {
value.fileCitationAnnotation != null ->
generator.writeObject(value.fileCitationAnnotation)
value.filePathAnnotation != null -> generator.writeObject(value.filePathAnnotation)
value.fileCitation != null -> generator.writeObject(value.fileCitation)
value.filePath != null -> generator.writeObject(value.filePath)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid Annotation")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import kotlin.jvm.optionals.getOrNull
@JsonSerialize(using = AnnotationDelta.Serializer::class)
class AnnotationDelta
private constructor(
private val fileCitationDeltaAnnotation: FileCitationDeltaAnnotation? = null,
private val filePathDeltaAnnotation: FilePathDeltaAnnotation? = null,
private val fileCitation: FileCitationDeltaAnnotation? = null,
private val filePath: FilePathDeltaAnnotation? = null,
private val _json: JsonValue? = null,
) {

Expand All @@ -37,43 +37,37 @@ private constructor(
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
* to search files.
*/
fun fileCitationDeltaAnnotation(): Optional<FileCitationDeltaAnnotation> =
Optional.ofNullable(fileCitationDeltaAnnotation)
fun fileCitation(): Optional<FileCitationDeltaAnnotation> = Optional.ofNullable(fileCitation)

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
* generate a file.
*/
fun filePathDeltaAnnotation(): Optional<FilePathDeltaAnnotation> =
Optional.ofNullable(filePathDeltaAnnotation)
fun filePath(): Optional<FilePathDeltaAnnotation> = Optional.ofNullable(filePath)

fun isFileCitationDeltaAnnotation(): Boolean = fileCitationDeltaAnnotation != null
fun isFileCitation(): Boolean = fileCitation != null

fun isFilePathDeltaAnnotation(): Boolean = filePathDeltaAnnotation != null
fun isFilePath(): Boolean = filePath != null

/**
* 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
* to search files.
*/
fun asFileCitationDeltaAnnotation(): FileCitationDeltaAnnotation =
fileCitationDeltaAnnotation.getOrThrow("fileCitationDeltaAnnotation")
fun asFileCitation(): FileCitationDeltaAnnotation = fileCitation.getOrThrow("fileCitation")

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
* generate a file.
*/
fun asFilePathDeltaAnnotation(): FilePathDeltaAnnotation =
filePathDeltaAnnotation.getOrThrow("filePathDeltaAnnotation")
fun asFilePath(): FilePathDeltaAnnotation = filePath.getOrThrow("filePath")

fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)

fun <T> accept(visitor: Visitor<T>): T {
return when {
fileCitationDeltaAnnotation != null ->
visitor.visitFileCitationDeltaAnnotation(fileCitationDeltaAnnotation)
filePathDeltaAnnotation != null ->
visitor.visitFilePathDeltaAnnotation(filePathDeltaAnnotation)
fileCitation != null -> visitor.visitFileCitation(fileCitation)
filePath != null -> visitor.visitFilePath(filePath)
else -> visitor.unknown(_json)
}
}
Expand All @@ -87,16 +81,12 @@ private constructor(

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

override fun visitFilePathDeltaAnnotation(
filePathDeltaAnnotation: FilePathDeltaAnnotation
) {
filePathDeltaAnnotation.validate()
override fun visitFilePath(filePath: FilePathDeltaAnnotation) {
filePath.validate()
}
}
)
Expand All @@ -108,17 +98,15 @@ private constructor(
return true
}

return /* spotless:off */ other is AnnotationDelta && fileCitationDeltaAnnotation == other.fileCitationDeltaAnnotation && filePathDeltaAnnotation == other.filePathDeltaAnnotation /* spotless:on */
return /* spotless:off */ other is AnnotationDelta && fileCitation == other.fileCitation && filePath == other.filePath /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitationDeltaAnnotation, filePathDeltaAnnotation) /* spotless:on */
override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitation, filePath) /* spotless:on */

override fun toString(): String =
when {
fileCitationDeltaAnnotation != null ->
"AnnotationDelta{fileCitationDeltaAnnotation=$fileCitationDeltaAnnotation}"
filePathDeltaAnnotation != null ->
"AnnotationDelta{filePathDeltaAnnotation=$filePathDeltaAnnotation}"
fileCitation != null -> "AnnotationDelta{fileCitation=$fileCitation}"
filePath != null -> "AnnotationDelta{filePath=$filePath}"
_json != null -> "AnnotationDelta{_unknown=$_json}"
else -> throw IllegalStateException("Invalid AnnotationDelta")
}
Expand All @@ -131,17 +119,15 @@ private constructor(
* "file_search" tool to search files.
*/
@JvmStatic
fun ofFileCitationDeltaAnnotation(
fileCitationDeltaAnnotation: FileCitationDeltaAnnotation
) = AnnotationDelta(fileCitationDeltaAnnotation = fileCitationDeltaAnnotation)
fun ofFileCitation(fileCitation: FileCitationDeltaAnnotation) =
AnnotationDelta(fileCitation = fileCitation)

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
* to generate a file.
*/
@JvmStatic
fun ofFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation) =
AnnotationDelta(filePathDeltaAnnotation = filePathDeltaAnnotation)
fun ofFilePath(filePath: FilePathDeltaAnnotation) = AnnotationDelta(filePath = filePath)
}

interface Visitor<out T> {
Expand All @@ -151,15 +137,13 @@ private constructor(
* associated with the assistant or the message. Generated when the assistant uses the
* "file_search" tool to search files.
*/
fun visitFileCitationDeltaAnnotation(
fileCitationDeltaAnnotation: FileCitationDeltaAnnotation
): T
fun visitFileCitation(fileCitation: FileCitationDeltaAnnotation): T

/**
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
* to generate a file.
*/
fun visitFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation): T
fun visitFilePath(filePath: FilePathDeltaAnnotation): T

fun unknown(json: JsonValue?): T {
throw OpenAIInvalidDataException("Unknown AnnotationDelta: $json")
Expand All @@ -178,15 +162,15 @@ private constructor(
it.validate()
}
?.let {
return AnnotationDelta(fileCitationDeltaAnnotation = it, _json = json)
return AnnotationDelta(fileCitation = it, _json = json)
}
}
"file_path" -> {
tryDeserialize(node, jacksonTypeRef<FilePathDeltaAnnotation>()) {
it.validate()
}
?.let {
return AnnotationDelta(filePathDeltaAnnotation = it, _json = json)
return AnnotationDelta(filePath = it, _json = json)
}
}
}
Expand All @@ -203,10 +187,8 @@ private constructor(
provider: SerializerProvider
) {
when {
value.fileCitationDeltaAnnotation != null ->
generator.writeObject(value.fileCitationDeltaAnnotation)
value.filePathDeltaAnnotation != null ->
generator.writeObject(value.filePathDeltaAnnotation)
value.fileCitation != null -> generator.writeObject(value.fileCitation)
value.filePath != null -> generator.writeObject(value.filePath)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid AnnotationDelta")
}
Expand Down
10 changes: 4 additions & 6 deletions openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,20 @@ private constructor(
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
*/
fun addTool(codeInterpreterTool: CodeInterpreterTool) =
addTool(AssistantTool.ofCodeInterpreterTool(codeInterpreterTool))
fun addTool(codeInterpreter: CodeInterpreterTool) =
addTool(AssistantTool.ofCodeInterpreter(codeInterpreter))

/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
*/
fun addTool(fileSearchTool: FileSearchTool) =
addTool(AssistantTool.ofFileSearchTool(fileSearchTool))
fun addTool(fileSearch: FileSearchTool) = addTool(AssistantTool.ofFileSearch(fileSearch))

/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
*/
fun addTool(functionTool: FunctionTool) =
addTool(AssistantTool.ofFunctionTool(functionTool))
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))

/**
* Specifies the format that the model must output. Compatible with
Expand Down
Loading

0 comments on commit 49d6980

Please sign in to comment.