Module: Legion::Extensions::Apollo::Helpers::Capability

Defined in:
lib/legion/extensions/apollo/helpers/capability.rb

Constant Summary collapse

EMBEDDING_MODELS =
%w[mxbai-embed-large bge-large snowflake-arctic-embed].freeze

Class Method Summary collapse

Class Method Details

.apollo_write_enabled?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 35

def apollo_write_enabled?
  Legion::Settings.dig(:data, :apollo_write) == true
rescue StandardError => e
  log.warn("Apollo Capability.apollo_write_enabled? failed: #{e.message}")
  false
end

.can_embed?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 16

def can_embed?
  return false unless defined?(Legion::LLM) && Legion::LLM.started?

  ollama_embedding_available? || cloud_embedding_configured?
rescue StandardError => e
  log.warn("Apollo Capability.can_embed? failed: #{e.message}")
  false
end

.can_write?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 25

def can_write?
  return false unless apollo_write_enabled?
  return false unless defined?(Legion::Data) && Legion::Data.connected?

  check_db_write_privilege
rescue StandardError => e
  log.warn("Apollo Capability.can_write? failed: #{e.message}")
  false
end

.check_db_write_privilegeObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 60

def check_db_write_privilege
  return @apollo_write_privilege unless @apollo_write_privilege.nil?

  @apollo_write_privilege = Legion::Data.connection
                                        .fetch("SELECT has_table_privilege(current_user, 'apollo_entries', 'INSERT') AS can_insert")
                                        .first[:can_insert] == true
rescue StandardError => e
  log.warn("Apollo Capability.check_db_write_privilege failed: #{e.message}")
  @apollo_write_privilege = false
end

.cloud_embedding_configured?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 51

def cloud_embedding_configured?
  provider = Legion::Settings.dig(:apollo, :embedding, :provider)
  model = Legion::Settings.dig(:apollo, :embedding, :model)
  !provider.nil? && !model.nil?
rescue StandardError => e
  log.warn("Apollo Capability.cloud_embedding_configured? failed: #{e.message}")
  false
end

.logObject



12
13
14
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 12

def log
  Legion::Logging
end

.ollama_embedding_available?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 42

def ollama_embedding_available?
  return false unless defined?(Legion::LLM::Discovery::Ollama)

  EMBEDDING_MODELS.any? { |m| Legion::LLM::Discovery::Ollama.model_available?(m) }
rescue StandardError => e
  log.warn("Apollo Capability.ollama_embedding_available? failed: #{e.message}")
  false
end

.reset!Object



71
72
73
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 71

def reset!
  @apollo_write_privilege = nil
end