Class: Ace::LLM::Organisms::BaseClient
- Inherits:
-
Object
- Object
- Ace::LLM::Organisms::BaseClient
- Defined in:
- lib/ace/llm/organisms/base_client.rb
Overview
BaseClient provides common functionality for all LLM provider clients
Direct Known Subclasses
AnthropicClient, GoogleClient, GroqClient, LMStudioClient, MistralClient, OpenAIClient, OpenRouterClient, TogetherAIClient, XAIClient, ZaiClient
Constant Summary collapse
- DEFAULT_GENERATION_CONFIG =
Default generation configuration
{ temperature: 0.7, max_tokens: nil, top_p: nil, top_k: nil }.freeze
- DEFAULT_SYSTEM_PROMPT_SEPARATOR =
Default separator for concatenating system prompts Can be overridden by subclasses if needed
"\n\n---\n\n"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#generation_config ⇒ Object
readonly
Returns the value of attribute generation_config.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
-
.provider_name ⇒ String
Get the provider name (class method).
Instance Method Summary collapse
-
#generate(messages, **options) ⇒ Hash
Generate a response from the LLM.
-
#initialize(api_key: nil, model: nil, **options) ⇒ BaseClient
constructor
Initialize base client with common configuration.
-
#needs_credentials? ⇒ Boolean
Check if this client needs API credentials.
-
#provider_name ⇒ String
Get the provider name for this client.
Constructor Details
#initialize(api_key: nil, model: nil, **options) ⇒ BaseClient
Initialize base client with common configuration
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ace/llm/organisms/base_client.rb', line 29 def initialize(api_key: nil, model: nil, **) # Prevent direct instantiation of abstract base class if instance_of?(BaseClient) raise NotImplementedError, "BaseClient is abstract and cannot be instantiated directly" end @model = model || default_model @base_url = .fetch(:base_url, self.class::API_BASE_URL) @generation_config = self.class::DEFAULT_GENERATION_CONFIG.merge( .fetch(:generation_config, {}) ) # Setup API key @api_key = api_key || fetch_api_key_from_env # Setup HTTP client @http_client = Atoms::HTTPClient.new( timeout: .fetch(:timeout, 30), max_retries: .fetch(:max_retries, 3) ) @options = end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/ace/llm/organisms/base_client.rb', line 23 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
23 24 25 |
# File 'lib/ace/llm/organisms/base_client.rb', line 23 def base_url @base_url end |
#generation_config ⇒ Object (readonly)
Returns the value of attribute generation_config.
23 24 25 |
# File 'lib/ace/llm/organisms/base_client.rb', line 23 def generation_config @generation_config end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
23 24 25 |
# File 'lib/ace/llm/organisms/base_client.rb', line 23 def http_client @http_client end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
23 24 25 |
# File 'lib/ace/llm/organisms/base_client.rb', line 23 def model @model end |
Class Method Details
.provider_name ⇒ String
Get the provider name (class method)
69 70 71 |
# File 'lib/ace/llm/organisms/base_client.rb', line 69 def self.provider_name raise NotImplementedError, "#{name} must implement .provider_name" end |
Instance Method Details
#generate(messages, **options) ⇒ Hash
Generate a response from the LLM
57 58 59 |
# File 'lib/ace/llm/organisms/base_client.rb', line 57 def generate(, **) raise NotImplementedError, "Subclasses must implement #generate" end |
#needs_credentials? ⇒ Boolean
Check if this client needs API credentials
75 76 77 |
# File 'lib/ace/llm/organisms/base_client.rb', line 75 def needs_credentials? true end |
#provider_name ⇒ String
Get the provider name for this client
63 64 65 |
# File 'lib/ace/llm/organisms/base_client.rb', line 63 def provider_name self.class.provider_name end |