Class StreamHelper
java.lang.Object
org.springframework.ai.anthropic.api.StreamHelper
Helper class to support streaming function calling and thinking events.
It can merge the streamed AnthropicApi.StreamEvent
chunks in case of function calling
message. It passes through other events like text, thinking, and signature deltas.
- Since:
- 1.0.0
- Author:
- Mariusz Bernacki, Christian Tzolov, Jihoon Kim, Alexandros Pappas, Claudio Silva Junior, Soby Chacko
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioneventToChatCompletionResponse
(AnthropicApi.StreamEvent event, AtomicReference<StreamHelper.ChatCompletionResponseBuilder> contentBlockReference) Converts a rawAnthropicApi.StreamEvent
potentially containing tool use aggregates or other block types (text, thinking) into aAnthropicApi.ChatCompletionResponse
chunk.boolean
boolean
mergeToolUseEvents
(AnthropicApi.StreamEvent previousEvent, AnthropicApi.StreamEvent event) Merge the tool‑use related streaming events into one aggregate event so that the upper layers see a single ContentBlock with the full JSON input.
-
Constructor Details
-
StreamHelper
public StreamHelper()
-
-
Method Details
-
isToolUseStart
-
isToolUseFinish
-
mergeToolUseEvents
public AnthropicApi.StreamEvent mergeToolUseEvents(AnthropicApi.StreamEvent previousEvent, AnthropicApi.StreamEvent event) Merge the tool‑use related streaming events into one aggregate event so that the upper layers see a single ContentBlock with the full JSON input. -
eventToChatCompletionResponse
public AnthropicApi.ChatCompletionResponse eventToChatCompletionResponse(AnthropicApi.StreamEvent event, AtomicReference<StreamHelper.ChatCompletionResponseBuilder> contentBlockReference) Converts a rawAnthropicApi.StreamEvent
potentially containing tool use aggregates or other block types (text, thinking) into aAnthropicApi.ChatCompletionResponse
chunk.- Parameters:
event
- The incoming StreamEvent.contentBlockReference
- Holds the state of the response being built across multiple events.- Returns:
- A ChatCompletionResponse representing the processed chunk.
-