Skip to content
Open
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/openai/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
20 changes: 20 additions & 0 deletions spec/openai/client/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down