Class: Mj::ChatGpt::Commands::AskCommandHandler
- Inherits:
-
Object
- Object
- Mj::ChatGpt::Commands::AskCommandHandler
- Defined in:
- lib/mj/chatgpt/commands/ask_command_handler.rb
Instance Method Summary collapse
- #handle(command) ⇒ Object
-
#initialize(client:) ⇒ AskCommandHandler
constructor
A new instance of AskCommandHandler.
Constructor Details
#initialize(client:) ⇒ AskCommandHandler
Returns a new instance of AskCommandHandler.
10 11 12 |
# File 'lib/mj/chatgpt/commands/ask_command_handler.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#handle(command) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/mj/chatgpt/commands/ask_command_handler.rb', line 14 def handle(command) request = Request.from_config_file(command..fetch("config_file")) @client.chat(**request.asking(command.question).to_h) rescue Faraday::Error => exception { error: exception., body: exception.response&.dig(:body, "error") || exception.response } end |