Skip to content

Commit

Permalink
chore: simplify examples involving lists (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jan 15, 2025
1 parent 16f8002 commit b9f1145
Show file tree
Hide file tree
Showing 27 changed files with 1,660 additions and 1,914 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,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()))
.build())
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
.build();
Message message = client.messages().create(params);
Expand All @@ -117,13 +116,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 @@ -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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BetaMessageBatchDeleteParamsTest {
fun createBetaMessageBatchDeleteParams() {
BetaMessageBatchDeleteParams.builder()
.messageBatchId("message_batch_id")
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ class BetaMessageBatchIndividualResponseTest {
.message(
BetaMessage.builder()
.id("msg_013Zva2CMHLNnXjNJJKqJ2EF")
.content(
listOf(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
.addContent(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
Expand Down Expand Up @@ -57,14 +55,12 @@ class BetaMessageBatchIndividualResponseTest {
.message(
BetaMessage.builder()
.id("msg_013Zva2CMHLNnXjNJJKqJ2EF")
.content(
listOf(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
.addContent(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BetaMessageBatchListParamsTest {
.afterId("after_id")
.beforeId("before_id")
.limit(1L)
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
}

Expand All @@ -25,7 +25,7 @@ class BetaMessageBatchListParamsTest {
.afterId("after_id")
.beforeId("before_id")
.limit(1L)
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
val expected = QueryParams.builder()
expected.put("after_id", "after_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BetaMessageBatchRetrieveParamsTest {
fun createBetaMessageBatchRetrieveParams() {
BetaMessageBatchRetrieveParams.builder()
.messageBatchId("message_batch_id")
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class BetaMessageBatchSucceededResultTest {
.message(
BetaMessage.builder()
.id("msg_013Zva2CMHLNnXjNJJKqJ2EF")
.content(
listOf(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
.addContent(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
Expand All @@ -46,14 +44,12 @@ class BetaMessageBatchSucceededResultTest {
.isEqualTo(
BetaMessage.builder()
.id("msg_013Zva2CMHLNnXjNJJKqJ2EF")
.content(
listOf(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
.addContent(
BetaContentBlock.ofBetaTextBlock(
BetaTextBlock.builder()
.text("Hi! My name is Claude.")
.type(BetaTextBlock.Type.TEXT)
.build()
)
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ class BetaMessageCountTokensParamsTest {
@Test
fun createBetaMessageCountTokensParams() {
BetaMessageCountTokensParams.builder()
.messages(
listOf(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.addMessage(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
.system(
Expand All @@ -43,60 +41,56 @@ class BetaMessageCountTokensParamsTest {
.build()
)
)
.tools(
listOf(
BetaMessageCountTokensParams.Tool.ofBetaTool(
BetaTool.builder()
.inputSchema(
BetaTool.InputSchema.builder()
.type(BetaTool.InputSchema.Type.OBJECT)
.properties(
JsonValue.from(
mapOf(
"location" to
mapOf(
"description" to
"The city and state, e.g. San Francisco, CA",
"type" to "string"
),
"unit" to
mapOf(
"description" to
"Unit for the output - one of (celsius, fahrenheit)",
"type" to "string"
)
)
.addTool(
BetaMessageCountTokensParams.Tool.ofBetaTool(
BetaTool.builder()
.inputSchema(
BetaTool.InputSchema.builder()
.type(BetaTool.InputSchema.Type.OBJECT)
.properties(
JsonValue.from(
mapOf(
"location" to
mapOf(
"description" to
"The city and state, e.g. San Francisco, CA",
"type" to "string"
),
"unit" to
mapOf(
"description" to
"Unit for the output - one of (celsius, fahrenheit)",
"type" to "string"
)
)
)
.build()
)
.name("name")
.cacheControl(
BetaCacheControlEphemeral.builder()
.type(BetaCacheControlEphemeral.Type.EPHEMERAL)
.build()
)
.description("Get the current weather in a given location")
.type(BetaTool.Type.CUSTOM)
.build()
)
)
.build()
)
.name("name")
.cacheControl(
BetaCacheControlEphemeral.builder()
.type(BetaCacheControlEphemeral.Type.EPHEMERAL)
.build()
)
.description("Get the current weather in a given location")
.type(BetaTool.Type.CUSTOM)
.build()
)
)
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
}

@Test
fun getBody() {
val params =
BetaMessageCountTokensParams.builder()
.messages(
listOf(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.addMessage(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
.system(
Expand All @@ -122,46 +116,44 @@ class BetaMessageCountTokensParamsTest {
.build()
)
)
.tools(
listOf(
BetaMessageCountTokensParams.Tool.ofBetaTool(
BetaTool.builder()
.inputSchema(
BetaTool.InputSchema.builder()
.type(BetaTool.InputSchema.Type.OBJECT)
.properties(
JsonValue.from(
mapOf(
"location" to
mapOf(
"description" to
"The city and state, e.g. San Francisco, CA",
"type" to "string"
),
"unit" to
mapOf(
"description" to
"Unit for the output - one of (celsius, fahrenheit)",
"type" to "string"
)
)
.addTool(
BetaMessageCountTokensParams.Tool.ofBetaTool(
BetaTool.builder()
.inputSchema(
BetaTool.InputSchema.builder()
.type(BetaTool.InputSchema.Type.OBJECT)
.properties(
JsonValue.from(
mapOf(
"location" to
mapOf(
"description" to
"The city and state, e.g. San Francisco, CA",
"type" to "string"
),
"unit" to
mapOf(
"description" to
"Unit for the output - one of (celsius, fahrenheit)",
"type" to "string"
)
)
)
.build()
)
.name("name")
.cacheControl(
BetaCacheControlEphemeral.builder()
.type(BetaCacheControlEphemeral.Type.EPHEMERAL)
.build()
)
.description("Get the current weather in a given location")
.type(BetaTool.Type.CUSTOM)
.build()
)
)
.build()
)
.name("name")
.cacheControl(
BetaCacheControlEphemeral.builder()
.type(BetaCacheControlEphemeral.Type.EPHEMERAL)
.build()
)
.description("Get the current weather in a given location")
.type(BetaTool.Type.CUSTOM)
.build()
)
)
.betas(listOf(AnthropicBeta.MESSAGE_BATCHES_2024_09_24))
.addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24)
.build()
val body = params.getBody()
assertThat(body).isNotNull
Expand Down Expand Up @@ -246,13 +238,11 @@ class BetaMessageCountTokensParamsTest {
fun getBodyWithoutOptionalFields() {
val params =
BetaMessageCountTokensParams.builder()
.messages(
listOf(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.addMessage(
BetaMessageParam.builder()
.content(BetaMessageParam.Content.ofString("string"))
.role(BetaMessageParam.Role.USER)
.build()
)
.model(Model.CLAUDE_3_5_HAIKU_LATEST)
.build()
Expand Down
Loading

0 comments on commit b9f1145

Please sign in to comment.