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

Inherits:
Command
  • Object
show all
Defined in:
foobara-ai-0.0.11/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

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from Command

install!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#run_subcommand!, #subcommand?

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#relevant_entity_classes

Methods included from NestedTransactionable

#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records

Methods included from CommandPatternImplementation::Concerns::Errors

#initialize

Methods included from CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Attribute Details

#modelsObject

Returns the value of attribute models.


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

def models
  @models
end

Instance Method Details

#executeObject

[View source]

18
19
20
21
22
23
24
# File 'foobara-ai-0.0.11/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

[View source]

40
41
42
43
44
# File 'foobara-ai-0.0.11/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

[View source]

32
33
34
35
36
37
38
# File 'foobara-ai-0.0.11/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

[View source]

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

def service_models
  @service_models ||= []
end

#sort_modelsObject

[View source]

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

def sort_models
  models.sort_by! do |model|
    [model.service, model.id]
  end
end