Class: Legion::CLI::Chat::Tools::RelateKnowledge

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/relate_knowledge.rb

Constant Summary collapse

DEFAULT_PORT =
4567
DEFAULT_HOST =
'127.0.0.1'

Instance Method Summary collapse

Instance Method Details

#execute(entry_id:, relation_types: nil, depth: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/cli/chat/tools/relate_knowledge.rb', line 29

def execute(entry_id:, relation_types: nil, depth: nil)
  depth = (depth || 2).clamp(1, 3)
  params = { depth: depth }
  params[:relation_types] = relation_types if relation_types

  data = apollo_related(entry_id, params)
  return "Apollo error: #{data[:error]}" if data[:error]

  entries = data[:entries] || []
  return "No related entries found for entry ##{entry_id}." if entries.empty?

  format_related(entry_id, entries, depth)
rescue Errno::ECONNREFUSED
  'Apollo unavailable (daemon not running).'
rescue StandardError => e
  Legion::Logging.warn("RelateKnowledge#execute failed: #{e.message}") if defined?(Legion::Logging)
  "Error finding related entries: #{e.message}"
end