Simplify and clean up "thinking" interactions with Turbo frames

This commit is contained in:
Zach Gollwitzer
2025-03-26 12:22:08 -04:00
parent 866bcdaa07
commit 32df8661cc
10 changed files with 12 additions and 32 deletions

View File

@@ -21,11 +21,7 @@ class ChatsController < ApplicationController
def create
@chat = Current.user.chats.start!(chat_params[:content], model: chat_params[:ai_model])
set_last_viewed_chat(@chat)
respond_to do |format|
format.html { redirect_to chat_path(@chat) }
format.turbo_stream
end
redirect_to chat_path(@chat, thinking: true)
end
def edit
@@ -49,14 +45,7 @@ class ChatsController < ApplicationController
def retry
@chat.retry_last_message!
respond_to do |format|
format.html { redirect_to chat_path(@chat) }
format.turbo_stream { render turbo_stream: [
turbo_stream.append("messages", partial: "chats/thinking_indicator", locals: { chat: @chat }),
turbo_stream.remove("chat-error")
] }
end
redirect_to chat_path(@chat, thinking: true)
end
private

View File

@@ -10,10 +10,7 @@ class MessagesController < ApplicationController
ai_model: message_params[:ai_model]
)
respond_to do |format|
format.html { redirect_to chat_path(@chat) }
format.turbo_stream
end
redirect_to chat_path(@chat, thinking: true)
end
private

View File

@@ -13,5 +13,5 @@ class Account::Transaction < ApplicationRecord
def search(params)
Account::TransactionSearch.new(params).build_query(all)
end
end
end
end

View File

@@ -16,4 +16,4 @@
</div>
<% end %>
</div>
</details>
</details>

View File

@@ -14,4 +14,4 @@
<span>Retry</span>
<% end %>
</div>
</div>
</div>

View File

@@ -1,5 +0,0 @@
<%= turbo_stream.replace "chat-form" do %>
<%= render "messages/chat_form", chat: @chat %>
<% end %>
<%= turbo_stream.append "messages", partial: "chats/thinking_indicator", locals: { chat: @chat } %>

View File

@@ -19,6 +19,10 @@
</div>
<% end %>
<% if params[:thinking].present? %>
<%= render "chats/thinking_indicator", chat: @chat %>
<% end %>
<% if @chat.error.present? %>
<%= render "chats/error", chat: @chat %>
<% end %>

View File

@@ -1,6 +1,6 @@
<%# locals: (developer_message:) %>
<div id="<%= dom_id(developer_message) %>" class="my-2 <%= developer_message.debug? ? 'bg-yellow-50 border-yellow-200' : 'bg-blue-50 border-blue-200' %> px-3 py-2 rounded-lg max-w-[85%] ml-auto border">
<div id="<%= dom_id(developer_message) %>" class="my-2 <%= developer_message.debug? ? "bg-yellow-50 border-yellow-200" : "bg-blue-50 border-blue-200" %> px-3 py-2 rounded-lg max-w-[85%] ml-auto border">
<span class="text-secondary text-xs"><%= developer_message.debug? ? "Debug message (internal only)" : "System instruction (sent to AI)" %></span>
<p class="text-primary text-sm"><%= developer_message.content %></p>
</div>

View File

@@ -1,5 +0,0 @@
<%= turbo_stream.replace "chat-form" do %>
<%= render "messages/chat_form", chat: @chat %>
<% end %>
<%= turbo_stream.append "messages", partial: "chats/thinking_indicator", locals: { chat: @chat } %>

View File

@@ -16,7 +16,7 @@ class ChatTest < ActiveSupport::TestCase
test "user sees assistant and user messages in normal mode" do
chat = chats(:one)
assert_equal 3, chat.conversation_messages.count
end
end
test "creates with initial message" do
prompt = "Test prompt"