Skip to content

Commit 57485b0

Browse files
committed
Update streaming.rb to use idiomatic pattern when forking Faraday logic
1 parent dfad8ae commit 57485b0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/ruby_llm/streaming.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def stream_response(connection, payload, &block)
1212
accumulator = StreamAccumulator.new
1313

1414
connection.post stream_url, payload do |req|
15-
if Faraday::VERSION.start_with?('1')
16-
# Handle Faraday 1.x streaming with :on_data key
17-
req.options[:on_data] = handle_stream do |chunk|
15+
if req.options.respond_to?(:on_data)
16+
# Handle Faraday 2.x streaming with on_data method
17+
req.options.on_data = handle_stream do |chunk|
1818
accumulator.add chunk
1919
block.call chunk
2020
end
2121
else
22-
# Handle Faraday 2.x streaming with on_data method
23-
req.options.on_data = handle_stream do |chunk|
22+
# Handle Faraday 1.x streaming with :on_data key
23+
req.options[:on_data] = handle_stream do |chunk|
2424
accumulator.add chunk
2525
block.call chunk
2626
end

0 commit comments

Comments
 (0)