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

Assistants redirect to settings if no token yet #566

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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
2 changes: 1 addition & 1 deletion test/controllers/settings/api_services_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Settings::APIServicesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get settings_api_services_url
assert_response :success
assert_select "table#api-services tbody tr", count: 4
assert_select "table#api-services tbody tr", count: 5
assert_select "p a", "Add New"
assert_select "p#no-api-services", false
end
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
Loading