Class: AsktiveRecord::Adapters::Base
- Inherits:
-
Object
- Object
- AsktiveRecord::Adapters::Base
- Defined in:
- lib/asktive_record/adapters/base.rb
Overview
Base adapter class that defines the interface all LLM adapters must implement. To create a custom adapter, inherit from this class and implement the required methods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Instance Method Summary collapse
-
#chat(prompt, options = {}) ⇒ String?
Send a prompt to the LLM and return the text response.
-
#default_model_name ⇒ String
Returns the default model name for this adapter.
-
#initialize(api_key:, model_name: nil) ⇒ Base
constructor
A new instance of Base.
-
#resolved_model_name ⇒ String
Returns the resolved model name (configured or default).
Constructor Details
#initialize(api_key:, model_name: nil) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 27 28 29 30 |
# File 'lib/asktive_record/adapters/base.rb', line 22 def initialize(api_key:, model_name: nil) @api_key = api_key @model_name = model_name return if @api_key raise ConfigurationError, "LLM API key is required for adapter initialization." end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
20 21 22 |
# File 'lib/asktive_record/adapters/base.rb', line 20 def api_key @api_key end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
20 21 22 |
# File 'lib/asktive_record/adapters/base.rb', line 20 def model_name @model_name end |
Instance Method Details
#chat(prompt, options = {}) ⇒ String?
Send a prompt to the LLM and return the text response.
37 38 39 |
# File 'lib/asktive_record/adapters/base.rb', line 37 def chat(prompt, = {}) raise NotImplementedError, "#{self.class.name} must implement #chat" end |
#default_model_name ⇒ String
Returns the default model name for this adapter.
44 45 46 |
# File 'lib/asktive_record/adapters/base.rb', line 44 def default_model_name raise NotImplementedError, "#{self.class.name} must implement #default_model_name" end |
#resolved_model_name ⇒ String
Returns the resolved model name (configured or default).
51 52 53 |
# File 'lib/asktive_record/adapters/base.rb', line 51 def resolved_model_name model_name || default_model_name end |