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.
-
#effort ⇒ Object
Returns the value of attribute effort.
-
#model ⇒ Object
Returns the value of attribute model.
-
#thinking_budget_tokens ⇒ Object
Returns the value of attribute thinking_budget_tokens.
Instance Method Summary collapse
- #chat(messages:, tools: nil, system: nil, model: nil, **opts) ⇒ Object
- #current_thinking_hash ⇒ 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 26 |
# 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) @thinking_budget_tokens = 0 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 |
#effort ⇒ Object
Returns the value of attribute effort.
18 19 20 |
# File 'lib/rubyn_code/llm/client.rb', line 18 def effort @effort 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 |
#thinking_budget_tokens ⇒ Object
Returns the value of attribute thinking_budget_tokens.
18 19 20 |
# File 'lib/rubyn_code/llm/client.rb', line 18 def thinking_budget_tokens @thinking_budget_tokens end |
Instance Method Details
#chat(messages:, tools: nil, system: nil, model: nil, **opts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubyn_code/llm/client.rb', line 28 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 effective_thinking = opts[:thinking] || current_thinking_hash kwargs = { messages: , tools: tools, system: system, model: effective_model, max_tokens: max_tokens, on_text: opts[:on_text], task_budget: opts[:task_budget] } kwargs[:thinking] = effective_thinking if effective_thinking kwargs[:effort] = @effort if @effort @adapter.chat(**kwargs) end |
#current_thinking_hash ⇒ Object
48 49 50 51 52 53 |
# File 'lib/rubyn_code/llm/client.rb', line 48 def current_thinking_hash budget = @thinking_budget_tokens.to_i return nil unless budget.positive? { budget_tokens: budget } end |
#models ⇒ Object
65 66 67 |
# File 'lib/rubyn_code/llm/client.rb', line 65 def models @adapter.models end |
#provider_name ⇒ Object
61 62 63 |
# File 'lib/rubyn_code/llm/client.rb', line 61 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
55 56 57 58 59 |
# File 'lib/rubyn_code/llm/client.rb', line 55 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.
74 75 76 77 78 |
# File 'lib/rubyn_code/llm/client.rb', line 74 def switch_provider!(provider, model: nil) @provider = provider @adapter = resolve_adapter(provider) @model = model if model end |