Module: Legion::Extensions::Apollo::Helpers::Capability
- Extended by:
- Logging::Helper, Settings::Helper
- 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
- .apollo_write_enabled? ⇒ Boolean
- .can_embed? ⇒ Boolean
- .can_write? ⇒ Boolean
- .check_db_write_privilege ⇒ Object
- .cloud_embedding_configured? ⇒ Boolean
- .ollama_embedding_available? ⇒ Boolean
- .reset! ⇒ Object
Class Method Details
.apollo_write_enabled? ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 34 def apollo_write_enabled? settings[:data][:apollo_write] == true rescue StandardError => e handle_exception(e, level: :warn, operation: 'apollo.capability.apollo_write_enabled') false end |
.can_embed? ⇒ Boolean
15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 15 def return false unless defined?(Legion::LLM) && Legion::LLM.started? || rescue StandardError => e handle_exception(e, level: :warn, operation: 'apollo.capability.can_embed') false end |
.can_write? ⇒ Boolean
24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 24 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 handle_exception(e, level: :warn, operation: 'apollo.capability.can_write') false end |
.check_db_write_privilege ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 59 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 handle_exception(e, level: :warn, operation: 'apollo.capability.check_db_write_privilege') @apollo_write_privilege = false end |
.cloud_embedding_configured? ⇒ Boolean
50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 50 def provider = settings[:embedding][:provider] model = settings[:embedding][:model] !provider.nil? && !model.nil? rescue StandardError => e handle_exception(e, level: :warn, operation: 'apollo.capability.cloud_embedding_configured') false end |
.ollama_embedding_available? ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 41 def return false unless defined?(Legion::LLM::Discovery::Ollama) EMBEDDING_MODELS.any? { |m| Legion::LLM::Discovery::Ollama.model_available?(m) } rescue StandardError => e handle_exception(e, level: :warn, operation: 'apollo.capability.ollama_embedding_available') false end |
.reset! ⇒ Object
70 71 72 |
# File 'lib/legion/extensions/apollo/helpers/capability.rb', line 70 def reset! @apollo_write_privilege = nil end |