Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming error mishandled in http.rb #20

Open
strukturedkaos opened this issue Jun 15, 2024 · 9 comments
Open

Streaming error mishandled in http.rb #20

strukturedkaos opened this issue Jun 15, 2024 · 9 comments

Comments

@strukturedkaos
Copy link

Line 154 in http.rb on env is nil on valid requests. This causes merge to error on line 157

 return unless env&.status != 200

Example:

          response = anthropic_client.messages(
            parameters: {
              temperature: 0.7,
              model: model,
              messages: message_data
              max_tokens: 100,
              preprocess_stream: :text,
              stream: proc do |incremental_response, delta|
                next if delta.blank?
                Rails.logger.info "Incremental response: #{incremental_response}"
                Rails.logger.info "Delta: #{delta}"
              end
            })  
@alexrudall
Copy link
Owner

Thanks, @strukturedkaos. Have you seen this occur @swombat ?

@redders123
Copy link

Any chance of this being fixed in the next few days? We can't use the streaming api right now.

@leo-quimbee
Copy link

Also getting this error

@alexrudall
Copy link
Owner

@redders123 will see if I can fix this

@strukturedkaos
Copy link
Author

@alexrudall Anything I can help with? Are you able to reproduce the issue?

In case it helps:

ruby 3.2.2
Rails 6.1.7.3

@alexrudall
Copy link
Owner

Hey @strukturedkaos -- struggling to find the time to look at this - but I'm very open to a PR if you're able to figure out a fix! If not I will get to it when I can.

@geeosh
Copy link

geeosh commented Jul 5, 2024

I ran into this as well, it's because the streaming proc method signature changed in Faraday 2.5.0, and any older version only provides the first two arguments to the proc (see 6799f58).

So you could update the gemspec to require ~> 2.5.0 of Faraday, although that wouldn't work for me as I have other gems that require < 2.0 of Faraday that I'm not able to easily upgrade.

The other option is to update Anthropic::HTTP#handle_faraday_error to accomodate the case where env isn't provided as a third argument. At first glance I don't see any way to get the http request status in order to check if there is an error with an older version of Faraday, so you might just have to assume the streaming request is successful on older versions of Faraday?

@alexrudall if you have any suggestions about how you'd like to handle older versions of Faraday and I can put together a PR.

@geeosh
Copy link

geeosh commented Jul 5, 2024

I created a PR that makes it functional for anyone using Faraday < 2.5.0: #21

Let me know if you have suggested changes on that one since it skips out on handling errors while receiving streaming results if Faraday < 2.5.0.

@strukturedkaos
Copy link
Author

@geeosh your fix worked for me. Thank you. Hopefully we can get the PR merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants