Skip to content

Commit 0622daa

Browse files
chore(internal): update formatter (#220)
chore(internal): optimize build and test perf
1 parent e5b8e55 commit 0622daa

File tree

271 files changed

+975
-1926
lines changed

Some content is hidden

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

271 files changed

+975
-1926
lines changed

buildSrc/build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
`kotlin-dsl`
3-
kotlin("jvm") version "2.1.0"
3+
kotlin("jvm") version "2.1.10"
44
id("com.vanniktech.maven.publish") version "0.28.0"
55
}
66

@@ -10,7 +10,7 @@ repositories {
1010
}
1111

1212
dependencies {
13-
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
14-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
13+
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2")
14+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.10")
1515
implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0")
1616
}

buildSrc/src/main/kotlin/openai.java.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ tasks.named<Jar>("jar") {
3939
}
4040
}
4141

42-
tasks.named<Test>("test") {
42+
tasks.withType<Test>().configureEach {
4343
useJUnitPlatform()
4444

45+
// Run tests in parallel to some degree.
46+
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
47+
forkEvery = 100
48+
4549
testLogging {
4650
exceptionFormat = TestExceptionFormat.FULL
4751
}

buildSrc/src/main/kotlin/openai.kotlin.gradle.kts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.diffplug.gradle.spotless.SpotlessExtension
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
34

45
plugins {
@@ -20,13 +21,19 @@ configure<SpotlessExtension> {
2021
}
2122

2223
tasks.withType<KotlinCompile>().configureEach {
23-
kotlinOptions {
24+
compilerOptions {
2425
freeCompilerArgs = listOf(
2526
"-Xjvm-default=all",
2627
"-Xjdk-release=1.8",
2728
// Suppress deprecation warnings because we may still reference and test deprecated members.
2829
"-Xsuppress-warning=DEPRECATION"
2930
)
30-
jvmTarget = "1.8"
31+
jvmTarget.set(JvmTarget.JVM_1_8)
3132
}
3233
}
34+
35+
// Run tests in parallel to some degree.
36+
tasks.withType<Test>().configureEach {
37+
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
38+
forkEvery = 100
39+
}

gradle.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
org.gradle.configuration-cache=true
12
org.gradle.caching=true
2-
org.gradle.jvmargs=-Xmx4g
33
org.gradle.parallel=true
4+
org.gradle.daemon=false
5+
org.gradle.jvmargs=-Xmx4g
46
kotlin.daemon.jvmargs=-Xmx4g

openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OkHttpClient.kt

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ class OkHttpClient
3131
private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) :
3232
HttpClient {
3333

34-
override fun execute(
35-
request: HttpRequest,
36-
requestOptions: RequestOptions,
37-
): HttpResponse {
34+
override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
3835
val call = newCall(request, requestOptions)
3936

4037
return try {
@@ -120,13 +117,13 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
120117
) {
121118
builder.header(
122119
"X-Stainless-Read-Timeout",
123-
Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString()
120+
Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(),
124121
)
125122
}
126123
if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) {
127124
builder.header(
128125
"X-Stainless-Timeout",
129-
Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString()
126+
Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(),
130127
)
131128
}
132129

openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.openai.credential.BearerTokenCredential
88
@JvmSynthetic
99
internal fun HttpRequest.Builder.addPathSegmentsForAzure(
1010
clientOptions: ClientOptions,
11-
deploymentModel: String?
11+
deploymentModel: String?,
1212
): HttpRequest.Builder = apply {
1313
if (isAzureEndpoint(clientOptions.baseUrl) && deploymentModel != null) {
1414
addPathSegments("openai", "deployments", deploymentModel)

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import com.openai.services.async.ModerationServiceAsyncImpl
2727
import com.openai.services.async.UploadServiceAsync
2828
import com.openai.services.async.UploadServiceAsyncImpl
2929

30-
class OpenAIClientAsyncImpl(
31-
private val clientOptions: ClientOptions,
32-
) : OpenAIClientAsync {
30+
class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAIClientAsync {
3331

3432
private val clientOptionsWithUserAgent =
3533
if (clientOptions.headers.names().contains("User-Agent")) clientOptions

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import com.openai.services.blocking.ModerationServiceImpl
2727
import com.openai.services.blocking.UploadService
2828
import com.openai.services.blocking.UploadServiceImpl
2929

30-
class OpenAIClientImpl(
31-
private val clientOptions: ClientOptions,
32-
) : OpenAIClient {
30+
class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient {
3331

3432
private val clientOptionsWithUserAgent =
3533
if (clientOptions.headers.names().contains("User-Agent")) clientOptions

openai-java-core/src/main/kotlin/com/openai/core/BaseDeserializer.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
1818

1919
override fun createContextual(
2020
context: DeserializationContext,
21-
property: BeanProperty?
21+
property: BeanProperty?,
2222
): JsonDeserializer<T> {
2323
return this
2424
}
@@ -32,7 +32,7 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
3232
protected fun <T> ObjectCodec.tryDeserialize(
3333
node: JsonNode,
3434
type: TypeReference<T>,
35-
validate: (T) -> Unit = {}
35+
validate: (T) -> Unit = {},
3636
): T? {
3737
return try {
3838
readValue(treeAsTokens(node), type).apply(validate)
@@ -46,7 +46,7 @@ abstract class BaseDeserializer<T : Any>(type: KClass<T>) :
4646
protected fun <T> ObjectCodec.tryDeserialize(
4747
node: JsonNode,
4848
type: JavaType,
49-
validate: (T) -> Unit = {}
49+
validate: (T) -> Unit = {},
5050
): T? {
5151
return try {
5252
readValue<T>(treeAsTokens(node), type).apply(validate)

openai-java-core/src/main/kotlin/com/openai/core/HttpRequestBodies.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import java.io.OutputStream
1010
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
1111

1212
@JvmSynthetic
13-
internal inline fun <reified T> json(
14-
jsonMapper: JsonMapper,
15-
value: T,
16-
): HttpRequestBody {
13+
internal inline fun <reified T> json(jsonMapper: JsonMapper, value: T): HttpRequestBody {
1714
return object : HttpRequestBody {
1815
private var cachedBytes: ByteArray? = null
1916

@@ -49,7 +46,7 @@ internal inline fun <reified T> json(
4946
@JvmSynthetic
5047
internal fun multipartFormData(
5148
jsonMapper: JsonMapper,
52-
parts: Array<MultipartFormValue<*>?>
49+
parts: Array<MultipartFormValue<*>?>,
5350
): HttpRequestBody {
5451
val builder = MultipartEntityBuilder.create()
5552
parts.forEach { part ->
@@ -66,14 +63,14 @@ internal fun multipartFormData(
6663
part.name,
6764
buffer.toByteArray(),
6865
part.contentType,
69-
part.filename
66+
part.filename,
7067
)
7168
}
7269
is Boolean ->
7370
builder.addTextBody(
7471
part.name,
7572
if (part.value) "true" else "false",
76-
part.contentType
73+
part.contentType,
7774
)
7875
is Int -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
7976
is Long -> builder.addTextBody(part.name, part.value.toString(), part.contentType)

openai-java-core/src/main/kotlin/com/openai/core/PrepareRequest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.concurrent.CompletableFuture
1111
internal fun HttpRequest.prepare(
1212
clientOptions: ClientOptions,
1313
params: Params,
14-
deploymentModel: String?
14+
deploymentModel: String?,
1515
): HttpRequest =
1616
toBuilder()
1717
// Clear the path segments and add them back below after the Azure path segments.
@@ -29,7 +29,7 @@ internal fun HttpRequest.prepare(
2929
internal fun HttpRequest.prepareAsync(
3030
clientOptions: ClientOptions,
3131
params: Params,
32-
deploymentModel: String?
32+
deploymentModel: String?,
3333
): CompletableFuture<HttpRequest> =
3434
// This async version exists to make it easier to add async specific preparation logic in the
3535
// future.

openai-java-core/src/main/kotlin/com/openai/core/RequestOptions.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ package com.openai.core
22

33
import java.time.Duration
44

5-
class RequestOptions
6-
private constructor(
7-
val responseValidation: Boolean?,
8-
val timeout: Duration?,
9-
) {
5+
class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Duration?) {
106
fun applyDefaults(options: RequestOptions): RequestOptions {
117
return RequestOptions(
128
responseValidation = this.responseValidation ?: options.responseValidation,

openai-java-core/src/main/kotlin/com/openai/core/Values.kt

+8-11
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class JsonMissing : JsonValue() {
287287
override fun serialize(
288288
value: JsonMissing,
289289
generator: JsonGenerator,
290-
provider: SerializerProvider
290+
provider: SerializerProvider,
291291
) {
292292
throw RuntimeException("JsonMissing cannot be serialized")
293293
}
@@ -422,10 +422,7 @@ private constructor(
422422
}
423423

424424
@JacksonAnnotationsInside
425-
@JsonInclude(
426-
JsonInclude.Include.CUSTOM,
427-
valueFilter = JsonField.IsMissing::class,
428-
)
425+
@JsonInclude(JsonInclude.Include.CUSTOM, valueFilter = JsonField.IsMissing::class)
429426
annotation class ExcludeMissing
430427

431428
@JacksonAnnotationsInside
@@ -434,7 +431,7 @@ annotation class ExcludeMissing
434431
isGetterVisibility = Visibility.NONE,
435432
setterVisibility = Visibility.NONE,
436433
creatorVisibility = Visibility.NONE,
437-
fieldVisibility = Visibility.NONE
434+
fieldVisibility = Visibility.NONE,
438435
)
439436
annotation class NoAutoDetect
440437

@@ -443,7 +440,7 @@ internal constructor(
443440
val name: String,
444441
val value: T,
445442
val contentType: ContentType,
446-
val filename: String? = null
443+
val filename: String? = null,
447444
) {
448445

449446
private var hashCode: Int = 0
@@ -462,7 +459,7 @@ internal constructor(
462459
is Long -> value
463460
is Double -> value
464461
else -> value?.hashCode()
465-
}
462+
},
466463
)
467464
}
468465
return hashCode
@@ -496,7 +493,7 @@ internal constructor(
496493
internal fun fromString(
497494
name: String,
498495
value: String,
499-
contentType: ContentType
496+
contentType: ContentType,
500497
): MultipartFormValue<String> = MultipartFormValue(name, value, contentType)
501498

502499
internal fun fromBoolean(
@@ -520,14 +517,14 @@ internal constructor(
520517
internal fun <T : Enum> fromEnum(
521518
name: String,
522519
value: T,
523-
contentType: ContentType
520+
contentType: ContentType,
524521
): MultipartFormValue<T> = MultipartFormValue(name, value, contentType)
525522

526523
internal fun fromByteArray(
527524
name: String,
528525
value: ByteArray,
529526
contentType: ContentType,
530-
filename: String? = null
527+
filename: String? = null,
531528
): MultipartFormValue<ByteArray> = MultipartFormValue(name, value, contentType, filename)
532529
}
533530
}

openai-java-core/src/main/kotlin/com/openai/core/handlers/SseHandler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private class SseState(
5050
var event: String? = null,
5151
val data: MutableList<String> = mutableListOf(),
5252
var lastId: String? = null,
53-
var retry: Int? = null
53+
var retry: Int? = null,
5454
) {
5555
// https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
5656
fun decode(line: String): SseMessage? {

openai-java-core/src/main/kotlin/com/openai/core/http/AsyncStreamResponse.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal fun <T> CompletableFuture<StreamResponse<T>>.toAsync(streamHandlerExecu
4040

4141
override fun subscribe(
4242
handler: Handler<T>,
43-
executor: Executor
43+
executor: Executor,
4444
): AsyncStreamResponse<T> = apply {
4545
// TODO(JDK): Use `compareAndExchange` once targeting JDK 9.
4646
check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) {
@@ -75,7 +75,7 @@ internal fun <T> CompletableFuture<StreamResponse<T>>.toAsync(streamHandlerExecu
7575
close()
7676
}
7777
},
78-
executor
78+
executor,
7979
)
8080
}
8181

@@ -93,5 +93,5 @@ internal fun <T> CompletableFuture<StreamResponse<T>>.toAsync(streamHandlerExecu
9393
private enum class State {
9494
NEW,
9595
SUBSCRIBED,
96-
CLOSED
96+
CLOSED,
9797
}

openai-java-core/src/main/kotlin/com/openai/core/http/Headers.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.TreeMap
66
class Headers
77
private constructor(
88
private val map: Map<String, List<String>>,
9-
@get:JvmName("size") val size: Int
9+
@get:JvmName("size") val size: Int,
1010
) {
1111

1212
fun isEmpty(): Boolean = map.isEmpty()
@@ -74,7 +74,7 @@ private constructor(
7474
values.toImmutable()
7575
}
7676
.toImmutable(),
77-
size
77+
size,
7878
)
7979
}
8080

openai-java-core/src/main/kotlin/com/openai/core/http/PhantomReachableClosingHttpClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class PhantomReachableClosingHttpClient(private val httpClient: HttpCli
1919

2020
override fun executeAsync(
2121
request: HttpRequest,
22-
requestOptions: RequestOptions
22+
requestOptions: RequestOptions,
2323
): CompletableFuture<HttpResponse> = httpClient.executeAsync(request, requestOptions)
2424

2525
override fun close() = httpClient.close()

openai-java-core/src/main/kotlin/com/openai/core/http/QueryParams.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.openai.core.toImmutable
55
class QueryParams
66
private constructor(
77
private val map: Map<String, List<String>>,
8-
@get:JvmName("size") val size: Int
8+
@get:JvmName("size") val size: Int,
99
) {
1010

1111
fun isEmpty(): Boolean = map.isEmpty()

0 commit comments

Comments
 (0)