Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import assistant #61

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/assistants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def edit; end

# POST /assistants or /assistants.json
def create
@assistant = Assistant.new(assistant_params)
json = JSON.parse(params[:json])
@assistant = Assistant.new(json || assistant_params)

authorize @assistant

Expand Down
5 changes: 5 additions & 0 deletions app/models/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Assistant < ApplicationRecord

validate :libraries_must_be_csv_with_numbers

# Override as_json to exclude specific fields
def as_json(options = {})
super(options.merge({ except: %i[created_at updated_at id user_prompt llm_prompt] }))
end

private

def libraries_must_be_csv_with_numbers
Expand Down
71 changes: 37 additions & 34 deletions app/views/assistants/_assistant.html.erb
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
<div id="<%= dom_id assistant %>" class="w-full">
<% cache assistant do %>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Description</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="5" disabled><%= assistant.description %></textarea>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Quip URL</strong>
<p class="text-gray-700"><%= assistant.quip_url %></p>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Confluence Spaces</strong>
<p class="text-gray-700"><%= assistant.confluence_spaces %></p>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Libraries</strong>
<p class="text-gray-700"><%= assistant.libraries %></p>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Input</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="5" disabled><%= assistant.input %></textarea>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Output</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="5" disabled><%= assistant.output %></textarea>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Instructions</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="5" disabled><%= assistant.instructions %></textarea>
</div>
<div class="my-5">
<strong class="block text-xl font-semibold text-gray-800 mb-2">Context</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="5" disabled><%= assistant.context %></textarea>
</div>
<% end %>
<!-- User Prompt -->
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Description</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.description %></textarea>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Quip URL</strong>
<p class="text-gray-700"><%= assistant.quip_url %></p>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Confluence Spaces</strong>
<p class="text-gray-700"><%= assistant.confluence_spaces %></p>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Libraries</strong>
<p class="text-gray-700"><%= assistant.libraries %></p>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Input</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.input %></textarea>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Output</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.output %></textarea>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Instructions</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.instructions %></textarea>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">Context</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.context %></textarea>
</div>
<div class="my-5">
<strong class="block text-lg font-semibold text-gray-800 mb-2">JSON</strong>
<textarea class="w-full p-3 border border-gray-300 rounded-lg bg-gray-100 text-gray-700" rows="10" disabled><%= assistant.to_json %></textarea>
</div>
</div>
4 changes: 4 additions & 0 deletions app/views/assistants/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<%= form.label :context %>
<%= form.text_area :context, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= label_tag :json %>
<%= text_area_tag :json, nil, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="inline">
<%= form.submit "Save", class: "rounded-lg py-3 px-5 bg-sky-600 text-white inline-block font-medium cursor-pointer" %>
</div>
Expand Down
10 changes: 10 additions & 0 deletions app/views/assistants/import.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render 'shared/page_header', title: 'Import Assistants', subtitle: 'Paste the JSON copied from another Assistant.' %>
<%= form_tag assistants_path, method: :post, class: "contents" do %>
<div class="my-5">
<%= label_tag :json %>
<%= text_area_tag :json, nil, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="inline">
<%= submit_tag "Import", class: "rounded-lg py-3 px-5 bg-sky-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/assistants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<%= render 'shared/page_header', title: 'Assistants', subtitle: 'Assistants have special instructions and context to answer specific problems better than general Q/A. Click "Chat" to begin!' %>
<% if policy(Assistant.new).edit? %>
<%= link_to "New +", new_assistant_path, class: "rounded-lg py-3 px-5 bg-sky-900 text-white block font-medium" %>
<%= link_to "Import", import_assistants_path, class: "rounded-lg py-3 px-5 bg-sky-900 text-white block font-medium" %>
<% end %>
</div>
<div id="assistants" class="mt-5 space-y-4">
Expand Down
8 changes: 6 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

Rails.application.routes.draw do
resources :messages
resources :chats do
resources :messages
end
resources :assistants do
resources :chats, only: %i[create new]

# Adding the import route for all assistants
collection do
post 'import'
get 'import'
end
end

# Auth routes
Expand Down
Loading