Class: LlmHub::Completion::Client
- Inherits:
-
LlmHub::Common::ClientBase
- Object
- LlmHub::Common::ClientBase
- LlmHub::Completion::Client
- Defined in:
- lib/llm_hub/completion/client.rb
Overview
Client for LLM providers (OpenAI, Anthropic, etc.)
Constant Summary collapse
- PROVIDER_CLASSES =
Available provider mappings
{ openai: Providers::OpenAI, anthropic: Providers::Anthropic, deepseek: Providers::Deepseek, google: Providers::Google }.freeze
Instance Attribute Summary
Attributes inherited from LlmHub::Common::ClientBase
#api_key, #open_time_out, #provider, #read_time_out, #retry_count
Instance Method Summary collapse
-
#ask_single_question(system_prompt:, content:, model_name:, option_params: {}) ⇒ Hash{Symbol => String, Integer}
Execute a single question prompt and return the response.
-
#initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) ⇒ Client
constructor
Initialize a new completion client.
Methods included from LlmHub::Common::HttpHelper
Constructor Details
#initialize(api_key:, provider:, open_time_out: nil, read_time_out: nil, retry_count: nil) ⇒ Client
Initialize a new completion client
23 24 25 26 |
# File 'lib/llm_hub/completion/client.rb', line 23 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
#ask_single_question(system_prompt:, content:, model_name:, option_params: {}) ⇒ Hash{Symbol => String, Integer}
Execute a single question prompt and return the response
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/llm_hub/completion/client.rb', line 35 def ask_single_question( system_prompt:, content:, model_name:, option_params: {} ) with_retry do url = provider_url(model_name) request_body = @provider_client.request_body(system_prompt, content, 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 |