Skip to content

Commit de136fa

Browse files
authored
Merge pull request #618 from daikimiura/main
Fix `ArgumentError` in `Stream#call` with `faraday-net_http` 2.1.0
2 parents 98f3a9a + 86942c5 commit de136fa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/openai/stream.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(user_proc:, parser: EventStreamParser::Parser.new)
1717
end
1818
end
1919

20-
def call(chunk, _bytes, env)
20+
def call(chunk, _bytes, env = nil)
2121
handle_http_error(chunk: chunk, env: env) if env && env.status != 200
2222

2323
parser.feed(chunk) do |event, data|

spec/openai/client/stream_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@
106106
CHUNK
107107
end
108108
end
109+
110+
context "when called with only 2 arguments (like Faraday 2.1.0)" do
111+
it "handles the call without env parameter" do
112+
expect(user_proc).to receive(:call)
113+
.with(
114+
JSON.parse('{"foo": "bar"}'),
115+
"event.test"
116+
)
117+
118+
# Faraday 2.1.0 calls with only (chunk, size), not (chunk, size, env)
119+
expect do
120+
stream.call(<<~CHUNK, bytes)
121+
event: event.test
122+
data: { "foo": "bar" }
123+
124+
#
125+
CHUNK
126+
end.not_to raise_error
127+
end
128+
end
109129
end
110130
end
111131

0 commit comments

Comments
 (0)