Class: Plain::MessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plain/messages_controller.rb

Constant Summary collapse

PER_PAGE =
10

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
# File 'app/controllers/plain/messages_controller.rb', line 21

def create
  @conversation = Plain::Conversation.find(params[:conversation_id])
  @question = params[:message][:content]
  @conversation.messages.create(role: "user", content: @question)
  @conversation.add_assistant_response_async(@question)
end

#indexObject



9
10
11
12
13
14
# File 'app/controllers/plain/messages_controller.rb', line 9

def index
  @conversation = Plain::Conversation.find(params[:conversation_id])
  @current_page = params[:page].to_i
  @next_page = @current_page + 1
  @messages = @conversation.messages.limit(PER_PAGE).offset(@current_page * PER_PAGE).order(created_at: :desc)
end

#newObject



16
17
18
19
# File 'app/controllers/plain/messages_controller.rb', line 16

def new
  @conversation = Plain::Conversation.find(params[:conversation_id])
  @message = @conversation.messages.new
end