Skip to content

Commit

Permalink
Assistants redirect to settings if no token yet
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Nov 27, 2024
1 parent fc7a482 commit 415f9a7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 32 deletions.
4 changes: 4 additions & 0 deletions app/models/api_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def effective_token
token.presence || default_llm_key
end

def effective_token?
effective_token.present?
end

private

def default_llm_key
Expand Down
76 changes: 45 additions & 31 deletions app/views/assistants/_assistant.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,55 @@
data-role="assistant"
data-radio-behavior-target="radio"
data-action="radio-changed@window->radio-behavior#select"
data-radio-behavior-id-param="<%= assistant.id %>"
data-transition-target="<%= !visible && 'transitionable' %>"
data-radio-behavior-id-param="<%= assistant.id %>"
data-transition-target="<%= !visible && 'transitionable' %>"
>
<%= link_to new_assistant_message_path(assistant), class: "flex-1 flex py-1 items-center text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
<%= render partial: "layouts/assistant_avatar", locals: { assistant: assistant, size: 7, classes: "mr-2" } %>
<%= assistant.name %>
<% end %>
<div class="hidden gap-3 pl-2 relationship:flex group-hover:flex">
<% if settings %>
<div class="inline-flex outline-none dropdown dropdown-end">
<%= icon "ellipsis-horizontal",
tabindex: 0,
role: :button,
variant: :micro,
<% if assistant.api_service.effective_token? %>
<%= link_to new_assistant_message_path(assistant), class: "flex items-center py-1 text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
<div class="relative inline-block w-7 h-7 mr-2">
<%= render partial: "layouts/assistant_avatar", locals: { assistant:, size: 7 } %>
</div>
<%= assistant.name %>
<% end %>
<div class="hidden gap-3 pl-2 relationship:flex group-hover:flex">
<% if settings %>
<div class="inline-flex outline-none dropdown dropdown-end">
<%= icon "ellipsis-horizontal",
tabindex: 0,
role: :button,
variant: :micro,
size: 18,
class: "outline-none text-gray-950 dark:text-gray-100 invisible group-hover:visible cursor-pointer",
data: { controller: "nested-pointer" },
title: "More"
%>
<menu tabindex="0" class="dropdown-content z-10 menu p-2 shadow-xl bg-base-100 rounded-box w-52 -mr-10 mt-7 dark:!bg-gray-700" data-controller="nested-pointer">
<li><%= link_to edit_settings_assistant_path(assistant) do %><%= icon "cog-6-tooth", variant: :outline, size: 18 %>Settings<% end %></li>
<!-- <li><a><%= icon "arrow-up-tray", variant: :outline, size: 18 %>Share</a></li> -->
</menu>
</div>
<% end %>
<%= link_to new_assistant_message_path(assistant), class: "inline-flex", data: { role: "new" } do %>
<%= icon "pencil-square",
variant: :outline,
size: 18,
class: "outline-none text-gray-950 dark:text-gray-100 invisible group-hover:visible cursor-pointer",
'data-controller': "nested-pointer",
title: "More"
class: "text-gray-950 dark:text-gray-100 cursor-pointer group-hover:visible invisible
relationship:visible relationship:text-gray-950 dark:relationship:text-gray-100",
data: { controller: "nested-pointer" },
title: "New"
%>
<menu tabindex="0" class="dropdown-content z-10 menu p-2 shadow-xl bg-base-100 rounded-box w-52 -mr-10 mt-7 dark:!bg-gray-700" data-controller="nested-pointer">
<li><%= link_to edit_settings_assistant_path(assistant) do %><%= icon "cog-6-tooth", variant: :outline, size: 18 %>Settings<% end %></li>
<!-- <li><a><%= icon "arrow-up-tray", variant: :outline, size: 18 %>Share</a></li> -->
</menu>
<% end %>
</div>
<% else %>
<%= link_to edit_settings_api_service_path(assistant.api_service), class: "flex items-center py-1 text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
<div class="relative inline-block w-7 h-7 mr-2">
<%= render partial: "layouts/assistant_avatar", locals: { assistant:, size: 7 } %>
<div class="absolute -bottom-1 right-0 bg-gray-50 dark:bg-gray-900 px-px py-[2px] rounded-full">
<%= icon "lock-closed", variant: :outline, size: 12, class: "text-gray-950 dark:text-gray-100" %>
</div>
</div>
<%= assistant.name %>
<% end %>
<%= link_to new_assistant_message_path(assistant), class: "inline-flex", data: { role: "new" } do %>
<%= icon "pencil-square",
variant: :outline,
size: 18,
class: "text-gray-950 dark:text-gray-100 cursor-pointer group-hover:visible invisible
relationship:visible relationship:text-gray-950 dark:relationship:text-gray-100",
'data-controller': "nested-pointer",
title: "New"
%>
<% end %>
</div>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/_assistant_avatar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ elsif assistant.name.starts_with?("Meta Llama")
end
%>
<% if logo %>
<picture class="<%= classes %> bg-white border border-gray-100 overflow-hidden">
<picture class="<%= classes %> block bg-white border border-gray-100 overflow-hidden">
<%= image_tag(logo, class: "w-full h-full") %>
</picture>
<% else %>
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/api_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ keith_other_service:
token: abc-secret
driver: openai

keith_missing_token_service:
name: Keith Server
user: keith
url: http://test.com/models
driver: openai

rob_openai_service:
name: OpenAI
Expand Down
13 changes: 13 additions & 0 deletions test/system/messages/nav_column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,17 @@ class NavColumnTest < ApplicationSystemTestCase
click_element pencil_on_second_assistant
assert_current_path new_assistant_message_path(assistant2)
end

test "clicking the assistant name redirects to API service settings if token is missing" do
assistant = assistants(:keith_gpt4)
keith_missing_token_service = api_services(:keith_missing_token_service)
assistant.language_model.update! api_service: keith_missing_token_service

conversation_path = conversation_messages_path(conversations(:greeting), version: 1)
visit conversation_path

click_text assistant.name

assert_current_path edit_settings_api_service_path(keith_missing_token_service)
end
end

0 comments on commit 415f9a7

Please sign in to comment.