-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): support results endpoint (#73)
- Loading branch information
1 parent
1115e31
commit aaaf92a
Showing
14 changed files
with
724 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
configured_endpoints: 19 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml | ||
configured_endpoints: 21 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-75f0573c3d6d79650bcbd8b1b4fcf93ce146d567afeb1061cd4afccf8d1d6799.yml |
23 changes: 23 additions & 0 deletions
23
anthropic-java-core/src/main/kotlin/com/anthropic/core/handlers/JsonlHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@file:JvmName("JsonlHandler") | ||
|
||
package com.anthropic.core.handlers | ||
|
||
import com.anthropic.core.http.HttpResponse.Handler | ||
import com.anthropic.core.http.StreamResponse | ||
import com.anthropic.errors.AnthropicException | ||
import com.fasterxml.jackson.databind.json.JsonMapper | ||
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef | ||
|
||
@JvmSynthetic | ||
internal inline fun <reified T> jsonlHandler(jsonMapper: JsonMapper): Handler<StreamResponse<T>> = | ||
streamHandler { lines -> | ||
for (line in lines) { | ||
val value = | ||
try { | ||
jsonMapper.readValue(line, jacksonTypeRef<T>()) | ||
} catch (e: Exception) { | ||
throw AnthropicException("Error reading response", e) | ||
} | ||
yield(value) | ||
} | ||
} |
214 changes: 214 additions & 0 deletions
214
anthropic-java-core/src/main/kotlin/com/anthropic/models/BetaMessageBatchResultsParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
// File generated from our OpenAPI spec by Stainless. | ||
|
||
package com.anthropic.models | ||
|
||
import com.anthropic.core.NoAutoDetect | ||
import com.anthropic.core.checkRequired | ||
import com.anthropic.core.http.Headers | ||
import com.anthropic.core.http.QueryParams | ||
import com.anthropic.core.toImmutable | ||
import java.util.Objects | ||
import java.util.Optional | ||
|
||
/** | ||
* Streams the results of a Message Batch as a `.jsonl` file. | ||
* | ||
* Each line in the file is a JSON object containing the result of a single request in the Message | ||
* Batch. Results are not guaranteed to be in the same order as requests. Use the `custom_id` field | ||
* to match results to requests. | ||
*/ | ||
class BetaMessageBatchResultsParams | ||
constructor( | ||
private val messageBatchId: String, | ||
private val betas: List<AnthropicBeta>?, | ||
private val additionalHeaders: Headers, | ||
private val additionalQueryParams: QueryParams, | ||
) { | ||
|
||
/** ID of the Message Batch. */ | ||
fun messageBatchId(): String = messageBatchId | ||
|
||
/** Optional header to specify the beta version(s) you want to use. */ | ||
fun betas(): Optional<List<AnthropicBeta>> = Optional.ofNullable(betas) | ||
|
||
fun _additionalHeaders(): Headers = additionalHeaders | ||
|
||
fun _additionalQueryParams(): QueryParams = additionalQueryParams | ||
|
||
@JvmSynthetic | ||
internal fun getHeaders(): Headers { | ||
val headers = Headers.builder() | ||
this.betas?.let { headers.put("anthropic-beta", it.map(Any::toString)) } | ||
headers.putAll(additionalHeaders) | ||
return headers.build() | ||
} | ||
|
||
@JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams | ||
|
||
fun getPathParam(index: Int): String { | ||
return when (index) { | ||
0 -> messageBatchId | ||
else -> "" | ||
} | ||
} | ||
|
||
fun toBuilder() = Builder().from(this) | ||
|
||
companion object { | ||
|
||
@JvmStatic fun builder() = Builder() | ||
} | ||
|
||
@NoAutoDetect | ||
class Builder { | ||
|
||
private var messageBatchId: String? = null | ||
private var betas: MutableList<AnthropicBeta>? = null | ||
private var additionalHeaders: Headers.Builder = Headers.builder() | ||
private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() | ||
|
||
@JvmSynthetic | ||
internal fun from(betaMessageBatchResultsParams: BetaMessageBatchResultsParams) = apply { | ||
messageBatchId = betaMessageBatchResultsParams.messageBatchId | ||
betas = betaMessageBatchResultsParams.betas?.toMutableList() | ||
additionalHeaders = betaMessageBatchResultsParams.additionalHeaders.toBuilder() | ||
additionalQueryParams = betaMessageBatchResultsParams.additionalQueryParams.toBuilder() | ||
} | ||
|
||
/** ID of the Message Batch. */ | ||
fun messageBatchId(messageBatchId: String) = apply { this.messageBatchId = messageBatchId } | ||
|
||
/** Optional header to specify the beta version(s) you want to use. */ | ||
fun betas(betas: List<AnthropicBeta>?) = apply { this.betas = betas?.toMutableList() } | ||
|
||
/** Optional header to specify the beta version(s) you want to use. */ | ||
fun betas(betas: Optional<List<AnthropicBeta>>) = betas(betas.orElse(null)) | ||
|
||
/** Optional header to specify the beta version(s) you want to use. */ | ||
fun addBeta(beta: AnthropicBeta) = apply { | ||
betas = (betas ?: mutableListOf()).apply { add(beta) } | ||
} | ||
|
||
/** Optional header to specify the beta version(s) you want to use. */ | ||
fun addBeta(value: String) = addBeta(AnthropicBeta.of(value)) | ||
|
||
fun additionalHeaders(additionalHeaders: Headers) = apply { | ||
this.additionalHeaders.clear() | ||
putAllAdditionalHeaders(additionalHeaders) | ||
} | ||
|
||
fun additionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { | ||
this.additionalHeaders.clear() | ||
putAllAdditionalHeaders(additionalHeaders) | ||
} | ||
|
||
fun putAdditionalHeader(name: String, value: String) = apply { | ||
additionalHeaders.put(name, value) | ||
} | ||
|
||
fun putAdditionalHeaders(name: String, values: Iterable<String>) = apply { | ||
additionalHeaders.put(name, values) | ||
} | ||
|
||
fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { | ||
this.additionalHeaders.putAll(additionalHeaders) | ||
} | ||
|
||
fun putAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { | ||
this.additionalHeaders.putAll(additionalHeaders) | ||
} | ||
|
||
fun replaceAdditionalHeaders(name: String, value: String) = apply { | ||
additionalHeaders.replace(name, value) | ||
} | ||
|
||
fun replaceAdditionalHeaders(name: String, values: Iterable<String>) = apply { | ||
additionalHeaders.replace(name, values) | ||
} | ||
|
||
fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { | ||
this.additionalHeaders.replaceAll(additionalHeaders) | ||
} | ||
|
||
fun replaceAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { | ||
this.additionalHeaders.replaceAll(additionalHeaders) | ||
} | ||
|
||
fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } | ||
|
||
fun removeAllAdditionalHeaders(names: Set<String>) = apply { | ||
additionalHeaders.removeAll(names) | ||
} | ||
|
||
fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { | ||
this.additionalQueryParams.clear() | ||
putAllAdditionalQueryParams(additionalQueryParams) | ||
} | ||
|
||
fun additionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = apply { | ||
this.additionalQueryParams.clear() | ||
putAllAdditionalQueryParams(additionalQueryParams) | ||
} | ||
|
||
fun putAdditionalQueryParam(key: String, value: String) = apply { | ||
additionalQueryParams.put(key, value) | ||
} | ||
|
||
fun putAdditionalQueryParams(key: String, values: Iterable<String>) = apply { | ||
additionalQueryParams.put(key, values) | ||
} | ||
|
||
fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { | ||
this.additionalQueryParams.putAll(additionalQueryParams) | ||
} | ||
|
||
fun putAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = | ||
apply { | ||
this.additionalQueryParams.putAll(additionalQueryParams) | ||
} | ||
|
||
fun replaceAdditionalQueryParams(key: String, value: String) = apply { | ||
additionalQueryParams.replace(key, value) | ||
} | ||
|
||
fun replaceAdditionalQueryParams(key: String, values: Iterable<String>) = apply { | ||
additionalQueryParams.replace(key, values) | ||
} | ||
|
||
fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { | ||
this.additionalQueryParams.replaceAll(additionalQueryParams) | ||
} | ||
|
||
fun replaceAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = | ||
apply { | ||
this.additionalQueryParams.replaceAll(additionalQueryParams) | ||
} | ||
|
||
fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } | ||
|
||
fun removeAllAdditionalQueryParams(keys: Set<String>) = apply { | ||
additionalQueryParams.removeAll(keys) | ||
} | ||
|
||
fun build(): BetaMessageBatchResultsParams = | ||
BetaMessageBatchResultsParams( | ||
checkRequired("messageBatchId", messageBatchId), | ||
betas?.toImmutable(), | ||
additionalHeaders.build(), | ||
additionalQueryParams.build(), | ||
) | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
|
||
return /* spotless:off */ other is BetaMessageBatchResultsParams && messageBatchId == other.messageBatchId && betas == other.betas && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ | ||
} | ||
|
||
override fun hashCode(): Int = /* spotless:off */ Objects.hash(messageBatchId, betas, additionalHeaders, additionalQueryParams) /* spotless:on */ | ||
|
||
override fun toString() = | ||
"BetaMessageBatchResultsParams{messageBatchId=$messageBatchId, betas=$betas, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" | ||
} |
Oops, something went wrong.