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

release: 0.1.0-alpha.8 #56

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
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.7"
".": "0.1.0-alpha.8"
}
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 0.1.0-alpha.8 (2025-01-15)

Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/anthropics/anthropic-sdk-java/compare/v0.1.0-alpha.7...v0.1.0-alpha.8)

### Chores

* **internal:** add and tweak check functions ([#55](https://github.com/anthropics/anthropic-sdk-java/issues/55)) ([16f8002](https://github.com/anthropics/anthropic-sdk-java/commit/16f80028849f54f8feab7314e33d557e4a923581))
* **internal:** tweak client options nullability handling ([16f8002](https://github.com/anthropics/anthropic-sdk-java/commit/16f80028849f54f8feab7314e33d557e4a923581))
* simplify examples involving lists ([#57](https://github.com/anthropics/anthropic-sdk-java/issues/57)) ([b9f1145](https://github.com/anthropics/anthropic-sdk-java/commit/b9f114543501938c386f659417e312844900dd56))
* simplify examples involving unions ([#58](https://github.com/anthropics/anthropic-sdk-java/issues/58)) ([e800907](https://github.com/anthropics/anthropic-sdk-java/commit/e800907343dfa88baf644eafa3953098072fcda0))


### Documentation

* don't mention a non-existent SDK ([#59](https://github.com/anthropics/anthropic-sdk-java/issues/59)) ([421a9ab](https://github.com/anthropics/anthropic-sdk-java/commit/421a9ab64779d1bb34fb10cd7ad014defe2660df))

## 0.1.0-alpha.7 (2025-01-14)

Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/anthropics/anthropic-sdk-java/compare/v0.1.0-alpha.6...v0.1.0-alpha.7)
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@

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

[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/0.1.0-alpha.7)
[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/0.1.0-alpha.8)

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

The Anthropic Java SDK provides convenient access to the Anthropic REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property.

The Anthropic Java SDK is similar to the Anthropic Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions.

## Documentation

The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/).
Expand All @@ -32,7 +30,7 @@ The REST API documentation can be found on [docs.anthropic.com](https://docs.an
<!-- x-release-please-start-version -->

```kotlin
implementation("com.anthropic:anthropic-java:0.1.0-alpha.7")
implementation("com.anthropic:anthropic-java:0.1.0-alpha.8")
```

#### Maven
Expand All @@ -41,7 +39,7 @@ implementation("com.anthropic:anthropic-java:0.1.0-alpha.7")
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>0.1.0-alpha.7</version>
<version>0.1.0-alpha.8</version>
</dependency>
```

Expand Down Expand Up @@ -84,14 +82,13 @@ import com.anthropic.models.Message;
import com.anthropic.models.MessageCreateParams;
import com.anthropic.models.MessageParam;
import com.anthropic.models.Model;
import java.util.List;

MessageCreateParams params = MessageCreateParams.builder()
.maxTokens(1024L)
.messages(List.of(MessageParam.builder()
.addMessage(MessageParam.builder()
.role(MessageParam.Role.USER)
.content(MessageParam.Content.ofString("Hello, Claude"))
.build()))
.content("Hello, Claude")
.build())
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
.build();
Message message = client.messages().create(params);
Expand All @@ -117,13 +114,12 @@ Use the `BetaMessageBatchListParams` builder to set parameters:
import com.anthropic.models.AnthropicBeta;
import com.anthropic.models.BetaMessageBatchListPage;
import com.anthropic.models.BetaMessageBatchListParams;
import java.util.List;

BetaMessageBatchListParams params = BetaMessageBatchListParams.builder()
.afterId("after_id")
.beforeId("before_id")
.limit(20L)
.betas(List.of(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build();
BetaMessageBatchListPage page1 = client.beta().messages().batches().list(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ package com.anthropic.core

@JvmSynthetic
internal fun <T : Any> checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required but was not set" }
checkNotNull(value) { "`$name` is required, but was not set" }

@JvmSynthetic
internal fun checkLength(name: String, value: String, length: Int): String =
value.also {
check(it.length == length) { "`$name` must have length $length, but was ${it.length}" }
}

@JvmSynthetic
internal fun checkMinLength(name: String, value: String, minLength: Int): String =
value.also {
check(it.length >= minLength) {
if (minLength == 1) "`$name` must be non-empty, but was empty"
else "`$name` must have at least length $minLength, but was ${it.length}"
}
}

@JvmSynthetic
internal fun checkMaxLength(name: String, value: String, maxLength: Int): String =
value.also {
check(it.length <= maxLength) {
"`$name` must have at most length $maxLength, but was ${it.length}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private constructor(
}

fun build(): ClientOptions {
checkRequired("httpClient", httpClient)
val httpClient = checkRequired("httpClient", httpClient)

val headers = Headers.builder()
val queryParams = QueryParams.builder()
Expand All @@ -209,10 +209,10 @@ private constructor(
queryParams.replaceAll(this.queryParams.build())

return ClientOptions(
httpClient!!,
httpClient,
PhantomReachableClosingHttpClient(
RetryingHttpClient.builder()
.httpClient(httpClient!!)
.httpClient(httpClient)
.clock(clock)
.maxRetries(maxRetries)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ sealed class JsonField<out T : Any> {
is JsonValue -> this
}

@JvmSynthetic fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume)

fun <R> accept(visitor: Visitor<T, R>): R =
when (this) {
is KnownValue -> visitor.visitKnown(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class BetaErrorResponseTest {
val betaErrorResponse =
BetaErrorResponse.builder()
.error(
BetaError.ofBetaInvalidRequestError(
BetaInvalidRequestError.builder()
.message("message")
.type(BetaInvalidRequestError.Type.INVALID_REQUEST_ERROR)
.build()
)
BetaInvalidRequestError.builder()
.message("message")
.type(BetaInvalidRequestError.Type.INVALID_REQUEST_ERROR)
.build()
)
.type(BetaErrorResponse.Type.ERROR)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BetaMessageBatchCancelParamsTest {
fun createBetaMessageBatchCancelParams() {
BetaMessageBatchCancelParams.builder()
.messageBatchId("message_batch_id")
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
}

Expand Down
Loading
Loading