Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ruby_llm/stream_accumulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize

def add(chunk)
RubyLLM.logger.debug { chunk.inspect } if RubyLLM.config.log_stream_debug
@model_id ||= chunk.model_id
@model_id = chunk.model_id if @model_id.to_s.empty?

handle_chunk_content(chunk)
accumulate_citations(chunk.citations)
Expand Down
20 changes: 20 additions & 0 deletions spec/ruby_llm/stream_accumulator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

RSpec.describe RubyLLM::StreamAccumulator do
describe '#add' do
it 'ignores an empty model_id from an initial chunk' do
accumulator = described_class.new

accumulator.add(RubyLLM::Chunk.new(role: :assistant, content: '', model_id: ''))
accumulator.add(RubyLLM::Chunk.new(role: :assistant, content: 'Hi', model_id: 'gpt-5.4-2026-03-05'))

message = accumulator.to_message(nil)
expect(message.model_id).to eq('gpt-5.4-2026-03-05')
end

it 'keeps the first non-empty model_id' do
accumulator = described_class.new

accumulator.add(RubyLLM::Chunk.new(role: :assistant, content: 'Hi', model_id: 'model-a'))
accumulator.add(RubyLLM::Chunk.new(role: :assistant, content: '!', model_id: 'model-b'))

message = accumulator.to_message(nil)
expect(message.model_id).to eq('model-a')
end

it 'handles tool call deltas that omit arguments' do
accumulator = described_class.new
tool_call = RubyLLM::ToolCall.new(id: 'call_1', name: 'weather', arguments: nil)
Expand Down
Loading