Class: OllamaAgent::Providers::Base
- Inherits:
-
Object
- Object
- OllamaAgent::Providers::Base
- Defined in:
- lib/ollama_agent/providers/base.rb
Overview
Abstract base class for model providers.
Every provider must implement:
#chat(messages:, model:, tools: nil, stream_hooks: nil, **opts) → Response
#available? → Boolean
A Response must respond to:
#message → { role:, content:, tool_calls: }
#usage → { prompt_tokens:, completion_tokens:, total_tokens: } or nil
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#available? ⇒ Boolean
abstract
True when the provider can accept requests right now.
- #chat(messages:, model:, tools: nil, stream_hooks: nil, **opts) ⇒ Response abstract
-
#estimate_cost(input_tokens:, output_tokens:) ⇒ Object
Returns approximate cost in USD for the given token counts.
-
#initialize(name:, **options) ⇒ Base
constructor
A new instance of Base.
-
#streaming_supported? ⇒ Boolean
Override in subclasses that support streaming natively.
- #to_s ⇒ Object
Constructor Details
#initialize(name:, **options) ⇒ Base
Returns a new instance of Base.
44 45 46 47 |
# File 'lib/ollama_agent/providers/base.rb', line 44 def initialize(name:, **) @name = name.to_s @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
42 43 44 |
# File 'lib/ollama_agent/providers/base.rb', line 42 def name @name end |
Instance Method Details
#available? ⇒ Boolean
This method is abstract.
Returns true when the provider can accept requests right now.
61 62 63 |
# File 'lib/ollama_agent/providers/base.rb', line 61 def available? raise NotImplementedError, "#{self.class}#available? is not implemented" end |
#chat(messages:, model:, tools: nil, stream_hooks: nil, **opts) ⇒ Response
This method is abstract.
55 56 57 |
# File 'lib/ollama_agent/providers/base.rb', line 55 def chat(messages:, model:, tools: nil, stream_hooks: nil, **opts) raise NotImplementedError, "#{self.class}#chat is not implemented" end |
#estimate_cost(input_tokens:, output_tokens:) ⇒ Object
Returns approximate cost in USD for the given token counts. Subclasses may override with provider-specific pricing.
72 73 74 |
# File 'lib/ollama_agent/providers/base.rb', line 72 def estimate_cost(input_tokens:, output_tokens:) 0.0 end |
#streaming_supported? ⇒ Boolean
Override in subclasses that support streaming natively.
66 67 68 |
# File 'lib/ollama_agent/providers/base.rb', line 66 def streaming_supported? false end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/ollama_agent/providers/base.rb', line 76 def to_s "#<#{self.class.name} name=#{@name}>" end |