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

[Feature Request] Add support for Faraday proxy #55

Open
ethicalhack3r opened this issue Aug 16, 2024 · 3 comments
Open

[Feature Request] Add support for Faraday proxy #55

ethicalhack3r opened this issue Aug 16, 2024 · 3 comments

Comments

@ethicalhack3r
Copy link

ethicalhack3r commented Aug 16, 2024

Hi,

I tried to get this working myself by pulling the weaviate-ruby repo and langchainrb, but could not get it to work.

I couldn't get bundler to use the local Gem versions for some reason, I think due to Homebrew overriding the path, or something.

So thought I'd ask for a feature request, rather than bang my head against gem dependencies, as I was getting no where fast.

Here's my Git Diff:

% git diff
diff --git a/lib/weaviate/client.rb b/lib/weaviate/client.rb
index d957ac7..c57b9ed 100644
--- a/lib/weaviate/client.rb
+++ b/lib/weaviate/client.rb
@@ -5,7 +5,7 @@ require "graphlient"
 
 module Weaviate
   class Client
-    attr_reader :url, :api_key, :model_service, :model_service_api_key, :adapter
+    attr_reader :url, :api_key, :model_service, :model_service_api_key, :adapter, :proxy
 
     API_VERSION = "v1"
 
@@ -23,7 +23,8 @@ module Weaviate
       api_key: nil,
       model_service: nil,
       model_service_api_key: nil,
-      adapter: Faraday.default_adapter
+      adapter: Faraday.default_adapter,
+      proxy: nil
     )
       validate_model_service!(model_service) unless model_service.nil?
 
@@ -32,6 +33,7 @@ module Weaviate
       @model_service = model_service
       @model_service_api_key = model_service_api_key
       @adapter = adapter
+      @proxy = proxy
     end
 
     def oidc
@@ -100,7 +102,7 @@ module Weaviate
     end
 
     def connection
-      @connection ||= Faraday.new(url: "#{url}/#{API_VERSION}/") do |faraday|
+      @connection ||= Faraday.new(url: "#{url}/#{API_VERSION}/", proxy: proxy) do |faraday|
         if api_key
           faraday.request :authorization, :Bearer, api_key
         end

A proxy feature would be super useful in debugging connection issues.

Perhaps a better way to do this, to ensure other connection options are also supported, would be to allow a hash of connection options passed to the Client, as seen in this example I found online:

conn_options = { ssl: {verify: false} }
conn_options[:proxy] = "http://localhost"
conn = Faraday.new(url, conn_options) do |conn|
  # middleware ...
  conn.adapter :em_http
end

Thanks,
Ryan

@andreibondarev
Copy link
Collaborator

@ethicalhack3r Have you tried passing adapter: :em_http in the initializer? What's your use-case, is it storing multiple vectors in parallel?

@ethicalhack3r
Copy link
Author

@andreibondarev Hi! Not sure if adapter: :em_http is relevant, but perhaps I'm misunderstanding your response.

The use case is to use a web proxy see the raw HTTP requests and responses that Faraday makes, so that I can debug connection problems.

But I think it would be a good idea to be able pass arbitrary Faraday connection options within a Hash.

Hope that makes sense.

@andreibondarev
Copy link
Collaborator

andreibondarev commented Aug 19, 2024

@ethicalhack3r Over the long-term I'd like to switch to using Net::HTTP native library instead of requiring the faraday dependency: #56.

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

2 participants