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

Constructor accepts logger: parameter #20

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/milvus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@

module Milvus
class Client
attr_reader :url, :api_key
attr_reader :url, :api_key, :adapter, :raise_error, :logger

API_VERSION = "v2/vectordb"

def initialize(url:, api_key: nil)
def initialize(
url:,
api_key: nil,
adapter: Faraday.default_adapter,
raise_error: false,
logger: nil
)
@url = url
@api_key = api_key
@adapter = adapter
@raise_error = raise_error
@logger = logger || Logger.new($stdout)
end

def collections
Expand Down Expand Up @@ -47,8 +56,10 @@ def connection
faraday.request :authorization, :Bearer, api_key
end
faraday.request :json
faraday.response :logger, logger, {headers: true, bodies: true, errors: true}
faraday.response :raise_error if raise_error
faraday.response :json, content_type: /\bjson$/
faraday.adapter Faraday.default_adapter
faraday.adapter adapter
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions spec/milvus/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Milvus::Client do
let(:client) {
described_class.new(
url: "localhost:8080",
api_key: "123"
)
}

describe "#initialize" do
it "creates a client" do
expect(client).to be_a(Milvus::Client)
end

it "accepts a custom logger" do
logger = Logger.new($stdout)
client = Milvus::Client.new(
url: "localhost:8080",
api_key: "123",
logger: logger
)
expect(client.logger).to eq(logger)
end
end
end