Skip to content

[Feature Request] Add support for Faraday proxy #55

@ethicalhack3r

Description

@ethicalhack3r

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions