Class: LlmHub::Embedding::Client
- Inherits:
-
Common::ClientBase
- Object
- Common::ClientBase
- LlmHub::Embedding::Client
- Defined in:
- lib/llm_hub/embedding/client.rb
Overview
Client for LLM providers (OpenAI, Anthropic, etc.)
Constant Summary collapse
Instance Attribute Summary
Attributes inherited from Common::ClientBase
#api_key, #open_time_out, #provider, #read_time_out, #retry_count
Instance Method Summary collapse
-
#initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) ⇒ Client
constructor
Initialize a new embedding client.
-
#post_embedding(text:, model_name:, option_params: {}) ⇒ Hash{Symbol => Array<Float>, Hash}
Generate embeddings for the given text.
Methods included from Common::HttpHelper
Constructor Details
#initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) ⇒ Client
Initialize a new embedding client
20 21 22 23 |
# File 'lib/llm_hub/embedding/client.rb', line 20 def initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) super @provider_client = create_provider_client end |
Instance Method Details
#post_embedding(text:, model_name:, option_params: {}) ⇒ Hash{Symbol => Array<Float>, Hash}
Generate embeddings for the given text
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/llm_hub/embedding/client.rb', line 31 def ( text:, model_name:, option_params: {} ) with_retry do url = @provider_client.url request_body = @provider_client.request_body(text, model_name, option_params) headers = @provider_client.headers response_body = make_request(url, request_body, headers) formatted_response(response_body) end rescue StandardError => e { error: e. }.deep_symbolize_keys end |