Skip to content

Stream broken in v8.2 with Faraday/NetHTTP adapter #617

@fabioxgn

Description

@fabioxgn

Describe the bug
Getting an error inside Faraday's on_data callback after upgrading from 8.1 to 8.2.

#<ArgumentError: wrong number of arguments (given 2, expected 3)>

Looks like the problem is that the gem is setting Faraday's on_data callback with invalid arguments, these are the last 2 lines in the call stack:

"/Users/fabiogomes/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/ruby-openai-8.2.0/lib/openai/stream.rb:20:in 'call'",
 "/Users/fabiogomes/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/faraday-net_http-2.1.0/lib/faraday/adapter/net_http.rb:112:in 'block in Faraday::Adapter::NetHttp#perform_request'",

Here's the Faraday code that is trying to call the function:

env[:request].on_data.call(chunk, size)

And the function definition:

def call(chunk, _bytes, env)
      handle_http_error(chunk: chunk, env: env) if env && env.status != 200

To Reproduce
Steps to reproduce the behavior:
Use stream with Faraday and NetHTTP with version 8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions