Class: VoyageAI::Client
- Inherits:
-
Object
- Object
- VoyageAI::Client
- Defined in:
- lib/voyageai/client.rb
Overview
A client for interacting with the VoyageAI API.
Defined Under Namespace
Classes: RequestError
Instance Method Summary collapse
- #embed(input, model: Model::VOYAGE) ⇒ Embedding
-
#initialize(api_key: VoyageAI.config.api_key, host: VoyageAI.config.host, version: VoyageAI.config.version, logger: VoyageAI.config.logger) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ String
- #rerank(query:, documents:, model: Model::RERANK, top_k: nil, truncation: nil) ⇒ Object
Constructor Details
#initialize(api_key: VoyageAI.config.api_key, host: VoyageAI.config.host, version: VoyageAI.config.version, logger: VoyageAI.config.logger) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/voyageai/client.rb', line 21 def initialize( api_key: VoyageAI.config.api_key, host: VoyageAI.config.host, version: VoyageAI.config.version, logger: VoyageAI.config.logger ) @api_key = api_key || raise(ArgumentError, "api_key is required or ENV['VOYAGEAI_API_KEY'] must be present") @host = host @version = version @logger = logger end |
Instance Method Details
#embed(input, model: Model::VOYAGE) ⇒ Embedding
44 45 46 47 48 49 50 51 |
# File 'lib/voyageai/client.rb', line 44 def (input, model: Model::VOYAGE) payload = { input: arrayify(input), model: model } response = http.accept(:json).post("/#{@version}/embeddings", json: payload) raise RequestError.new(response:) unless response.status.ok? Embed.parse(data: response.parse) end |
#inspect ⇒ String
34 35 36 37 38 |
# File 'lib/voyageai/client.rb', line 34 def inspect masked_api_key = "#{@api_key[..4]}***" "#<#{self.class.name} api_key=#{masked_api_key.inspect} host=#{@host.inspect} version=#{@version.inspect}>" end |
#rerank(query:, documents:, model: Model::RERANK, top_k: nil, truncation: nil) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/voyageai/client.rb', line 58 def rerank(query:, documents:, model: Model::RERANK, top_k: nil, truncation: nil) payload = { query:, documents:, model:, top_k:, truncation: }.compact response = http.accept(:json).post("/#{@version}/rerank", json: payload) raise RequestError.new(response:) unless response.status.ok? Rerank.parse(data: response.parse) end |