Module: Legion::LLM::Discovery

Extended by:
Legion::Logging::Helper
Defined in:
lib/legion/llm/discovery.rb,
lib/legion/llm/discovery/vllm.rb,
lib/legion/llm/discovery/ollama.rb,
lib/legion/llm/discovery/system.rb

Defined Under Namespace

Modules: Ollama, System, Vllm

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.embedding_fallback_chainObject (readonly)

Returns the value of attribute embedding_fallback_chain.



19
20
21
# File 'lib/legion/llm/discovery.rb', line 19

def embedding_fallback_chain
  @embedding_fallback_chain
end

.embedding_modelObject (readonly)

Returns the value of attribute embedding_model.



19
20
21
# File 'lib/legion/llm/discovery.rb', line 19

def embedding_model
  @embedding_model
end

.embedding_providerObject (readonly)

Returns the value of attribute embedding_provider.



19
20
21
# File 'lib/legion/llm/discovery.rb', line 19

def embedding_provider
  @embedding_provider
end

Class Method Details

.can_embed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/legion/llm/discovery.rb', line 21

def can_embed?
  @can_embed == true
end

.detect_embedding_capabilityObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/llm/discovery.rb', line 46

def detect_embedding_capability
  log.debug '[llm][discovery] detect_embedding_capability.enter'
  embedding_settings = Legion::LLM.settings[:embedding] || {}
  found = find_embedding_provider(embedding_settings)
  if found
    @can_embed = true
    @embedding_provider = found[:provider]
    @embedding_model = found[:model]
    @embedding_fallback_chain = build_embedding_fallback_chain(embedding_settings)
    log.info "[llm][discovery] embedding available provider=#{@embedding_provider} model=#{@embedding_model}"
  else
    @can_embed = false
    @embedding_fallback_chain = []
    log.info '[llm][discovery] no embedding provider available'
  end
rescue StandardError => e
  @can_embed = false
  @embedding_fallback_chain = []
  handle_exception(e, level: :warn, operation: 'llm.discovery.detect_embedding_capability')
end

.reset!Object



67
68
69
70
71
72
73
# File 'lib/legion/llm/discovery.rb', line 67

def reset!
  log.debug '[llm][discovery] reset'
  @can_embed = nil
  @embedding_provider = nil
  @embedding_model = nil
  @embedding_fallback_chain = nil
end

.runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/legion/llm/discovery.rb', line 25

def run
  log.debug '[llm][discovery] run.enter'

  if Legion::LLM.settings.dig(:providers, :ollama, :enabled)
    Ollama.refresh!
    System.refresh!
    names = Ollama.model_names
    log.info "[llm][discovery] ollama model_count=#{names.size} models=#{names.join(', ')}"
    log.info "[llm][discovery] system total_mb=#{System.total_memory_mb} available_mb=#{System.available_memory_mb}"
  end

  if Legion::LLM.settings.dig(:providers, :vllm, :enabled)
    Vllm.refresh!
    names = Vllm.model_names
    contexts = names.map { |n| "#{n}(#{Vllm.max_context(n)})" }
    log.info "[llm][discovery] vllm model_count=#{names.size} models=#{contexts.join(', ')}"
  end
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'llm.discovery.run')
end