Class: Ollama::Policies::AutoPull
- Defined in:
- lib/ollama/policies/auto_pull.rb
Overview
AutoPull policy - automatically pulls missing models on 404
Constant Summary collapse
- MAX_RETRY_ATTEMPTS =
1- PULLABLE_ENDPOINTS =
%i[chat generate embeddings show_model create_model].freeze
Instance Attribute Summary collapse
-
#allowed_patterns ⇒ Object
readonly
Returns the value of attribute allowed_patterns.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
Instance Method Summary collapse
- #around(request, env, &block) ⇒ Object
-
#initialize(enabled: true, allowed_patterns: ["*"], hooks: {}) ⇒ AutoPull
constructor
A new instance of AutoPull.
Constructor Details
#initialize(enabled: true, allowed_patterns: ["*"], hooks: {}) ⇒ AutoPull
Returns a new instance of AutoPull.
14 15 16 17 18 19 |
# File 'lib/ollama/policies/auto_pull.rb', line 14 def initialize(enabled: true, allowed_patterns: ["*"], hooks: {}) super() @enabled = enabled @allowed_patterns = Array(allowed_patterns) @hooks = hooks end |
Instance Attribute Details
#allowed_patterns ⇒ Object (readonly)
Returns the value of attribute allowed_patterns.
9 10 11 |
# File 'lib/ollama/policies/auto_pull.rb', line 9 def allowed_patterns @allowed_patterns end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/ollama/policies/auto_pull.rb', line 9 def enabled @enabled end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
9 10 11 |
# File 'lib/ollama/policies/auto_pull.rb', line 9 def hooks @hooks end |
Instance Method Details
#around(request, env, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ollama/policies/auto_pull.rb', line 24 def around(request, env, &block) return block.call(request, env) unless @enabled && pullable?(request) attempt = 0 loop do attempt += 1 env[:auto_pull_attempt] = attempt begin return block.call(request, env) rescue NotFoundError raise unless attempt <= MAX_RETRY_ATTEMPTS model = request_model(request) raise unless model && allowed?(model) @hooks[:before_pull]&.call(model, env) pull_model(model, env) @hooks[:after_pull]&.call(model, env) end end end |