Skip to content

Commit 9704fe1

Browse files
committed
Support attachments when accumulating streams
1 parent 9bf9e3e commit 9704fe1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/ruby_llm/stream_accumulator.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def initialize
1010
@tool_calls = {}
1111
@input_tokens = 0
1212
@output_tokens = 0
13+
@cached_tokens = 0
14+
@cache_creation_tokens = 0
1315
@latest_tool_call_id = nil
1416
end
1517

@@ -35,6 +37,8 @@ def to_message(response)
3537
tool_calls: tool_calls_from_stream,
3638
input_tokens: @input_tokens.positive? ? @input_tokens : nil,
3739
output_tokens: @output_tokens.positive? ? @output_tokens : nil,
40+
cached_tokens: @cached_tokens.positive? ? @cached_tokens : nil,
41+
cache_creation_tokens: @cache_creation_tokens.positive? ? @cache_creation_tokens : nil,
3842
raw: response
3943
)
4044
end
@@ -90,6 +94,8 @@ def find_tool_call(tool_call_id)
9094
def count_tokens(chunk)
9195
@input_tokens = chunk.input_tokens if chunk.input_tokens
9296
@output_tokens = chunk.output_tokens if chunk.output_tokens
97+
@cached_tokens = chunk.cached_tokens if chunk.cached_tokens
98+
@cache_creation_tokens = chunk.cache_creation_tokens if chunk.cache_creation_tokens
9399
end
94100
end
95101
end

0 commit comments

Comments
 (0)