-
-
Notifications
You must be signed in to change notification settings - Fork 284
Closed
Description
There's a compatibility issue when using ruby_llm
's streaming capabilities with versions of faraday-net_http
older than 3.0.
Cause:
The RubyLLM::Streaming#to_json_stream
method defines an on_data
callback that expects three arguments: chunk
, _bytes
, and env
. It uses env.status
to check if the response status is 200.
# lib/ruby_llm/streaming.rb
proc do |chunk, _bytes, env|
# ...
if error_chunk?(chunk)
handle_error_chunk(chunk, env)
elsif env&.status != 200 # <-- Relies on env
handle_failed_response(chunk, buffer, env)
else
yield handle_sse(chunk, parser, env, &block)
end
end
However, in faraday-net_http
versions prior to 3.0 (e.g., this line), the on_data
callback was invoked with only two arguments (chunk
, size
):
# Older faraday-net_http code
env[:request].on_data.call(chunk, size)
This mismatch causes env
to be nil
within the to_json_stream
callback when using older adapter versions, leading to successful stream chunks being incorrectly handled as errors.
Resolution:
This issue is resolved by ensuring faraday-net_http
version 3.0 or later is used.
# ruby_llm.gemspec
spec.add_dependency 'faraday-net_http', '~> 3'
Metadata
Metadata
Assignees
Labels
No labels