Accumulates streaming chunks into a complete response. Handles content accumulation, tool call accumulation, thinking content, and token tracking.
Mutable and not thread-safe: use one accumulator per stream, fed from the thread that reads it. Tool calls are keyed by id, so every chunk of a streamed tool call - continuations included - must carry its call's id; a tool-call chunk with an empty id is ignored. Clients whose wire format identifies continuations only by index must map them back to the id first.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Concrete methods
Add a streaming chunk to the accumulator
Add a streaming chunk to the accumulator
Attributes
Add thinking content delta directly
Add thinking content delta directly
Attributes
Clear the accumulator state
Clear the accumulator state
Attributes
Get the current accumulated content
Get the current accumulated content
Attributes
Get the current accumulated thinking content
Get the current accumulated thinking content
Attributes
Get the current tool calls, in the order each was first seen in the stream
Get the current tool calls, in the order each was first seen in the stream
Attributes
Check if there is any thinking content
Check if there is any thinking content
Attributes
Check if accumulation is complete
Check if accumulation is complete
Attributes
Convert accumulated data to a Completion, stamped with the current time
Convert accumulated data to a Completion, stamped with the current time
Attributes
Convert accumulated data to a Completion, stamped with the given creation time. Pure given the accumulator's current state - split out from the no-arg overload so the conversion itself is testable without a real clock.
Convert accumulated data to a Completion, stamped with the given creation time. Pure given the accumulator's current state - split out from the no-arg overload so the conversion itself is testable without a real clock.
Attributes
Update the prompt and completion token counts.
Update the prompt and completion token counts.
The completion's total becomes their sum plus any thinking tokens; cache counts set by updateUsage are kept. Use updateUsage when the provider reports more than these two.
Attributes
Update token counts including thinking tokens.
Update token counts including thinking tokens.
The completion's total becomes their sum; cache counts set by updateUsage are kept.
Attributes
Merge a provider's usage report into the accumulated usage, every org.llm4s.llmconnect.model.TokenUsage field included, so a streamed org.llm4s.llmconnect.model.Completion reports what a non-streaming one does.
Merge a provider's usage report into the accumulated usage, every org.llm4s.llmconnect.model.TokenUsage field included, so a streamed org.llm4s.llmconnect.model.Completion reports what a non-streaming one does.
Call it once per usage report the stream carries. Each field follows the latest report that states it: promptTokens and completionTokens when positive, the Option fields (thinkingTokens, cachedTokens, cacheCreationTokens) when defined, and totalTokens when positive. A field a report leaves at zero or None keeps its earlier value, so a provider that splits its usage across events (input and cache counts first, output last) can pass each part as it arrives. When no report states a total, the completion's total is prompt plus completion plus thinking tokens.
Value parameters
- usage
-
the usage as the provider reported it, in llm4s's terms:
thinkingTokensthe reasoning tokens,cachedTokensthe prompt tokens read from the provider's prompt cache,cacheCreationTokensthose written to it