Class: PromptsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PromptsController
- Includes:
- ChatManager::ChatManageable, PromptNavigator::HistoryManageable
- Defined in:
- lib/generators/llm_meta_client/scaffold/templates/app/controllers/prompts_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Leaf-only delete.
- #show ⇒ Object
Instance Method Details
#destroy ⇒ Object
Leaf-only delete. Re-checks leaf status server-side (a branch could have been added after the page rendered) so the tree can never be corrupted.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/llm_meta_client/scaffold/templates/app/controllers/prompts_controller.rb', line 39 def destroy pe = PromptNavigator::PromptExecution.find_by!(execution_id: params[:id]) scope = user_signed_in? ? current_user.chats : Chat.where(user_id: nil) chat = Message.where(prompt_navigator_prompt_execution_id: pe.id).first&.chat unless chat && scope.exists?(id: chat.id) redirect_to(root_path, alert: "Prompt not found.") return end if PromptNavigator::PromptExecution.where(previous_id: pe.id).exists? redirect_to(prompt_path(pe.execution_id), alert: "Cannot delete: this prompt has follow-up branches.") return end ActiveRecord::Base.transaction do Message.where(prompt_navigator_prompt_execution_id: pe.id).delete_all pe.delete end redirect_to chat_path(chat.uuid), notice: "Prompt deleted." rescue ActiveRecord::RecordNotFound redirect_to root_path, alert: "Prompt not found." end |
#show ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/llm_meta_client/scaffold/templates/app/controllers/prompts_controller.rb', line 6 def show @prompt_execution = PromptNavigator::PromptExecution.find_by!(execution_id: params[:id]) @message = Message.where(prompt_navigator_prompt_execution: @prompt_execution).order(:created_at).first @chat = @message.chat @messages = @chat. # Initialize chat context initialize_chat current_user&.chats # Initialize history initialize_history @chat.ordered_by_descending_prompt_executions # Get LLM options available for users jwt_token = current_user.jwt_token if user_signed_in? @llm_families = LlmMetaClient::ServerResource.available_llm_families(jwt_token) # Set the target message ID for scrolling @target_message_id = @message.id # Set active UUID for history sidebar highlighting (@prompt_execution.execution_id) # Set branch_from_uuid so the form knows which message to branch from @branch_from_uuid = @prompt_execution.execution_id render "chats/edit" rescue StandardError => e Rails.logger.error "Error in PromptsController#show_by_uuid: #{e.class} - #{e.}\n#{e.backtrace&.join("\n")}" redirect_to root_path, alert: "Message not found." end |