Skip to content

Commit c7d1a64

Browse files
enhancements
1 parent 4c1f0ce commit c7d1a64

File tree

10 files changed

+40
-5
lines changed

10 files changed

+40
-5
lines changed

lib/langchainrb_rails/generators/langchainrb_rails/assistant_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def add_routes
7474
EOS
7575
end
7676

77+
# TODO: Copy stylesheet into app/assets/stylesheets or whatever the host app uses
7778
def copy_stylesheets
7879
template "assistant/stylesheets/chat.css", "app/assets/stylesheets/chat.css"
7980
end

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def chat
4242
private
4343

4444
def assistant_params
45-
params.require(:assistant).permit(:instructions, :tool_choice)
45+
params
46+
.require(:assistant)
47+
.permit(:name, :instructions, :tool_choice)
4648
end
4749
end

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/migrations/create_assistants.rb.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
22
def change
33
create_table :assistants do |t|
4+
t.string :name, null: false
45
t.string :instructions
56
t.string :tool_choice
67
t.json :tools, default: []

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/migrations/create_messages.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
22
def change
33
create_table :messages do |t|
44
t.references :assistant, foreign_key: true
5-
t.string :role
5+
t.string :role, null: false
66
t.text :content
77
t.json :tool_calls, default: []
88
t.string :tool_call_id

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
class Assistant < ActiveRecord::Base
44
has_many :messages
55

6+
validates :name, presence: true
7+
8+
# TODO: Validate tool_choice
9+
610
def llm
711
<%= llm_class %>.new(api_key: ENV["<%= llm.upcase %>_API_KEY"])
812
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
class Message < ActiveRecord::Base
44
belongs_to :assistant
5+
6+
validates :role, presence: true
57
end

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/stylesheets/chat.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,22 @@
249249
.chat-container {
250250
font-family: Arial, sans-serif;
251251
}
252+
253+
.chat-instructions {
254+
font-style: italic;
255+
color: #666;
256+
margin-bottom: 20px;
257+
}
258+
259+
.form-group input[type="text"] {
260+
width: 100%;
261+
padding: 10px;
262+
border: 1px solid #ccc;
263+
border-radius: 4px;
264+
font-size: 16px;
265+
}
266+
267+
.form-group input[type="text"]:focus {
268+
outline: none;
269+
border-color: #007bff;
270+
}

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/views/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ul class="assistant-list">
77
<%% @assistants.each do |assistant| %>
88
<li class="assistant-item">
9-
<%%= link_to assistant.instructions, assistant_path(assistant), class: "assistant-link" %>
9+
<%%= link_to assistant.name, assistant_path(assistant), class: "assistant-link" %>
1010
</li>
1111
<%% end %>
1212
</ul>

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/views/new.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="assistant-form-container">
22
<h1 class="form-header">Create New Assistant</h1>
33

4-
<%%= form_with(model: @assistant, local: true, class: "assistant-form") do |form| %>
4+
<%%= form_with(model: @assistant, local: true, class: "assistant-form", data: { turbo: false }) do |form| %>
55
<%% if @assistant.errors.any? %>
66
<div class="error-messages">
77
<h2><%%= pluralize(@assistant.errors.count, "error") %> prohibited this assistant from being saved:</h2>
@@ -13,6 +13,11 @@
1313
</div>
1414
<%% end %>
1515

16+
<div class="form-group">
17+
<%%= form.label :name, "Assistant Name" %>
18+
<%%= form.text_field :name, placeholder: "Enter assistant name..." %>
19+
</div>
20+
1621
<div class="form-group">
1722
<%%= form.label :instructions, "Instructions for the Assistant" %>
1823
<%%= form.text_area :instructions, rows: 5, placeholder: "Enter instructions for the assistant..." %>

lib/langchainrb_rails/generators/langchainrb_rails/templates/assistant/views/show.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="chat-container">
2-
<h1 class="chat-header">Assistant: <%%= @assistant.id %></h1>
2+
<h1 class="chat-header"><%%= @assistant.name %></h1>
3+
<p class="chat-instructions"><%%= @assistant.instructions %></p>
34

45
<div id="chat-messages" class="chat-messages">
56
<%%= render partial: "assistants/message", collection: @messages %>

0 commit comments

Comments
 (0)