Class: Legion::Extensions::Llm::Ollama::Actor::DiscoveryRefresh

Inherits:
Actors::Every
  • Object
show all
Includes:
Inventory::ScopedRefresher, Logging::Helper
Defined in:
lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.every_secondsObject



31
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 31

def self.every_seconds = 300

Instance Method Details

#check_subtask?Boolean

Returns:

  • (Boolean)


37
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 37

def check_subtask?  = false

#compute_lanes_for_scopeObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 50

def compute_lanes_for_scope(**)
  return [] unless defined?(Legion::LLM::Call::Registry)

  lanes = []
  ollama_instances.each do |instance|
    collect_lanes_for_instance(instance, lanes)
  rescue StandardError => e
    handle_exception(e, level: :warn, handled: true,
                        operation: 'ollama.discovery_refresh.compute_lanes',
                        instance: instance[:instance])
  end
  lanes
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true,
                      operation: 'ollama.discovery_refresh.compute_lanes_for_scope')
  []
end

#credential_hashObject



68
69
70
71
72
73
74
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 68

def credential_hash(**)
  settings = ollama_settings
  Digest::SHA256.hexdigest(settings[:api_key].to_s + settings[:instances].to_s)[0, 16]
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: 'ollama.discovery_refresh.credential_hash')
  'unknown'
end

#generate_task?Boolean

Returns:

  • (Boolean)


38
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 38

def generate_task?  = false

#manualObject



76
77
78
79
80
81
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 76

def manual(**)
  tick if defined?(Legion::Extensions::Llm::Inventory::ScopedRefresher) &&
          respond_to?(:tick, true)
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: 'ollama.actor.discovery_refresh')
end

#run_now?Boolean

Returns:

  • (Boolean)


35
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 35

def run_now?        = true

#runner_classObject



33
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 33

def runner_class    = self.class

#runner_functionObject



34
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 34

def runner_function = 'manual'

#scope_keyObject



46
47
48
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 46

def scope_key(**)
  { provider: :ollama }
end

#timeObject



40
41
42
43
44
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 40

def time
  return self.class.every_seconds unless defined?(Legion::Settings)

  Legion::Settings.dig(:extensions, :llm, :ollama, :discovery_interval) || self.class.every_seconds
end

#use_runner?Boolean

Returns:

  • (Boolean)


36
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 36

def use_runner?     = false