Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 23, 2024
1 parent 29f340b commit 08636e2
Show file tree
Hide file tree
Showing 564 changed files with 49,812 additions and 73,327 deletions.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or products provided by Braintrust please follow the respective company's securi

### Braintrust Terms and Policies

Please contact infotest@braintrustdata.com for any questions or concerns regarding security of our services.
Please contact info@braintrustdata.com for any questions or concerns regarding security of our services.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

package com.braintrustdata.api.client.okhttp

import com.braintrustdata.api.client.BraintrustClient
import com.braintrustdata.api.client.BraintrustClientImpl
import com.braintrustdata.api.core.ClientOptions
import com.fasterxml.jackson.databind.json.JsonMapper
import com.google.common.collect.Multimap
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.client.BraintrustClient
import com.braintrustdata.api.client.BraintrustClientImpl

class BraintrustOkHttpClient private constructor() {

Expand All @@ -32,15 +35,21 @@ class BraintrustOkHttpClient private constructor() {
this.baseUrl = baseUrl
}

fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
fun jsonMapper(jsonMapper: JsonMapper) = apply {
clientOptions.jsonMapper(jsonMapper)
}

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
fun clock(clock: Clock) = apply {
clientOptions.clock(clock)
}

fun headers(headers: Map<String, Iterable<String>>) = apply {
clientOptions.headers(headers)
}

fun putHeader(name: String, value: String) = apply { clientOptions.putHeader(name, value) }
fun putHeader(name: String, value: String) = apply {
clientOptions.putHeader(name, value)
}

fun putHeaders(name: String, values: Iterable<String>) = apply {
clientOptions.putHeaders(name, values)
Expand All @@ -50,34 +59,42 @@ class BraintrustOkHttpClient private constructor() {
clientOptions.putAllHeaders(headers)
}

fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) }
fun removeHeader(name: String) = apply {
clientOptions.removeHeader(name)
}

fun timeout(timeout: Duration) = apply { this.timeout = timeout }
fun timeout(timeout: Duration) = apply {
this.timeout = timeout
}

fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
fun maxRetries(maxRetries: Int) = apply {
clientOptions.maxRetries(maxRetries)
}

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

fun responseValidation(responseValidation: Boolean) = apply {
clientOptions.responseValidation(responseValidation)
}

fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
fun apiKey(apiKey: String?) = apply {
clientOptions.apiKey(apiKey)
}

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

fun build(): BraintrustClient {
return BraintrustClientImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
.baseUrl(baseUrl)
.timeout(timeout)
.proxy(proxy)
.build()
)
.build()
)
return BraintrustClientImpl(clientOptions
.httpClient(OkHttpClient.builder()
.baseUrl(baseUrl)
.timeout(timeout)
.proxy(proxy)
.build())
.build())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

package com.braintrustdata.api.client.okhttp

import com.braintrustdata.api.client.BraintrustClientAsync
import com.braintrustdata.api.client.BraintrustClientAsyncImpl
import com.braintrustdata.api.core.ClientOptions
import com.fasterxml.jackson.databind.json.JsonMapper
import com.google.common.collect.Multimap
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.client.BraintrustClientAsync
import com.braintrustdata.api.client.BraintrustClientAsyncImpl

class BraintrustOkHttpClientAsync private constructor() {

Expand All @@ -32,15 +35,21 @@ class BraintrustOkHttpClientAsync private constructor() {
this.baseUrl = baseUrl
}

fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
fun jsonMapper(jsonMapper: JsonMapper) = apply {
clientOptions.jsonMapper(jsonMapper)
}

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
fun clock(clock: Clock) = apply {
clientOptions.clock(clock)
}

fun headers(headers: Map<String, Iterable<String>>) = apply {
clientOptions.headers(headers)
}

fun putHeader(name: String, value: String) = apply { clientOptions.putHeader(name, value) }
fun putHeader(name: String, value: String) = apply {
clientOptions.putHeader(name, value)
}

fun putHeaders(name: String, values: Iterable<String>) = apply {
clientOptions.putHeaders(name, values)
Expand All @@ -50,34 +59,42 @@ class BraintrustOkHttpClientAsync private constructor() {
clientOptions.putAllHeaders(headers)
}

fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) }
fun removeHeader(name: String) = apply {
clientOptions.removeHeader(name)
}

fun timeout(timeout: Duration) = apply { this.timeout = timeout }
fun timeout(timeout: Duration) = apply {
this.timeout = timeout
}

fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
fun maxRetries(maxRetries: Int) = apply {
clientOptions.maxRetries(maxRetries)
}

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

fun responseValidation(responseValidation: Boolean) = apply {
clientOptions.responseValidation(responseValidation)
}

fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
fun apiKey(apiKey: String?) = apply {
clientOptions.apiKey(apiKey)
}

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

fun build(): BraintrustClientAsync {
return BraintrustClientAsyncImpl(
clientOptions
.httpClient(
OkHttpClient.builder()
.baseUrl(baseUrl)
.timeout(timeout)
.proxy(proxy)
.build()
)
.build()
)
return BraintrustClientAsyncImpl(clientOptions
.httpClient(OkHttpClient.builder()
.baseUrl(baseUrl)
.timeout(timeout)
.proxy(proxy)
.build())
.build())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.braintrustdata.api.client.okhttp

import com.google.common.collect.ListMultimap
import com.google.common.collect.MultimapBuilder
import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.core.http.HttpMethod
import com.braintrustdata.api.core.http.HttpRequest
import com.braintrustdata.api.core.http.HttpRequestBody
import com.braintrustdata.api.core.http.HttpResponse
import com.braintrustdata.api.core.http.HttpMethod
import com.braintrustdata.api.errors.BraintrustIoException
import com.google.common.collect.ListMultimap
import com.google.common.collect.MultimapBuilder
import java.io.IOException
import java.io.InputStream
import java.net.Proxy
import java.time.Duration
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Response
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.MediaType
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okio.BufferedSink

class OkHttpClient
Expand All @@ -33,8 +34,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient {
val timeout = requestOptions.timeout ?: return okHttpClient
return okHttpClient
.newBuilder()
return okHttpClient.newBuilder()
.connectTimeout(timeout)
.readTimeout(timeout)
.writeTimeout(timeout)
Expand Down Expand Up @@ -190,20 +190,19 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
}
}

private suspend fun Call.executeAsync(): Response =
suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation { this.cancel() }
private suspend fun Call.executeAsync(): Response = suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation { this.cancel() }

enqueue(
object : Callback {
override fun onFailure(call: Call, e: IOException) {
continuation.resumeWith(Result.failure(e))
}
enqueue(
object : Callback {
override fun onFailure(call: Call, e: IOException) {
continuation.resumeWith(Result.failure(e))
}

override fun onResponse(call: Call, response: Response) {
continuation.resumeWith(Result.success(response))
}
override fun onResponse(call: Call, response: Response) {
continuation.resumeWith(Result.success(response))
}
)
}
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@

package com.braintrustdata.api.client

import java.time.Duration
import java.util.Base64
import java.util.Optional
import java.util.concurrent.CompletableFuture
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.http.HttpMethod
import com.braintrustdata.api.core.http.HttpRequest
import com.braintrustdata.api.core.http.HttpResponse.Handler
import com.braintrustdata.api.core.JsonField
import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.errors.BraintrustError
import com.braintrustdata.api.errors.BraintrustInvalidDataException
import com.braintrustdata.api.models.*
import com.braintrustdata.api.services.blocking.*
import com.braintrustdata.api.services.emptyHandler
import com.braintrustdata.api.services.errorHandler
import com.braintrustdata.api.services.json
import com.braintrustdata.api.services.jsonHandler
import com.braintrustdata.api.services.stringHandler
import com.braintrustdata.api.services.binaryHandler
import com.braintrustdata.api.services.withErrorHandler

interface BraintrustClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@

package com.braintrustdata.api.client

import java.time.Duration
import java.util.Base64
import java.util.Optional
import java.util.concurrent.CompletableFuture
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.http.HttpMethod
import com.braintrustdata.api.core.http.HttpRequest
import com.braintrustdata.api.core.http.HttpResponse.Handler
import com.braintrustdata.api.core.JsonField
import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.errors.BraintrustError
import com.braintrustdata.api.errors.BraintrustInvalidDataException
import com.braintrustdata.api.models.*
import com.braintrustdata.api.services.async.*
import com.braintrustdata.api.services.emptyHandler
import com.braintrustdata.api.services.errorHandler
import com.braintrustdata.api.services.json
import com.braintrustdata.api.services.jsonHandler
import com.braintrustdata.api.services.stringHandler
import com.braintrustdata.api.services.binaryHandler
import com.braintrustdata.api.services.withErrorHandler

interface BraintrustClientAsync {

Expand Down
Loading

0 comments on commit 08636e2

Please sign in to comment.