Skip to content

Commit 98f1631

Browse files
feat(client): add beta endpoints (#79)
1 parent d237c3c commit 98f1631

File tree

273 files changed

+66311
-2
lines changed

Some content is hidden

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

273 files changed

+66311
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 24
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-a39aca84ed97ebafb707ebd5221e2787c5a42ff3d98f2ffaea8a0dcd84cbcbcb.yml
1+
configured_endpoints: 60
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-02200a58ed631064b6419711da99fefd6e97bdbbeb577a80a1a6e0c8dbcb18f5.yml

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.openai.client
44

55
import com.openai.services.blocking.BatchService
6+
import com.openai.services.blocking.BetaService
67
import com.openai.services.blocking.ChatService
78
import com.openai.services.blocking.CompletionService
89
import com.openai.services.blocking.EmbeddingService
@@ -33,6 +34,8 @@ interface OpenAIClient {
3334

3435
fun fineTuning(): FineTuningService
3536

37+
fun beta(): BetaService
38+
3639
fun batches(): BatchService
3740

3841
fun uploads(): UploadService

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.openai.client
44

55
import com.openai.services.async.BatchServiceAsync
6+
import com.openai.services.async.BetaServiceAsync
67
import com.openai.services.async.ChatServiceAsync
78
import com.openai.services.async.CompletionServiceAsync
89
import com.openai.services.async.EmbeddingServiceAsync
@@ -33,6 +34,8 @@ interface OpenAIClientAsync {
3334

3435
fun fineTuning(): FineTuningServiceAsync
3536

37+
fun beta(): BetaServiceAsync
38+
3639
fun batches(): BatchServiceAsync
3740

3841
fun uploads(): UploadServiceAsync

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.openai.core.ClientOptions
66
import com.openai.core.getPackageVersion
77
import com.openai.services.async.BatchServiceAsync
88
import com.openai.services.async.BatchServiceAsyncImpl
9+
import com.openai.services.async.BetaServiceAsync
10+
import com.openai.services.async.BetaServiceAsyncImpl
911
import com.openai.services.async.ChatServiceAsync
1012
import com.openai.services.async.ChatServiceAsyncImpl
1113
import com.openai.services.async.CompletionServiceAsync
@@ -69,6 +71,8 @@ constructor(
6971
FineTuningServiceAsyncImpl(clientOptionsWithUserAgent)
7072
}
7173

74+
private val beta: BetaServiceAsync by lazy { BetaServiceAsyncImpl(clientOptionsWithUserAgent) }
75+
7276
private val batches: BatchServiceAsync by lazy {
7377
BatchServiceAsyncImpl(clientOptionsWithUserAgent)
7478
}
@@ -95,6 +99,8 @@ constructor(
9599

96100
override fun fineTuning(): FineTuningServiceAsync = fineTuning
97101

102+
override fun beta(): BetaServiceAsync = beta
103+
98104
override fun batches(): BatchServiceAsync = batches
99105

100106
override fun uploads(): UploadServiceAsync = uploads

openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.openai.core.ClientOptions
66
import com.openai.core.getPackageVersion
77
import com.openai.services.blocking.BatchService
88
import com.openai.services.blocking.BatchServiceImpl
9+
import com.openai.services.blocking.BetaService
10+
import com.openai.services.blocking.BetaServiceImpl
911
import com.openai.services.blocking.ChatService
1012
import com.openai.services.blocking.ChatServiceImpl
1113
import com.openai.services.blocking.CompletionService
@@ -65,6 +67,8 @@ constructor(
6567
FineTuningServiceImpl(clientOptionsWithUserAgent)
6668
}
6769

70+
private val beta: BetaService by lazy { BetaServiceImpl(clientOptionsWithUserAgent) }
71+
6872
private val batches: BatchService by lazy { BatchServiceImpl(clientOptionsWithUserAgent) }
6973

7074
private val uploads: UploadService by lazy { UploadServiceImpl(clientOptionsWithUserAgent) }
@@ -87,6 +91,8 @@ constructor(
8791

8892
override fun fineTuning(): FineTuningService = fineTuning
8993

94+
override fun beta(): BetaService = beta
95+
9096
override fun batches(): BatchService = batches
9197

9298
override fun uploads(): UploadService = uploads
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.openai.models
4+
5+
import com.fasterxml.jackson.core.JsonGenerator
6+
import com.fasterxml.jackson.core.ObjectCodec
7+
import com.fasterxml.jackson.databind.JsonNode
8+
import com.fasterxml.jackson.databind.SerializerProvider
9+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
10+
import com.fasterxml.jackson.databind.annotation.JsonSerialize
11+
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
12+
import com.openai.core.BaseDeserializer
13+
import com.openai.core.BaseSerializer
14+
import com.openai.core.JsonValue
15+
import com.openai.core.getOrThrow
16+
import com.openai.errors.OpenAIInvalidDataException
17+
import java.util.Objects
18+
import java.util.Optional
19+
import kotlin.jvm.optionals.getOrNull
20+
21+
/**
22+
* A citation within the message that points to a specific quote from a specific File associated
23+
* with the assistant or the message. Generated when the assistant uses the "file_search" tool to
24+
* search files.
25+
*/
26+
@JsonDeserialize(using = Annotation.Deserializer::class)
27+
@JsonSerialize(using = Annotation.Serializer::class)
28+
class Annotation
29+
private constructor(
30+
private val fileCitationAnnotation: FileCitationAnnotation? = null,
31+
private val filePathAnnotation: FilePathAnnotation? = null,
32+
private val _json: JsonValue? = null,
33+
) {
34+
35+
private var validated: Boolean = false
36+
37+
/**
38+
* A citation within the message that points to a specific quote from a specific File associated
39+
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
40+
* to search files.
41+
*/
42+
fun fileCitationAnnotation(): Optional<FileCitationAnnotation> =
43+
Optional.ofNullable(fileCitationAnnotation)
44+
/**
45+
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
46+
* generate a file.
47+
*/
48+
fun filePathAnnotation(): Optional<FilePathAnnotation> = Optional.ofNullable(filePathAnnotation)
49+
50+
fun isFileCitationAnnotation(): Boolean = fileCitationAnnotation != null
51+
52+
fun isFilePathAnnotation(): Boolean = filePathAnnotation != null
53+
54+
/**
55+
* A citation within the message that points to a specific quote from a specific File associated
56+
* with the assistant or the message. Generated when the assistant uses the "file_search" tool
57+
* to search files.
58+
*/
59+
fun asFileCitationAnnotation(): FileCitationAnnotation =
60+
fileCitationAnnotation.getOrThrow("fileCitationAnnotation")
61+
/**
62+
* A URL for the file that's generated when the assistant used the `code_interpreter` tool to
63+
* generate a file.
64+
*/
65+
fun asFilePathAnnotation(): FilePathAnnotation =
66+
filePathAnnotation.getOrThrow("filePathAnnotation")
67+
68+
fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)
69+
70+
fun <T> accept(visitor: Visitor<T>): T {
71+
return when {
72+
fileCitationAnnotation != null ->
73+
visitor.visitFileCitationAnnotation(fileCitationAnnotation)
74+
filePathAnnotation != null -> visitor.visitFilePathAnnotation(filePathAnnotation)
75+
else -> visitor.unknown(_json)
76+
}
77+
}
78+
79+
fun validate(): Annotation = apply {
80+
if (!validated) {
81+
if (fileCitationAnnotation == null && filePathAnnotation == null) {
82+
throw OpenAIInvalidDataException("Unknown Annotation: $_json")
83+
}
84+
fileCitationAnnotation?.validate()
85+
filePathAnnotation?.validate()
86+
validated = true
87+
}
88+
}
89+
90+
override fun equals(other: Any?): Boolean {
91+
if (this === other) {
92+
return true
93+
}
94+
95+
return /* spotless:off */ other is Annotation && fileCitationAnnotation == other.fileCitationAnnotation && filePathAnnotation == other.filePathAnnotation /* spotless:on */
96+
}
97+
98+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitationAnnotation, filePathAnnotation) /* spotless:on */
99+
100+
override fun toString(): String =
101+
when {
102+
fileCitationAnnotation != null ->
103+
"Annotation{fileCitationAnnotation=$fileCitationAnnotation}"
104+
filePathAnnotation != null -> "Annotation{filePathAnnotation=$filePathAnnotation}"
105+
_json != null -> "Annotation{_unknown=$_json}"
106+
else -> throw IllegalStateException("Invalid Annotation")
107+
}
108+
109+
companion object {
110+
111+
/**
112+
* A citation within the message that points to a specific quote from a specific File
113+
* associated with the assistant or the message. Generated when the assistant uses the
114+
* "file_search" tool to search files.
115+
*/
116+
@JvmStatic
117+
fun ofFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation) =
118+
Annotation(fileCitationAnnotation = fileCitationAnnotation)
119+
120+
/**
121+
* A URL for the file that's generated when the assistant used the `code_interpreter` tool
122+
* to generate a file.
123+
*/
124+
@JvmStatic
125+
fun ofFilePathAnnotation(filePathAnnotation: FilePathAnnotation) =
126+
Annotation(filePathAnnotation = filePathAnnotation)
127+
}
128+
129+
interface Visitor<out T> {
130+
131+
fun visitFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation): T
132+
133+
fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation): T
134+
135+
fun unknown(json: JsonValue?): T {
136+
throw OpenAIInvalidDataException("Unknown Annotation: $json")
137+
}
138+
}
139+
140+
class Deserializer : BaseDeserializer<Annotation>(Annotation::class) {
141+
142+
override fun ObjectCodec.deserialize(node: JsonNode): Annotation {
143+
val json = JsonValue.fromJsonNode(node)
144+
val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull()
145+
146+
when (type) {
147+
"file_citation" -> {
148+
tryDeserialize(node, jacksonTypeRef<FileCitationAnnotation>()) { it.validate() }
149+
?.let {
150+
return Annotation(fileCitationAnnotation = it, _json = json)
151+
}
152+
}
153+
"file_path" -> {
154+
tryDeserialize(node, jacksonTypeRef<FilePathAnnotation>()) { it.validate() }
155+
?.let {
156+
return Annotation(filePathAnnotation = it, _json = json)
157+
}
158+
}
159+
}
160+
161+
return Annotation(_json = json)
162+
}
163+
}
164+
165+
class Serializer : BaseSerializer<Annotation>(Annotation::class) {
166+
167+
override fun serialize(
168+
value: Annotation,
169+
generator: JsonGenerator,
170+
provider: SerializerProvider
171+
) {
172+
when {
173+
value.fileCitationAnnotation != null ->
174+
generator.writeObject(value.fileCitationAnnotation)
175+
value.filePathAnnotation != null -> generator.writeObject(value.filePathAnnotation)
176+
value._json != null -> generator.writeObject(value._json)
177+
else -> throw IllegalStateException("Invalid Annotation")
178+
}
179+
}
180+
}
181+
}

0 commit comments

Comments
 (0)