Class: Layered::Assistant::ConversationsController

Inherits:
ApplicationController show all
Includes:
StoppableResponse
Defined in:
app/controllers/layered/assistant/conversations_controller.rb

Instance Method Summary collapse

Methods included from StoppableResponse

#stop

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 32

def create
  @conversation = Conversation.new(conversation_params)
  @conversation.owner = l_ui_current_user
  @conversation.assistant = scoped(Assistant).find(conversation_params[:assistant_id]) if conversation_params[:assistant_id].present?
  @conversation.name = Conversation.default_name if @conversation.name.blank?
  if @conversation.save
    redirect_to layered_assistant.conversation_path(@conversation), notice: "Conversation was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



56
57
58
59
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 56

def destroy
  @conversation.destroy
  redirect_to layered_assistant.conversations_path, notice: "Conversation was successfully deleted."
end

#editObject



44
45
46
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 44

def edit
  @page_title = "Edit conversation"
end

#indexObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 9

def index
  if params[:assistant_id]
    @assistant = scoped(Assistant).find(params[:assistant_id])
    @page_title = "Conversations - #{@assistant.name}"
    @pagy, @conversations = pagy(@assistant.conversations.merge(scoped(Conversation)).includes(:owner).by_created_at)
  else
    @page_title = "Conversations"
    @pagy, @conversations = pagy(scoped(Conversation).includes(:assistant, :owner).by_created_at)
  end
end

#newObject



27
28
29
30
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 27

def new
  @page_title = "New conversation"
  @conversation = Conversation.new(params.permit(conversation: [:assistant_id])[:conversation])
end

#showObject



20
21
22
23
24
25
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 20

def show
  @page_title = @conversation.name
  @messages = @conversation.messages.includes(:model).by_created_at
  @models = Model.available
  @selected_model_id = @messages.last&.model_id || @conversation.assistant.default_model_id || @models.first&.id
end

#updateObject



48
49
50
51
52
53
54
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 48

def update
  if @conversation.update(conversation_params)
    redirect_to layered_assistant.conversations_path, notice: "Conversation was successfully updated."
  else
    render :edit, status: :unprocessable_entity
  end
end