Class: Soka::LLM
- Inherits:
-
Object
- Object
- Soka::LLM
- Defined in:
- lib/soka/llm.rb
Overview
LLM wrapper class that delegates to specific provider implementations
Instance Attribute Summary collapse
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Class Method Summary collapse
-
.build(config) ⇒ LLM
Build LLM instance from configuration object.
Instance Method Summary collapse
-
#chat(messages, **params) ⇒ LLMs::Result
Chat with the LLM.
-
#initialize(provider_name = nil, **options) ⇒ LLM
constructor
Initialize LLM with specified provider.
-
#model ⇒ String
Get the model being used.
-
#streaming_chat(messages, **params) {|chunk| ... } ⇒ Object
Stream chat responses.
-
#supports_streaming? ⇒ Boolean
Check if provider supports streaming.
Constructor Details
#initialize(provider_name = nil, **options) ⇒ LLM
Initialize LLM with specified provider
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/soka/llm.rb', line 11 def initialize(provider_name = nil, **) provider_name ||= Soka.configuration.ai.provider # Merge configuration options if no explicit options provided if .empty? && provider_name == Soka.configuration.ai.provider config = Soka.configuration.ai = { api_key: config.api_key, model: config.model }.compact end @provider = create_provider(provider_name, **) end |
Instance Attribute Details
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
6 7 8 |
# File 'lib/soka/llm.rb', line 6 def provider @provider end |
Class Method Details
.build(config) ⇒ LLM
Build LLM instance from configuration object
57 58 59 60 61 62 63 64 |
# File 'lib/soka/llm.rb', line 57 def self.build(config) = { model: config.model, api_key: config.api_key }.compact new(config.provider, **) end |
Instance Method Details
#chat(messages, **params) ⇒ LLMs::Result
Chat with the LLM
30 31 32 |
# File 'lib/soka/llm.rb', line 30 def chat(, **params) @provider.chat(, **params) end |
#model ⇒ String
Get the model being used
50 51 52 |
# File 'lib/soka/llm.rb', line 50 def model @provider.model end |
#streaming_chat(messages, **params) {|chunk| ... } ⇒ Object
Stream chat responses
38 39 40 |
# File 'lib/soka/llm.rb', line 38 def streaming_chat(, **params, &) @provider.streaming_chat(, **params, &) end |
#supports_streaming? ⇒ Boolean
Check if provider supports streaming
44 45 46 |
# File 'lib/soka/llm.rb', line 44 def supports_streaming? @provider.supports_streaming? end |