Request for Feedback #95
Pinned
aaron-lerner
announced in
Announcements
Replies: 2 comments 2 replies
-
Thank you for exmaples. I've been able to find method I have produced some looping code that fullfils my flow:
public String askClaude(final String system, final String body) {
final var messageBuilder = createConversation(system, body);
var response = this.client.messages().create(messageBuilder.build());
boolean doLoop = true;
while (doLoop) {
final var previousResponse = response;
messageBuilder.addMessage(previousResponse);
final var newResponse = response.content().stream()
.map(content -> content.accept(new ContentBlock.Visitor<Message>() {
@Override
public Message visitTextBlock(@NotNull final TextBlock textBlock) {
return null; // end of looping
}
@Override
public Message visitToolUseBlock(@NotNull final ToolUseBlock toolUseBlock) {
messageBuilder.addMessage(
MessageParam.builder()
.role(MessageParam.Role.USER)
.content(
MessageParam.Content.ofContentBlockParams(
List.of(
ContentBlockParam.ofToolResultBlockParam(
ToolResultBlockParam.builder()
.type(ToolResultBlockParam.Type.TOOL_RESULT)
.toolUseId(toolUseBlock.id())
.content(executeToolUse(toolUseBlock))
.build()
)
)
)
)
.build()
);
return SyncRequestClient.this.client.messages().create(messageBuilder.build());
}
}))
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
// kind of heuristic ending
doLoop = newResponse != null;
if (newResponse != null) {
response = newResponse;
}
}
return response.content()
.stream()
.flatMap(contentBlock -> contentBlock.textBlock().stream())
.map(TextBlock::text)
.collect(Collectors.joining());
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi team, thanks for the good examples. Do we have a api to support big request body set/big body response? Or is not necessary in fact? like this case :
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
👋 Hi everyone!
This SDK is in alpha, and we are actively iterating on its design and making improvements. We would love to hear your thoughts and feedback!
As you try the new SDK, please share your thoughts and feedback. We'll be actively monitoring discussion threads and new issues.
Thanks in advance! We hope to make a Java SDK you'll love using.
Beta Was this translation helpful? Give feedback.
All reactions