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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 7 deletions
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)

0 commit comments

Comments
 (0)