Class: Askcii::Commands::LastResponseCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/askcii/commands/last_response_command.rb

Overview

Retrieves and displays the last assistant response from the current session

Instance Attribute Summary

Attributes inherited from BaseCommand

#cli, #config

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Askcii::Commands::BaseCommand

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/askcii/commands/last_response_command.rb', line 7

def execute
  verbose "Retrieving last response from session: #{session_context}"

  chat = Chat.find(context: session_context)

  unless chat
    error! "No chat session found for context: #{session_context}"
  end

  last_message = chat.messages_dataset
                    .where(role: 'assistant')
                    .order(Sequel.desc(:created_at))
                    .first

  unless last_message
    error! "No assistant messages found in this session"
  end

  puts last_message.content

  exit 0
end