From d3534c117cf3cac86afe02d026f44508f050a320 Mon Sep 17 00:00:00 2001 From: daikimiura Date: Sun, 17 Aug 2025 16:07:15 +0900 Subject: [PATCH 1/2] Add spec --- spec/openai/client/stream_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/openai/client/stream_spec.rb b/spec/openai/client/stream_spec.rb index df97972e..47544e49 100644 --- a/spec/openai/client/stream_spec.rb +++ b/spec/openai/client/stream_spec.rb @@ -106,6 +106,26 @@ CHUNK end end + + context "when called with only 2 arguments (like Faraday 2.1.0)" do + it "handles the call without env parameter" do + expect(user_proc).to receive(:call) + .with( + JSON.parse('{"foo": "bar"}'), + "event.test" + ) + + # Faraday 2.1.0 calls with only (chunk, size), not (chunk, size, env) + expect do + stream.call(<<~CHUNK, bytes) + event: event.test + data: { "foo": "bar" } + + # + CHUNK + end.not_to raise_error + end + end end end From 86942c51a7a30d08673f856f330aedd9e2329faa Mon Sep 17 00:00:00 2001 From: daikimiura Date: Sun, 17 Aug 2025 16:07:34 +0900 Subject: [PATCH 2/2] Fix arg --- lib/openai/stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openai/stream.rb b/lib/openai/stream.rb index 6bd70e6c..64cf704e 100644 --- a/lib/openai/stream.rb +++ b/lib/openai/stream.rb @@ -17,7 +17,7 @@ def initialize(user_proc:, parser: EventStreamParser::Parser.new) end end - def call(chunk, _bytes, env) + def call(chunk, _bytes, env = nil) handle_http_error(chunk: chunk, env: env) if env && env.status != 200 parser.feed(chunk) do |event, data|