Class: Regent::LLM
- Inherits:
-
Object
- Object
- Regent::LLM
- Defined in:
- lib/regent/llm.rb,
lib/regent/llm/base.rb,
lib/regent/llm/gemini.rb,
lib/regent/llm/ollama.rb,
lib/regent/llm/open_ai.rb,
lib/regent/llm/anthropic.rb,
lib/regent/llm/open_router.rb
Defined Under Namespace
Classes: APIKeyNotFoundError, Anthropic, ApiError, Base, Gemini, Ollama, OpenAI, OpenRouter, ProviderNotFoundError, Result
Constant Summary collapse
- DEFAULT_RETRY_COUNT =
3- PROVIDER_PATTERNS =
{ OpenAI: /^gpt-/, Gemini: /^gemini-/, Anthropic: /^claude-/ }.freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(model, strict_mode: true, **options) ⇒ LLM
constructor
A new instance of LLM.
- #invoke(messages, **args) ⇒ Object
Constructor Details
#initialize(model, strict_mode: true, **options) ⇒ LLM
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/regent/llm.rb', line 16 def initialize(model, strict_mode: true, **) @strict_mode = strict_mode = if model.class.ancestors.include?(Regent::LLM::Base) @model = model.model @provider = model else @model = model @provider = instantiate_provider end end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
28 29 30 |
# File 'lib/regent/llm.rb', line 28 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/regent/llm.rb', line 28 def end |
Instance Method Details
#invoke(messages, **args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/regent/llm.rb', line 30 def invoke(, **args) retries = 0 = [{ role: "user", content: }] if .is_a?(String) provider.invoke(, **args) rescue Faraday::Error, ApiError => error if error.respond_to?(:retryable?) && error.retryable? && retries < DEFAULT_RETRY_COUNT sleep(exponential_backoff(retries)) retry end handle_error(error) end |