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 #11

Merged
merged 1 commit into from
May 10, 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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ implementation("com.braintrust.api:braintrust-kotlin:0.1.0")

### Configure the client

Use `BraintrustOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
Use `BraintrustOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()` and `.baseUrl()`:

```kotlin
import com.braintrust.api.client.BraintrustClient
import com.braintrust.api.client.okhttp.BraintrustOkHttpClient

val client = BraintrustOkHttpClient.builder()
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
```

Alternately, set the environment with `BRAINTRUST_API_KEY`, and use `BraintrustOkHttpClient.fromEnv()` to read from the environment.
Alternately, set the environment with `BRAINTRUST_API_KEY` or `BRAINTRUST_APP_URL`, and use `BraintrustOkHttpClient.fromEnv()` to read from the environment.

```kotlin
val client = BraintrustOkHttpClient.fromEnv()
Expand All @@ -64,6 +65,7 @@ val client = BraintrustOkHttpClient.builder()
| Property | Environment variable | Required | Default value |
| -------- | -------------------- | -------- | ------------- |
| apiKey | `BRAINTRUST_API_KEY` | true | — |
| baseUrl | `BRAINTRUST_APP_URL` | true | — |

Read the documentation for more configuration options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class BraintrustOkHttpClient private constructor() {

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

fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }

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

fun build(): BraintrustClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class BraintrustOkHttpClientAsync private constructor() {

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

fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }

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

fun build(): BraintrustClientAsync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private constructor(
val clock: Clock,
val baseUrl: String,
val apiKey: String,
val baseUrl: String,
val headers: ListMultimap<String, String>,
val responseValidation: Boolean,
) {
Expand All @@ -39,6 +40,7 @@ private constructor(
private var responseValidation: Boolean = false
private var maxRetries: Int = 2
private var apiKey: String? = null
private var baseUrl: String? = null

fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient }

Expand Down Expand Up @@ -75,11 +77,17 @@ private constructor(

fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }

fun fromEnv() = apply { System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) } }
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }

fun fromEnv() = apply {
System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) }
System.getenv("BRAINTRUST_APP_URL")?.let { baseUrl(it) }
}

fun build(): ClientOptions {
checkNotNull(httpClient) { "`httpClient` is required but was not set" }
checkNotNull(apiKey) { "`apiKey` is required but was not set" }
checkNotNull(baseUrl) { "`baseUrl` is required but was not set" }

val headers = ArrayListMultimap.create<String, String>()
headers.put("X-Stainless-Lang", "kotlin")
Expand All @@ -103,6 +111,7 @@ private constructor(
clock,
baseUrl,
apiKey!!,
baseUrl!!,
headers.toUnmodifiable(),
responseValidation,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ErrorHandlingTest {
BraintrustOkHttpClient.builder()
.baseUrl(wmRuntimeInfo.getHttpBaseUrl())
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ServiceParamsTest {
client =
BraintrustOkHttpClient.builder()
.apiKey("My API Key")
.baseUrl("My Base URL")
.baseUrl(wmRuntimeInfo.getHttpBaseUrl())
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AclServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val aclService = client.acl()
val acl =
Expand Down Expand Up @@ -50,6 +51,7 @@ class AclServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val aclService = client.acl()
val acl =
Expand All @@ -66,6 +68,7 @@ class AclServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val aclService = client.acl()
val response =
Expand All @@ -85,6 +88,7 @@ class AclServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val aclService = client.acl()
val acl =
Expand All @@ -101,6 +105,7 @@ class AclServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val aclService = client.acl()
val acl =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val dataset =
Expand All @@ -39,6 +40,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val dataset =
Expand All @@ -57,6 +59,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val dataset =
Expand All @@ -77,6 +80,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val response = datasetService.list(DatasetListParams.builder().build())
Expand All @@ -90,6 +94,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val dataset =
Expand All @@ -108,6 +113,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
datasetService.feedback(
Expand All @@ -133,6 +139,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val datasetFetchResponse =
Expand All @@ -155,6 +162,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val datasetFetchPostResponse =
Expand Down Expand Up @@ -187,6 +195,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val datasetInsertResponse =
Expand Down Expand Up @@ -225,6 +234,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val dataset =
Expand All @@ -245,6 +255,7 @@ class DatasetServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val datasetService = client.dataset()
val datasetSummarizeResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experiment =
Expand Down Expand Up @@ -58,6 +59,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experiment =
Expand All @@ -76,6 +78,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experiment =
Expand Down Expand Up @@ -114,6 +117,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val response = experimentService.list(ExperimentListParams.builder().build())
Expand All @@ -127,6 +131,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experiment =
Expand All @@ -145,6 +150,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
experimentService.feedback(
Expand Down Expand Up @@ -172,6 +178,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experimentFetchResponse =
Expand All @@ -194,6 +201,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experimentFetchPostResponse =
Expand Down Expand Up @@ -226,6 +234,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experimentInsertResponse =
Expand Down Expand Up @@ -307,6 +316,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experiment =
Expand Down Expand Up @@ -346,6 +356,7 @@ class ExperimentServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val experimentService = client.experiment()
val experimentSummarizeResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val group =
Expand All @@ -40,6 +41,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val group =
Expand All @@ -58,6 +60,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val group =
Expand All @@ -80,6 +83,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val response = groupService.list(GroupListParams.builder().build())
Expand All @@ -93,6 +97,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val group =
Expand All @@ -109,6 +114,7 @@ class GroupServiceTest {
BraintrustOkHttpClient.builder()
.baseUrl(TestServerExtension.BASE_URL)
.apiKey("My API Key")
.baseUrl("My Base URL")
.build()
val groupService = client.group()
val group =
Expand Down
Loading