Class: Foobara::Ai::AnswerBot::ListModels

Inherits:
Command
  • Object
show all
Defined in:
foobara-ai-1.0.4/src/foobara/ai/answer_bot/list_models.rb

Constant Summary collapse

LIST_COMMANDS =
AI_SERVICES.keys.map do |service|
  Foobara::Ai::AnswerBot::DomainMappers::ServiceToListModelsCommand.map!(service)
end

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

install!

Methods included from TruncatedInspect

#inspect, truncating

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Attribute Details

#modelsObject

Returns the value of attribute models.



30
31
32
# File 'src/foobara/ai/answer_bot/list_models.rb', line 30

def models
  @models
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
# File 'src/foobara/ai/answer_bot/list_models.rb', line 18

def execute
  run_each_list_command_and_collect_models
  map_to_foobara_models
  sort_models

  models
end

#map_to_foobara_modelsObject



40
41
42
43
44
# File 'src/foobara/ai/answer_bot/list_models.rb', line 40

def map_to_foobara_models
  self.models = service_models.map do |model|
    domain_map!(model, to: Types::Model)
  end
end

#run_each_list_command_and_collect_modelsObject



32
33
34
35
36
37
38
# File 'src/foobara/ai/answer_bot/list_models.rb', line 32

def run_each_list_command_and_collect_models
  threads = LIST_COMMANDS.map do |list_command|
    Thread.new { service_models.concat(run_subcommand!(list_command)) }
  end

  self.models = threads.each(&:join).map(&:value)
end

#service_modelsObject



26
27
28
# File 'src/foobara/ai/answer_bot/list_models.rb', line 26

def service_models
  @service_models ||= []
end

#sort_modelsObject



46
47
48
# File 'src/foobara/ai/answer_bot/list_models.rb', line 46

def sort_models
  models.sort_by!(&:id)
end