Class: LlmConductor::Clients::BaseClient
- Inherits:
-
Object
- Object
- LlmConductor::Clients::BaseClient
- Includes:
- Concerns::Retryable, Prompts
- Defined in:
- lib/llm_conductor/clients/base_client.rb
Overview
Base client class providing common functionality for all LLM providers including prompt building, token counting, and response formatting.
Every provider request goes through Concerns::Retryable, so transient rate-limit/overload failures are retried according to configuration.max_retries and configuration.retry_delay. See docs/retries.md for the exact policy.
Direct Known Subclasses
AnthropicClient, GeminiClient, GptClient, GroqClient, OllamaClient, OpenrouterClient, ZaiClient
Constant Summary
Constants included from Concerns::Retryable
Concerns::Retryable::JITTER_RATIO, Concerns::Retryable::MAX_BACKOFF_SECONDS, Concerns::Retryable::MAX_RETRY_AFTER_SECONDS, Concerns::Retryable::RETRYABLE_STATUSES, Concerns::Retryable::TRANSPORT_ERRORS
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #generate(data:) ⇒ Object
-
#generate_simple(prompt:) ⇒ Object
Simple generation method that accepts a direct prompt and returns a Response object.
-
#initialize(model:, type:, params: {}) ⇒ BaseClient
constructor
A new instance of BaseClient.
Methods included from Concerns::Retryable
Methods included from Prompts
#prompt_analyze_content, #prompt_classify_content, #prompt_custom, #prompt_extract_links, #prompt_summarize_text
Constructor Details
#initialize(model:, type:, params: {}) ⇒ BaseClient
Returns a new instance of BaseClient.
23 24 25 26 27 |
# File 'lib/llm_conductor/clients/base_client.rb', line 23 def initialize(model:, type:, params: {}) @model = model @type = type @params = params end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/llm_conductor/clients/base_client.rb', line 21 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
21 22 23 |
# File 'lib/llm_conductor/clients/base_client.rb', line 21 def params @params end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/llm_conductor/clients/base_client.rb', line 21 def type @type end |
Instance Method Details
#generate(data:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/llm_conductor/clients/base_client.rb', line 29 def generate(data:) prompt = build_prompt(data) input_tokens = calculate_tokens(prompt) output_text = with_retries { generate_content(prompt) } output_tokens = calculate_tokens(output_text || '') # Logging AI request metadata if logger is set configuration.logger&.debug( "Vendor: #{vendor_name}, Model: #{@model} " \ "Output_tokens: #{output_tokens} Input_tokens: #{input_tokens}" ) build_response(output_text, input_tokens, output_tokens, { prompt: }) rescue StandardError => e build_error_response(e) end |
#generate_simple(prompt:) ⇒ Object
Simple generation method that accepts a direct prompt and returns a Response object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/llm_conductor/clients/base_client.rb', line 47 def generate_simple(prompt:) input_tokens = calculate_tokens(prompt) output_text = with_retries { generate_content(prompt) } output_tokens = calculate_tokens(output_text || '') # Logging AI request metadata if logger is set configuration.logger&.debug( "Vendor: #{vendor_name}, Model: #{@model} " \ "Output_tokens: #{output_tokens} Input_tokens: #{input_tokens}" ) build_response(output_text, input_tokens, output_tokens) rescue StandardError => e build_error_response(e) end |