Class: Ollama::Policies::CapabilityValidation
- Defined in:
- lib/ollama/policies/capability_validation.rb
Overview
CapabilityValidation policy - validates model capabilities before request
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#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, cache: nil, cache_ttl: 3600, hooks: {}) ⇒ CapabilityValidation
constructor
A new instance of CapabilityValidation.
Constructor Details
#initialize(enabled: true, cache: nil, cache_ttl: 3600, hooks: {}) ⇒ CapabilityValidation
Returns a new instance of CapabilityValidation.
15 16 17 18 19 20 21 |
# File 'lib/ollama/policies/capability_validation.rb', line 15 def initialize(enabled: true, cache: nil, cache_ttl: 3600, hooks: {}) super() @enabled = enabled @cache = cache @cache_ttl = cache_ttl @hooks = hooks end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
9 10 11 |
# File 'lib/ollama/policies/capability_validation.rb', line 9 def cache @cache end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/ollama/policies/capability_validation.rb', line 9 def enabled @enabled end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
9 10 11 |
# File 'lib/ollama/policies/capability_validation.rb', line 9 def hooks @hooks end |
Instance Method Details
#around(request, env, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ollama/policies/capability_validation.rb', line 23 def around(request, env, &block) return block.call(request, env) unless @enabled # Skip if no model or endpoint doesn't require capabilities return block.call(request, env) unless validate_capabilities?(request) model = request_model(request) return block.call(request, env) unless model # Get model profile (with caching) profile = get_model_profile(model) # Check capabilities missing = check_capabilities(request, profile) return block.call(request, env) if missing.empty? @hooks[:capability_missing]&.call(missing, model, env) raise UnsupportedCapabilityError, "Model '#{model}' does not support: #{missing.join(", ")}" end |