Skip to content

Commit 7656bc0

Browse files
feat(client)!: better union variant method and variable names (#157)
# 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.
1 parent 62453cd commit 7656bc0

File tree

69 files changed

+1164
-1809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1164
-1809
lines changed

openai-java-core/src/main/kotlin/com/openai/models/Annotation.kt

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import kotlin.jvm.optionals.getOrNull
2727
@JsonSerialize(using = Annotation.Serializer::class)
2828
class Annotation
2929
private constructor(
30-
private val fileCitationAnnotation: FileCitationAnnotation? = null,
31-
private val filePathAnnotation: FilePathAnnotation? = null,
30+
private val fileCitation: FileCitationAnnotation? = null,
31+
private val filePath: FilePathAnnotation? = null,
3232
private val _json: JsonValue? = null,
3333
) {
3434

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

4342
/**
4443
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
4544
* generate a file.
4645
*/
47-
fun filePathAnnotation(): Optional<FilePathAnnotation> = Optional.ofNullable(filePathAnnotation)
46+
fun filePath(): Optional<FilePathAnnotation> = Optional.ofNullable(filePath)
4847

49-
fun isFileCitationAnnotation(): Boolean = fileCitationAnnotation != null
48+
fun isFileCitation(): Boolean = fileCitation != null
5049

51-
fun isFilePathAnnotation(): Boolean = filePathAnnotation != null
50+
fun isFilePath(): Boolean = filePath != null
5251

5352
/**
5453
* A citation within the message that points to a specific quote from a specific File associated
5554
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
5655
* to search files.
5756
*/
58-
fun asFileCitationAnnotation(): FileCitationAnnotation =
59-
fileCitationAnnotation.getOrThrow("fileCitationAnnotation")
57+
fun asFileCitation(): FileCitationAnnotation = fileCitation.getOrThrow("fileCitation")
6058

6159
/**
6260
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
6361
* generate a file.
6462
*/
65-
fun asFilePathAnnotation(): FilePathAnnotation =
66-
filePathAnnotation.getOrThrow("filePathAnnotation")
63+
fun asFilePath(): FilePathAnnotation = filePath.getOrThrow("filePath")
6764

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

7067
fun <T> accept(visitor: Visitor<T>): T {
7168
return when {
72-
fileCitationAnnotation != null ->
73-
visitor.visitFileCitationAnnotation(fileCitationAnnotation)
74-
filePathAnnotation != null -> visitor.visitFilePathAnnotation(filePathAnnotation)
69+
fileCitation != null -> visitor.visitFileCitation(fileCitation)
70+
filePath != null -> visitor.visitFilePath(filePath)
7571
else -> visitor.unknown(_json)
7672
}
7773
}
@@ -85,14 +81,12 @@ private constructor(
8581

8682
accept(
8783
object : Visitor<Unit> {
88-
override fun visitFileCitationAnnotation(
89-
fileCitationAnnotation: FileCitationAnnotation
90-
) {
91-
fileCitationAnnotation.validate()
84+
override fun visitFileCitation(fileCitation: FileCitationAnnotation) {
85+
fileCitation.validate()
9286
}
9387

94-
override fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation) {
95-
filePathAnnotation.validate()
88+
override fun visitFilePath(filePath: FilePathAnnotation) {
89+
filePath.validate()
9690
}
9791
}
9892
)
@@ -104,16 +98,15 @@ private constructor(
10498
return true
10599
}
106100

107-
return /* spotless:off */ other is Annotation && fileCitationAnnotation == other.fileCitationAnnotation && filePathAnnotation == other.filePathAnnotation /* spotless:on */
101+
return /* spotless:off */ other is Annotation && fileCitation == other.fileCitation && filePath == other.filePath /* spotless:on */
108102
}
109103

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

112106
override fun toString(): String =
113107
when {
114-
fileCitationAnnotation != null ->
115-
"Annotation{fileCitationAnnotation=$fileCitationAnnotation}"
116-
filePathAnnotation != null -> "Annotation{filePathAnnotation=$filePathAnnotation}"
108+
fileCitation != null -> "Annotation{fileCitation=$fileCitation}"
109+
filePath != null -> "Annotation{filePath=$filePath}"
117110
_json != null -> "Annotation{_unknown=$_json}"
118111
else -> throw IllegalStateException("Invalid Annotation")
119112
}
@@ -126,16 +119,14 @@ private constructor(
126119
* "file_search" tool to search files.
127120
*/
128121
@JvmStatic
129-
fun ofFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation) =
130-
Annotation(fileCitationAnnotation = fileCitationAnnotation)
122+
fun ofFileCitation(fileCitation: FileCitationAnnotation) =
123+
Annotation(fileCitation = fileCitation)
131124

132125
/**
133126
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
134127
* to generate a file.
135128
*/
136-
@JvmStatic
137-
fun ofFilePathAnnotation(filePathAnnotation: FilePathAnnotation) =
138-
Annotation(filePathAnnotation = filePathAnnotation)
129+
@JvmStatic fun ofFilePath(filePath: FilePathAnnotation) = Annotation(filePath = filePath)
139130
}
140131

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

150141
/**
151142
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
152143
* to generate a file.
153144
*/
154-
fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation): T
145+
fun visitFilePath(filePath: FilePathAnnotation): T
155146

156147
fun unknown(json: JsonValue?): T {
157148
throw OpenAIInvalidDataException("Unknown Annotation: $json")
@@ -168,13 +159,13 @@ private constructor(
168159
"file_citation" -> {
169160
tryDeserialize(node, jacksonTypeRef<FileCitationAnnotation>()) { it.validate() }
170161
?.let {
171-
return Annotation(fileCitationAnnotation = it, _json = json)
162+
return Annotation(fileCitation = it, _json = json)
172163
}
173164
}
174165
"file_path" -> {
175166
tryDeserialize(node, jacksonTypeRef<FilePathAnnotation>()) { it.validate() }
176167
?.let {
177-
return Annotation(filePathAnnotation = it, _json = json)
168+
return Annotation(filePath = it, _json = json)
178169
}
179170
}
180171
}
@@ -191,9 +182,8 @@ private constructor(
191182
provider: SerializerProvider
192183
) {
193184
when {
194-
value.fileCitationAnnotation != null ->
195-
generator.writeObject(value.fileCitationAnnotation)
196-
value.filePathAnnotation != null -> generator.writeObject(value.filePathAnnotation)
185+
value.fileCitation != null -> generator.writeObject(value.fileCitation)
186+
value.filePath != null -> generator.writeObject(value.filePath)
197187
value._json != null -> generator.writeObject(value._json)
198188
else -> throw IllegalStateException("Invalid Annotation")
199189
}

openai-java-core/src/main/kotlin/com/openai/models/AnnotationDelta.kt

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import kotlin.jvm.optionals.getOrNull
2727
@JsonSerialize(using = AnnotationDelta.Serializer::class)
2828
class AnnotationDelta
2929
private constructor(
30-
private val fileCitationDeltaAnnotation: FileCitationDeltaAnnotation? = null,
31-
private val filePathDeltaAnnotation: FilePathDeltaAnnotation? = null,
30+
private val fileCitation: FileCitationDeltaAnnotation? = null,
31+
private val filePath: FilePathDeltaAnnotation? = null,
3232
private val _json: JsonValue? = null,
3333
) {
3434

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

4342
/**
4443
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
4544
* generate a file.
4645
*/
47-
fun filePathDeltaAnnotation(): Optional<FilePathDeltaAnnotation> =
48-
Optional.ofNullable(filePathDeltaAnnotation)
46+
fun filePath(): Optional<FilePathDeltaAnnotation> = Optional.ofNullable(filePath)
4947

50-
fun isFileCitationDeltaAnnotation(): Boolean = fileCitationDeltaAnnotation != null
48+
fun isFileCitation(): Boolean = fileCitation != null
5149

52-
fun isFilePathDeltaAnnotation(): Boolean = filePathDeltaAnnotation != null
50+
fun isFilePath(): Boolean = filePath != null
5351

5452
/**
5553
* A citation within the message that points to a specific quote from a specific File associated
5654
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
5755
* to search files.
5856
*/
59-
fun asFileCitationDeltaAnnotation(): FileCitationDeltaAnnotation =
60-
fileCitationDeltaAnnotation.getOrThrow("fileCitationDeltaAnnotation")
57+
fun asFileCitation(): FileCitationDeltaAnnotation = fileCitation.getOrThrow("fileCitation")
6158

6259
/**
6360
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
6461
* generate a file.
6562
*/
66-
fun asFilePathDeltaAnnotation(): FilePathDeltaAnnotation =
67-
filePathDeltaAnnotation.getOrThrow("filePathDeltaAnnotation")
63+
fun asFilePath(): FilePathDeltaAnnotation = filePath.getOrThrow("filePath")
6864

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

7167
fun <T> accept(visitor: Visitor<T>): T {
7268
return when {
73-
fileCitationDeltaAnnotation != null ->
74-
visitor.visitFileCitationDeltaAnnotation(fileCitationDeltaAnnotation)
75-
filePathDeltaAnnotation != null ->
76-
visitor.visitFilePathDeltaAnnotation(filePathDeltaAnnotation)
69+
fileCitation != null -> visitor.visitFileCitation(fileCitation)
70+
filePath != null -> visitor.visitFilePath(filePath)
7771
else -> visitor.unknown(_json)
7872
}
7973
}
@@ -87,16 +81,12 @@ private constructor(
8781

8882
accept(
8983
object : Visitor<Unit> {
90-
override fun visitFileCitationDeltaAnnotation(
91-
fileCitationDeltaAnnotation: FileCitationDeltaAnnotation
92-
) {
93-
fileCitationDeltaAnnotation.validate()
84+
override fun visitFileCitation(fileCitation: FileCitationDeltaAnnotation) {
85+
fileCitation.validate()
9486
}
9587

96-
override fun visitFilePathDeltaAnnotation(
97-
filePathDeltaAnnotation: FilePathDeltaAnnotation
98-
) {
99-
filePathDeltaAnnotation.validate()
88+
override fun visitFilePath(filePath: FilePathDeltaAnnotation) {
89+
filePath.validate()
10090
}
10191
}
10292
)
@@ -108,17 +98,15 @@ private constructor(
10898
return true
10999
}
110100

111-
return /* spotless:off */ other is AnnotationDelta && fileCitationDeltaAnnotation == other.fileCitationDeltaAnnotation && filePathDeltaAnnotation == other.filePathDeltaAnnotation /* spotless:on */
101+
return /* spotless:off */ other is AnnotationDelta && fileCitation == other.fileCitation && filePath == other.filePath /* spotless:on */
112102
}
113103

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

116106
override fun toString(): String =
117107
when {
118-
fileCitationDeltaAnnotation != null ->
119-
"AnnotationDelta{fileCitationDeltaAnnotation=$fileCitationDeltaAnnotation}"
120-
filePathDeltaAnnotation != null ->
121-
"AnnotationDelta{filePathDeltaAnnotation=$filePathDeltaAnnotation}"
108+
fileCitation != null -> "AnnotationDelta{fileCitation=$fileCitation}"
109+
filePath != null -> "AnnotationDelta{filePath=$filePath}"
122110
_json != null -> "AnnotationDelta{_unknown=$_json}"
123111
else -> throw IllegalStateException("Invalid AnnotationDelta")
124112
}
@@ -131,17 +119,15 @@ private constructor(
131119
* "file_search" tool to search files.
132120
*/
133121
@JvmStatic
134-
fun ofFileCitationDeltaAnnotation(
135-
fileCitationDeltaAnnotation: FileCitationDeltaAnnotation
136-
) = AnnotationDelta(fileCitationDeltaAnnotation = fileCitationDeltaAnnotation)
122+
fun ofFileCitation(fileCitation: FileCitationDeltaAnnotation) =
123+
AnnotationDelta(fileCitation = fileCitation)
137124

138125
/**
139126
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
140127
* to generate a file.
141128
*/
142129
@JvmStatic
143-
fun ofFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation) =
144-
AnnotationDelta(filePathDeltaAnnotation = filePathDeltaAnnotation)
130+
fun ofFilePath(filePath: FilePathDeltaAnnotation) = AnnotationDelta(filePath = filePath)
145131
}
146132

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

158142
/**
159143
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
160144
* to generate a file.
161145
*/
162-
fun visitFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation): T
146+
fun visitFilePath(filePath: FilePathDeltaAnnotation): T
163147

164148
fun unknown(json: JsonValue?): T {
165149
throw OpenAIInvalidDataException("Unknown AnnotationDelta: $json")
@@ -178,15 +162,15 @@ private constructor(
178162
it.validate()
179163
}
180164
?.let {
181-
return AnnotationDelta(fileCitationDeltaAnnotation = it, _json = json)
165+
return AnnotationDelta(fileCitation = it, _json = json)
182166
}
183167
}
184168
"file_path" -> {
185169
tryDeserialize(node, jacksonTypeRef<FilePathDeltaAnnotation>()) {
186170
it.validate()
187171
}
188172
?.let {
189-
return AnnotationDelta(filePathDeltaAnnotation = it, _json = json)
173+
return AnnotationDelta(filePath = it, _json = json)
190174
}
191175
}
192176
}
@@ -203,10 +187,8 @@ private constructor(
203187
provider: SerializerProvider
204188
) {
205189
when {
206-
value.fileCitationDeltaAnnotation != null ->
207-
generator.writeObject(value.fileCitationDeltaAnnotation)
208-
value.filePathDeltaAnnotation != null ->
209-
generator.writeObject(value.filePathDeltaAnnotation)
190+
value.fileCitation != null -> generator.writeObject(value.fileCitation)
191+
value.filePath != null -> generator.writeObject(value.filePath)
210192
value._json != null -> generator.writeObject(value._json)
211193
else -> throw IllegalStateException("Invalid AnnotationDelta")
212194
}

openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,20 @@ private constructor(
407407
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
408408
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
409409
*/
410-
fun addTool(codeInterpreterTool: CodeInterpreterTool) =
411-
addTool(AssistantTool.ofCodeInterpreterTool(codeInterpreterTool))
410+
fun addTool(codeInterpreter: CodeInterpreterTool) =
411+
addTool(AssistantTool.ofCodeInterpreter(codeInterpreter))
412412

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

420419
/**
421420
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per
422421
* assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`.
423422
*/
424-
fun addTool(functionTool: FunctionTool) =
425-
addTool(AssistantTool.ofFunctionTool(functionTool))
423+
fun addTool(function: FunctionTool) = addTool(AssistantTool.ofFunction(function))
426424

427425
/**
428426
* Specifies the format that the model must output. Compatible with

0 commit comments

Comments
 (0)