Class: Glancer::ChatsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Glancer::ChatsController
- Defined in:
- app/controllers/glancer/chats_controller.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#destroy ⇒ Object
44 45 46 47 |
# File 'app/controllers/glancer/chats_controller.rb', line 44 def destroy Glancer::Chat.find(params[:id]).destroy! redirect_to glancer.root_path end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/glancer/chats_controller.rb', line 8 def index @chats = Glancer::Chat.order(created_at: :desc) @chat = nil end |
#show ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/controllers/glancer/chats_controller.rb', line 13 def show @chat = Glancer::Chat.find_by(id: params[:id]) return redirect_to(glancer.root_path, alert: "Chat not found") unless @chat @chats = Glancer::Chat.order(created_at: :desc) @messages = @chat..order(:created_at) end |
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/glancer/chats_controller.rb', line 21 def start content = params[:content].to_s.strip return render(json: { error: "Message required" }, status: :unprocessable_entity) if content.blank? @chat = Glancer::Chat.create!(title: "New Chat") @message = @chat..create!(role: :user, content: content) @response_message = @chat..create!( role: :assistant, content: "", code_type: "sql", user_message: @message, status: :processing ) Glancer::AsyncRunner.call(@response_message.id, content) render json: { chat_id: @chat.id } rescue StandardError => e Glancer::Utils::Logger.error("ChatsController#start", e.) render json: { error: e. }, status: :internal_server_error end |