Class: Foobara::Ai::AnswerBot::ListModels
- Inherits:
-
Command
- Object
- Command
- Foobara::Ai::AnswerBot::ListModels
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
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Command
install!
#inspect, truncating
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#models ⇒ Object
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
#execute ⇒ Object
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_models ⇒ Object
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_models ⇒ Object
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_models ⇒ Object
26
27
28
|
# File 'src/foobara/ai/answer_bot/list_models.rb', line 26
def service_models
@service_models ||= []
end
|
#sort_models ⇒ Object
46
47
48
|
# File 'src/foobara/ai/answer_bot/list_models.rb', line 46
def sort_models
models.sort_by!(&:id)
end
|