Skip to content

Commit 12ef3b6

Browse files
wip
1 parent 82e6680 commit 12ef3b6

File tree

14 files changed

+383
-224
lines changed

14 files changed

+383
-224
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
# rspec failure tracking
1111
.rspec_status
12+
.DS_Store

lib/langchainrb_rails/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
6 KB
Binary file not shown.

lib/langchainrb_rails/generators/langchainrb_rails/assistant_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def create_view_files
5959
template "assistant/views/_message.html.erb", "app/views/assistants/_message.html.erb"
6060
template "assistant/views/_message_form.html.erb", "app/views/assistants/_message_form.html.erb"
6161
template "assistant/views/chat.turbo_stream.erb", "app/views/assistants/chat.turbo_stream.erb"
62+
template "assistant/views/edit.html.erb", "app/views/assistants/edit.html.erb"
6263
template "assistant/views/index.html.erb", "app/views/assistants/index.html.erb"
6364
template "assistant/views/new.html.erb", "app/views/assistants/new.html.erb"
6465
template "assistant/views/show.html.erb", "app/views/assistants/show.html.erb"
Binary file not shown.
Binary file not shown.

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/controllers/assistants_controller.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
class AssistantsController < ApplicationController
4+
before_action :set_assistant, only: [:show, :edit, :update, :chat, :destroy]
5+
46
def index
57
@assistants = Assistant.all
68
end
@@ -19,11 +21,23 @@ def create
1921
end
2022

2123
def show
24+
@assistants = Assistant.all
2225
@assistant = Assistant.find(params[:id])
2326
@messages = @assistant.messages
2427
@message = Message.new
2528
end
2629

30+
def edit
31+
end
32+
33+
def update
34+
if @assistant.update(assistant_params)
35+
redirect_to @assistant, notice: 'Assistant was successfully updated.'
36+
else
37+
render :edit
38+
end
39+
end
40+
2741
def chat
2842
@assistant = Assistant.find(params[:id])
2943
@message = @assistant.messages.create(role: "user", content: params[:message][:content])
@@ -39,11 +53,18 @@ def chat
3953
end
4054
end
4155

56+
def destroy
57+
@assistant.destroy
58+
redirect_to assistants_path, notice: 'Assistant was successfully deleted.'
59+
end
60+
4261
private
4362

63+
def set_assistant
64+
@assistant = Assistant.find(params[:id])
65+
end
66+
4467
def assistant_params
45-
params
46-
.require(:assistant)
47-
.permit(:name, :instructions, :tool_choice)
68+
params.require(:assistant).permit(:name, :instructions, :tool_choice)
4869
end
4970
end

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/models/assistant.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class Assistant < ActiveRecord::Base
4-
has_many :messages
4+
has_many :messages, dependent: :destroy
55

66
validates :name, presence: true
77

0 commit comments

Comments
 (0)