Improve Anthropic Claude streaming handling
- add StreamEven API domain model for reliably parsing stream events. - add StreamHelper#mergeToolUseEvents to aggregate partial tool use jsons into a list of ContentBlocks. - add StreamHelper#eventToChatCompletionResponse to convert Flux<StreamEvents> into Flux<ChatCompletionResponse>. - Rename MediaContent -> ContentBlock, RequestMessage -> AnthropicMessage, ChatCompletion -> ChatCompletionResponse. - Improve tests and docs.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 558 KiB After Width: | Height: | Size: 447 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 444 KiB |
@@ -279,6 +279,8 @@ Following class diagram illustrates the `AnthropicApi` chat interfaces and build
|
||||
|
||||
image::anthropic-claude3-class-diagram.jpg[AnthropicApi Chat API Diagram, width=1000, align="center"]
|
||||
|
||||
image::anthropic-claude3-events-model.jpg[AnthropicApi Event Model, width=1000, align="center"]
|
||||
|
||||
Here is a simple snippet how to use the api programmatically:
|
||||
|
||||
[source,java]
|
||||
@@ -286,11 +288,11 @@ Here is a simple snippet how to use the api programmatically:
|
||||
AnthropicApi anthropicApi =
|
||||
new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));
|
||||
|
||||
RequestMessage chatCompletionMessage = new RequestMessage(
|
||||
List.of(new MediaContent("Tell me a Joke?")), Role.USER);
|
||||
AnthropicMessage chatCompletionMessage = new AnthropicMessage(
|
||||
List.of(new ContentBlock("Tell me a Joke?")), Role.USER);
|
||||
|
||||
// Sync request
|
||||
ResponseEntity<ChatCompletion> response = anthropicApi
|
||||
ResponseEntity<ChatCompletionResponse> response = anthropicApi
|
||||
.chatCompletionEntity(new ChatCompletionRequest(AnthropicApi.ChatModel.CLAUDE_3_OPUS.getValue(),
|
||||
List.of(chatCompletionMessage), null, 100, 0.8f, false));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user