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

Add ability to pass Faraday config block to Client #373

Merged
merged 5 commits into from
Nov 26, 2023
Merged

Conversation

alexrudall
Copy link
Owner

  • Add test that error messages are included in Faraday response body
  • Add ability to pass Faraday config block to client

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?

"message")).to include("Missing parameter 'name'")
end
end
end
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec is kind of unrelated but being unable to find this error is what triggered this PR. So including it

@ErikDeBruijn
Copy link

This is such interesting timing. I was thinking of adding something along these lines, actually, because so far I was monkey patching this in the initializer openai.rb!

OpenAI.configure do |config|
  config.access_token = Rails.application.credentials.open_ai_key
  config.request_timeout = 300
end

module OpenAI
  module HTTP
    def connection_with_timeout(multipart: false)
      original_connection(multipart:).tap do |conn|
        conn.use TimeoutMiddleware, timeout: @request_timeout
      end
    end

    alias_method :original_connection, :conn
    alias_method :conn, :connection_with_timeout
  end
end

Obviously, having such a block to configure the Faraday object is an improvement.

FYI: this was because I was still observing time outs

@alexrudall
Copy link
Owner Author

This is such interesting timing. I was thinking of adding something along these lines, actually, because so far I was monkey patching this in the initializer openai.rb!


OpenAI.configure do |config|

  config.access_token = Rails.application.credentials.open_ai_key

  config.request_timeout = 300

end



module OpenAI

  module HTTP

    def connection_with_timeout(multipart: false)

      original_connection(multipart:).tap do |conn|

        conn.use TimeoutMiddleware, timeout: @request_timeout

      end

    end



    alias_method :original_connection, :conn

    alias_method :conn, :connection_with_timeout

  end

end

Obviously, having such a block to configure the Faraday object is an improvement.

FYI: this was because I was still observing time outs

Ah sweet - could you test this PR with that use case? Would be much appreciated 🙏

Copy link
Contributor

@obie obie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do merge

@alexrudall alexrudall merged commit d25d085 into main Nov 26, 2023
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

Successfully merging this pull request may close these issues.

3 participants