Class: RubynCode::LLM::Client
- Inherits:
-
Object
- Object
- RubynCode::LLM::Client
- Defined in:
- lib/rubyn_code/llm/client.rb
Overview
Thin facade over provider-specific adapters.
All consumers (Agent::Loop, REPL, DaemonRunner) talk to Client. Client delegates to the resolved adapter, which can be swapped at runtime via ‘switch_provider!` or the `/model` command.
Defined Under Namespace
Classes: AuthExpiredError, PromptTooLongError, RequestError
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #chat(messages:, tools: nil, system: nil, model: nil, **opts) ⇒ Object
-
#initialize(model: nil, provider: nil, adapter: nil) ⇒ Client
constructor
A new instance of Client.
- #models ⇒ Object
- #provider_name ⇒ Object
- #stream(messages:, tools: nil, system: nil, model: nil, max_tokens: Config::Defaults::CAPPED_MAX_OUTPUT_TOKENS, &block) ⇒ Object
-
#switch_provider!(provider, model: nil) ⇒ Object
Switch the active provider (and optionally model) at runtime.
Constructor Details
#initialize(model: nil, provider: nil, adapter: nil) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 |
# File 'lib/rubyn_code/llm/client.rb', line 20 def initialize(model: nil, provider: nil, adapter: nil) settings = Config::Settings.new @model = model || settings.model @provider = provider || settings.provider @adapter = adapter || resolve_adapter(@provider) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
17 18 19 |
# File 'lib/rubyn_code/llm/client.rb', line 17 def adapter @adapter end |
#model ⇒ Object
Returns the value of attribute model.
18 19 20 |
# File 'lib/rubyn_code/llm/client.rb', line 18 def model @model end |
Instance Method Details
#chat(messages:, tools: nil, system: nil, model: nil, **opts) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubyn_code/llm/client.rb', line 27 def chat(messages:, tools: nil, system: nil, model: nil, **opts) effective_model = model || @model max_tokens = opts[:max_tokens] || Config::Defaults::CAPPED_MAX_OUTPUT_TOKENS @adapter.chat( messages: , tools: tools, system: system, model: effective_model, max_tokens: max_tokens, on_text: opts[:on_text], task_budget: opts[:task_budget] ) end |
#models ⇒ Object
52 53 54 |
# File 'lib/rubyn_code/llm/client.rb', line 52 def models @adapter.models end |
#provider_name ⇒ Object
48 49 50 |
# File 'lib/rubyn_code/llm/client.rb', line 48 def provider_name @adapter.provider_name end |
#stream(messages:, tools: nil, system: nil, model: nil, max_tokens: Config::Defaults::CAPPED_MAX_OUTPUT_TOKENS, &block) ⇒ Object
42 43 44 45 46 |
# File 'lib/rubyn_code/llm/client.rb', line 42 def stream(messages:, tools: nil, system: nil, model: nil, max_tokens: Config::Defaults::CAPPED_MAX_OUTPUT_TOKENS, &block) chat(messages: , tools: tools, system: system, model: model, max_tokens: max_tokens, on_text: block) end |
#switch_provider!(provider, model: nil) ⇒ Object
Switch the active provider (and optionally model) at runtime. Called by the REPL when ‘/model provider:model` is used.
61 62 63 64 65 |
# File 'lib/rubyn_code/llm/client.rb', line 61 def switch_provider!(provider, model: nil) @provider = provider @adapter = resolve_adapter(provider) @model = model if model end |