Module: Ask::Rails::ServiceDiscovery
- Defined in:
- lib/ask/rails/service_discovery.rb
Constant Summary collapse
- SERVICE_GEMS_PATTERN =
/\Aask-(?!tools|tools-shell|agent|rails|core|auth|schema|llm)/
Class Method Summary collapse
Class Method Details
.build_system_prompt(contexts) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ask/rails/service_discovery.rb', line 33 def build_system_prompt(contexts) sections = ["## Available Services"] contexts.each do |mod| sections << "### #{mod.name.demodulize}" sections << mod::DESCRIPTION if mod.const_defined?(:DESCRIPTION) sections << "Documentation: #{mod::DOCS_URL}" if mod.const_defined?(:DOCS_URL) sections << "Authentication: #{mod::AUTH_HOW}" if mod.const_defined?(:AUTH_HOW) sections << "" end sections.join("\n") end |
.discover! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ask/rails/service_discovery.rb', line 10 def discover! service_gems = Gem.loaded_specs.keys.select { |name| name.match?(SERVICE_GEMS_PATTERN) } contexts = [] service_gems.each do |name| begin require "#{name.tr("-", "/")}/context" mod = name.camelize.constantize contexts << mod if mod.const_defined?(:DESCRIPTION) rescue LoadError, NameError # No context module for this gem end end unless contexts.empty? prompt = build_system_prompt(contexts) existing = Ask::Rails.configuration.system_prompt Ask::Rails.configuration.system_prompt = [existing, prompt].compact.join("\n\n") end contexts end |