Class: Foobara::Ai::AnswerBot::Ask

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

Constant Summary

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

#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions

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

#ai_commandObject

Returns the value of attribute ai_command.



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

def ai_command
  @ai_command
end

#ai_serviceObject

Returns the value of attribute ai_service.



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

def ai_service
  @ai_service
end

#answerObject

Returns the value of attribute answer.



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

def answer
  @answer
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#determine_ai_commandObject



35
36
37
# File 'foobara-ai-0.0.11/src/foobara/ai/answer_bot/ask.rb', line 35

def determine_ai_command
  self.ai_command = Foobara::Ai::AnswerBot::DomainMappers::ServiceToChatCompletionCommand.map!(ai_service)
end

#determine_ai_serviceObject



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

def determine_ai_service
  self.ai_service = service || domain_map!(model, from: :model_enum)
end

#executeObject



21
22
23
24
25
26
27
# File 'foobara-ai-0.0.11/src/foobara/ai/answer_bot/ask.rb', line 21

def execute
  determine_ai_service
  determine_ai_command
  run_ai_service

  answer
end

#run_ai_serviceObject



39
40
41
42
43
44
45
46
47
# File 'foobara-ai-0.0.11/src/foobara/ai/answer_bot/ask.rb', line 39

def run_ai_service
  inputs = { question:, model: }

  if instructions
    inputs[:instructions] = instructions
  end

  self.answer = run_mapped_subcommand!(ai_command, inputs)
end