Class: Desiru::Models::Base
- Inherits:
-
Object
- Object
- Desiru::Models::Base
- Defined in:
- lib/desiru/models/base.rb
Overview
Base adapter class for language model integrations Defines the interface all model adapters must implement
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#complete(prompt, **options) ⇒ Object
Main interface method - calls perform_completion with proper message formatting.
-
#healthy? ⇒ Boolean
Health check.
-
#initialize(config = {}) ⇒ Base
constructor
A new instance of Base.
-
#models ⇒ Object
Get available models.
- #reset_stats ⇒ Object
-
#stats ⇒ Object
Usage statistics.
-
#stream_complete(prompt, **options) ⇒ Object
Stream completion - optional implementation.
Constructor Details
#initialize(config = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 16 17 |
# File 'lib/desiru/models/base.rb', line 10 def initialize(config = {}) @config = default_config.merge(config) @client = build_client @request_count = 0 @token_count = 0 validate_config! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/desiru/models/base.rb', line 8 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/desiru/models/base.rb', line 8 def config @config end |
Instance Method Details
#complete(prompt, **options) ⇒ Object
Main interface method - calls perform_completion with proper message formatting
20 21 22 23 24 25 26 27 28 |
# File 'lib/desiru/models/base.rb', line 20 def complete(prompt, **) = (prompt, [:messages]) with_retry do response = perform_completion(, ) increment_stats(response[:usage][:total_tokens]) if response[:usage] response end end |
#healthy? ⇒ Boolean
Health check
41 42 43 44 45 46 |
# File 'lib/desiru/models/base.rb', line 41 def healthy? models true rescue StandardError false end |
#models ⇒ Object
Get available models
36 37 38 |
# File 'lib/desiru/models/base.rb', line 36 def models raise NotImplementedError, 'Subclasses must implement #models' end |
#reset_stats ⇒ Object
57 58 59 60 |
# File 'lib/desiru/models/base.rb', line 57 def reset_stats @request_count = 0 @token_count = 0 end |
#stats ⇒ Object
Usage statistics
49 50 51 52 53 54 55 |
# File 'lib/desiru/models/base.rb', line 49 def stats { request_count: @request_count, token_count: @token_count, model: config[:model] } end |
#stream_complete(prompt, **options) ⇒ Object
Stream completion - optional implementation
31 32 33 |
# File 'lib/desiru/models/base.rb', line 31 def stream_complete(prompt, **, &) raise NotImplementedError, "Streaming not supported by #{self.class.name}" end |