Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): update via SDK Studio #40

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# syntax=docker/dockerfile:1
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install -y --no-install-recommends \
libxkbcommon0 \
ca-certificates \
ca-certificates-java \
make \
curl \
git \
openjdk-17-jdk \
openjdk-17-jdk-headless \
unzip \
libc++1 \
vim \
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.3"
".": "0.1.0-alpha.4"
}
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.openlayer.api/openlayer-java)](https://central.sonatype.com/artifact/com.openlayer.api/openlayer-java/0.1.0-alpha.3)
[![Maven Central](https://img.shields.io/maven-central/v/com.openlayer.api/openlayer-java)](https://central.sonatype.com/artifact/com.openlayer.api/openlayer-java/0.1.0-alpha.4)

<!-- x-release-please-end -->

Expand All @@ -27,7 +27,7 @@ The REST API documentation can be found on [openlayer.com](https://openlayer.co
<!-- x-release-please-start-version -->

```kotlin
implementation("com.openlayer.api:openlayer-java:0.1.0-alpha.3")
implementation("com.openlayer.api:openlayer-java:0.1.0-alpha.4")
```

#### Maven
Expand All @@ -36,7 +36,7 @@ implementation("com.openlayer.api:openlayer-java:0.1.0-alpha.3")
<dependency>
<groupId>com.openlayer.api</groupId>
<artifactId>openlayer-java</artifactId>
<version>0.1.0-alpha.3</version>
<version>0.1.0-alpha.4</version>
</dependency>
```

Expand Down Expand Up @@ -77,16 +77,17 @@ import com.openlayer.api.models.InferencePipelineDataStreamResponse;
import java.util.List;

InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.builder()
.rows(List.of(InferencePipelineDataStreamParams.Row.builder().build()))
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.config(InferencePipelineDataStreamParams.Config.ofLlmData(InferencePipelineDataStreamParams.Config.LlmData.builder()
.outputColumnName("output")
.costColumnName("cost")
.inputVariableNames(List.of("user_query"))
.numOfTokenColumnName("tokens")
.timestampColumnName("timestamp")
.build()))
.row(List.of(InferencePipelineDataStreamParams.Row.builder().build()))
.build();
InferencePipelineDataStreamResponse inferencePipelineDataStreamResponse = client.inferencePipelines().data().stream(params);
InferencePipelineDataStreamResponse response = client.inferencePipelines().data().stream(params);
```

---
Expand Down Expand Up @@ -118,7 +119,7 @@ InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.bui
When receiving a response, the Openlayer Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `OpenlayerInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model.

```java
InferencePipelineDataStreamResponse inferencePipelineDataStreamResponse = client.inferencePipelines().data().stream().validate();
InferencePipelineDataStreamResponse response = client.inferencePipelines().data().stream().validate();
```

### Response properties as JSON
Expand Down Expand Up @@ -148,7 +149,7 @@ if (field.isMissing()) {
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method:

```java
JsonValue secret = inferencePipelineDataStreamResponse._additionalProperties().get("secret_field");
JsonValue secret = projectCreateResponse._additionalProperties().get("secret_field");
```

---
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "com.openlayer.api"
version = "0.1.0-alpha.3" // x-release-please-version
version = "0.1.0-alpha.4" // x-release-please-version
}


1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/openlayer.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configure<SpotlessExtension> {
importOrder()
removeUnusedImports()
palantirJavaFormat()
toggleOffOn()
}
}

Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/openlayer.kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kotlin {
configure<SpotlessExtension> {
kotlin {
ktfmt().kotlinlangStyle()
toggleOffOn()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
request.body?.run { future.whenComplete { _, _ -> close() } }

val call = getClient(requestOptions).newCall(request.toRequest())

call.enqueue(
object : Callback {
override fun onResponse(call: Call, response: Response) {
Expand All @@ -90,7 +89,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

private fun HttpRequest.toRequest(): Request {
var body: RequestBody? = body?.toRequestBody()
// OkHttpClient always requires a request body for PUT and POST methods
// OkHttpClient always requires a request body for PUT and POST methods.
if (body == null && (method == HttpMethod.PUT || method == HttpMethod.POST)) {
body = "".toRequestBody()
}
Expand Down Expand Up @@ -118,43 +117,27 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
val length = contentLength()

return object : RequestBody() {
override fun contentType(): MediaType? {
return mediaType
}
override fun contentType(): MediaType? = mediaType

override fun contentLength(): Long {
return length
}
override fun contentLength(): Long = length

override fun isOneShot(): Boolean {
return !repeatable()
}
override fun isOneShot(): Boolean = !repeatable()

override fun writeTo(sink: BufferedSink) {
writeTo(sink.outputStream())
}
override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream())
}
}

private fun Response.toResponse(): HttpResponse {
val headers = headers.toHeaders()

return object : HttpResponse {
override fun statusCode(): Int {
return code
}
override fun statusCode(): Int = code

override fun headers(): ListMultimap<String, String> {
return headers
}
override fun headers(): ListMultimap<String, String> = headers

override fun body(): InputStream {
return body!!.byteStream()
}
override fun body(): InputStream = body!!.byteStream()

override fun close() {
body!!.close()
}
override fun close() = body!!.close()
}
}

Expand All @@ -163,9 +146,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
.arrayListValues()
.build<String, String>()

forEach { pair -> headers.put(pair.first, pair.second) }

return headers
}

Expand All @@ -176,7 +157,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
class Builder {

private var baseUrl: HttpUrl? = null
// default timeout is 1 minute
// The default timeout is 1 minute.
private var timeout: Duration = Duration.ofSeconds(60)
private var proxy: Proxy? = null

Expand All @@ -186,8 +167,8 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }

fun build(): OkHttpClient {
return OkHttpClient(
fun build(): OkHttpClient =
OkHttpClient(
okhttp3.OkHttpClient.Builder()
.connectTimeout(timeout)
.readTimeout(timeout)
Expand All @@ -197,6 +178,5 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
.build(),
checkNotNull(baseUrl) { "`baseUrl` is required but was not set" },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OpenlayerOkHttpClient private constructor() {

private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
// default timeout for client is 1 minute
// The default timeout for the client is 1 minute.
private var timeout: Duration = Duration.ofSeconds(60)
private var proxy: Proxy? = null

Expand Down Expand Up @@ -66,8 +66,8 @@ class OpenlayerOkHttpClient private constructor() {

fun fromEnv() = apply { clientOptions.fromEnv() }

fun build(): OpenlayerClient {
return OpenlayerClientImpl(
fun build(): OpenlayerClient =
OpenlayerClientImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
Expand All @@ -78,6 +78,5 @@ class OpenlayerOkHttpClient private constructor() {
)
.build()
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OpenlayerOkHttpClientAsync private constructor() {

private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
// default timeout for client is 1 minute
// The default timeout for the client is 1 minute.
private var timeout: Duration = Duration.ofSeconds(60)
private var proxy: Proxy? = null

Expand Down Expand Up @@ -66,8 +66,8 @@ class OpenlayerOkHttpClientAsync private constructor() {

fun fromEnv() = apply { clientOptions.fromEnv() }

fun build(): OpenlayerClientAsync {
return OpenlayerClientAsyncImpl(
fun build(): OpenlayerClientAsync =
OpenlayerClientAsyncImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
Expand All @@ -78,6 +78,5 @@ class OpenlayerOkHttpClientAsync private constructor() {
)
.build()
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// File generated from our OpenAPI spec by Stainless.

@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102

package com.openlayer.api.client

import com.openlayer.api.models.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// File generated from our OpenAPI spec by Stainless.

@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102

package com.openlayer.api.client

import com.openlayer.api.models.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,41 @@
package com.openlayer.api.client

import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.http.HttpResponse.Handler
import com.openlayer.api.errors.OpenlayerError
import com.openlayer.api.core.getPackageVersion
import com.openlayer.api.models.*
import com.openlayer.api.services.async.*
import com.openlayer.api.services.errorHandler

class OpenlayerClientAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : OpenlayerClientAsync {

private val errorHandler: Handler<OpenlayerError> = errorHandler(clientOptions.jsonMapper)
private val clientOptionsWithUserAgent =
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
else
clientOptions
.toBuilder()
.putHeader("User-Agent", "${javaClass.simpleName}/Java ${getPackageVersion()}")
.build()

// Pass the original clientOptions so that this client sets its own User-Agent.
private val sync: OpenlayerClient by lazy { OpenlayerClientImpl(clientOptions) }

private val projects: ProjectServiceAsync by lazy { ProjectServiceAsyncImpl(clientOptions) }
private val projects: ProjectServiceAsync by lazy {
ProjectServiceAsyncImpl(clientOptionsWithUserAgent)
}

private val commits: CommitServiceAsync by lazy { CommitServiceAsyncImpl(clientOptions) }
private val commits: CommitServiceAsync by lazy {
CommitServiceAsyncImpl(clientOptionsWithUserAgent)
}

private val inferencePipelines: InferencePipelineServiceAsync by lazy {
InferencePipelineServiceAsyncImpl(clientOptions)
InferencePipelineServiceAsyncImpl(clientOptionsWithUserAgent)
}

private val storage: StorageServiceAsync by lazy { StorageServiceAsyncImpl(clientOptions) }
private val storage: StorageServiceAsync by lazy {
StorageServiceAsyncImpl(clientOptionsWithUserAgent)
}

override fun sync(): OpenlayerClient = sync

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@
package com.openlayer.api.client

import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.http.HttpResponse.Handler
import com.openlayer.api.errors.OpenlayerError
import com.openlayer.api.core.getPackageVersion
import com.openlayer.api.models.*
import com.openlayer.api.services.blocking.*
import com.openlayer.api.services.errorHandler

class OpenlayerClientImpl
constructor(
private val clientOptions: ClientOptions,
) : OpenlayerClient {

private val errorHandler: Handler<OpenlayerError> = errorHandler(clientOptions.jsonMapper)
private val clientOptionsWithUserAgent =
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
else
clientOptions
.toBuilder()
.putHeader("User-Agent", "${javaClass.simpleName}/Java ${getPackageVersion()}")
.build()

// Pass the original clientOptions so that this client sets its own User-Agent.
private val async: OpenlayerClientAsync by lazy { OpenlayerClientAsyncImpl(clientOptions) }

private val projects: ProjectService by lazy { ProjectServiceImpl(clientOptions) }
private val projects: ProjectService by lazy { ProjectServiceImpl(clientOptionsWithUserAgent) }

private val commits: CommitService by lazy { CommitServiceImpl(clientOptions) }
private val commits: CommitService by lazy { CommitServiceImpl(clientOptionsWithUserAgent) }

private val inferencePipelines: InferencePipelineService by lazy {
InferencePipelineServiceImpl(clientOptions)
InferencePipelineServiceImpl(clientOptionsWithUserAgent)
}

private val storage: StorageService by lazy { StorageServiceImpl(clientOptions) }
private val storage: StorageService by lazy { StorageServiceImpl(clientOptionsWithUserAgent) }

override fun async(): OpenlayerClientAsync = async

Expand Down
Loading