From 96d4a1ae1ef3eee196d13162210331a9bd1e6ff8 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 24 Mar 2025 17:26:46 -0400 Subject: [PATCH] Update openai class naming to avoid conflicts --- app/models/provider/openAI/chat_response.rb | 2 +- app/models/provider/openai.rb | 2 +- app/models/providers.rb | 2 +- .../assistant_messages/_assistant_message.html.erb | 11 ++++++++++- app/views/chats/_ai_avatar.html.erb | 2 +- app/views/chats/_ai_consent.html.erb | 2 +- app/views/chats/_ai_greeting.html.erb | 10 +++++----- app/views/chats/_chat.html.erb | 2 +- app/views/chats/_chat_nav.html.erb | 2 +- app/views/chats/edit.html.erb | 6 +++--- app/views/chats/index.html.erb | 2 +- app/views/chats/new.html.erb | 2 +- app/views/chats/show.html.erb | 6 +++--- .../developer_messages/_developer_message.html.erb | 10 +++++++++- app/views/layouts/application.html.erb | 8 ++++---- app/views/layouts/shared/_breadcrumbs.html.erb | 2 +- app/views/messages/_chat_form.html.erb | 4 ++-- app/views/messages/_debug_message.html.erb | 6 +++--- app/views/messages/_message.html.erb | 10 ---------- app/views/messages/_thinking_message.html.erb | 2 +- app/views/messages/create.turbo_stream.erb | 2 +- app/views/user_messages/_user_message.html.erb | 10 +++++++++- config/routes.rb | 4 ++-- test/models/provider/openai_test.rb | 4 ++-- 24 files changed, 64 insertions(+), 49 deletions(-) delete mode 100644 app/views/messages/_message.html.erb diff --git a/app/models/provider/openAI/chat_response.rb b/app/models/provider/openAI/chat_response.rb index ce64a643..7734a4bd 100644 --- a/app/models/provider/openAI/chat_response.rb +++ b/app/models/provider/openAI/chat_response.rb @@ -1,4 +1,4 @@ -class Provider::OpenAI::ChatResponse +class Provider::Openai::ChatResponse def initialize(client:, model:, chat_history:, instructions: nil, available_functions: []) @client = client @model = model diff --git a/app/models/provider/openai.rb b/app/models/provider/openai.rb index 58d839a3..e89ceb2d 100644 --- a/app/models/provider/openai.rb +++ b/app/models/provider/openai.rb @@ -1,4 +1,4 @@ -class Provider::OpenAI < Provider +class Provider::Openai < Provider include Assistant::Provideable MODELS = %w[gpt-4o] diff --git a/app/models/providers.rb b/app/models/providers.rb index b27ba7dc..e775e9a4 100644 --- a/app/models/providers.rb +++ b/app/models/providers.rb @@ -34,6 +34,6 @@ module Providers return nil unless access_token.present? - Provider::OpenAI.new(access_token) + Provider::Openai.new(access_token) end end diff --git a/app/views/assistant_messages/_assistant_message.html.erb b/app/views/assistant_messages/_assistant_message.html.erb index 6f059204..2be153a9 100644 --- a/app/views/assistant_messages/_assistant_message.html.erb +++ b/app/views/assistant_messages/_assistant_message.html.erb @@ -1 +1,10 @@ -

Assistant message

\ No newline at end of file +<%# locals: (assistant_message:) %> + +
+
+ <%= render "chats/ai_avatar" %> +
+
<%= markdown(assistant_message.content) %>
+
+
+
diff --git a/app/views/chats/_ai_avatar.html.erb b/app/views/chats/_ai_avatar.html.erb index 9124fc3b..82cc8007 100644 --- a/app/views/chats/_ai_avatar.html.erb +++ b/app/views/chats/_ai_avatar.html.erb @@ -1,3 +1,3 @@
<%= image_tag "ai.svg", alt: "AI", class: "w-full h-full" %> -
\ No newline at end of file + diff --git a/app/views/chats/_ai_consent.html.erb b/app/views/chats/_ai_consent.html.erb index 70ffe01d..1fc2c722 100644 --- a/app/views/chats/_ai_consent.html.erb +++ b/app/views/chats/_ai_consent.html.erb @@ -30,4 +30,4 @@ <% end %> <% end %> - \ No newline at end of file + diff --git a/app/views/chats/_ai_greeting.html.erb b/app/views/chats/_ai_greeting.html.erb index f4f06b24..688cfd3a 100644 --- a/app/views/chats/_ai_greeting.html.erb +++ b/app/views/chats/_ai_greeting.html.erb @@ -2,7 +2,7 @@ <%= render "chats/ai_avatar" %>
-

Hey <%= Current.user&.first_name || 'there' %>! I'm an AI built by Maybe to help with your finances. I have access to the web and your account data.

+

Hey <%= Current.user&.first_name || "there" %>! I'm an AI built by Maybe to help with your finances. I have access to the web and your account data.

You can use / to access commands @@ -17,7 +17,7 @@ text: "Evaluate investment portfolio" }, { - icon: "credit-card", + icon: "credit-card", text: "Show spending insights" }, { @@ -28,8 +28,8 @@

<% questions.each do |question| %> - @@ -37,4 +37,4 @@
- \ No newline at end of file + diff --git a/app/views/chats/_chat.html.erb b/app/views/chats/_chat.html.erb index dd01840d..aa0a915b 100644 --- a/app/views/chats/_chat.html.erb +++ b/app/views/chats/_chat.html.erb @@ -13,4 +13,4 @@ <%= contextual_menu_item("Edit chat", url: edit_chat_path(chat), icon: "pencil", turbo_frame: dom_id(chat, :title)) %> <%= contextual_menu_destructive_item("Delete chat", chat_path(chat)) %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/chats/_chat_nav.html.erb b/app/views/chats/_chat_nav.html.erb index a2b0954e..fda09856 100644 --- a/app/views/chats/_chat_nav.html.erb +++ b/app/views/chats/_chat_nav.html.erb @@ -21,4 +21,4 @@ <%= contextual_menu_destructive_item "Delete chat", chat_path(chat), turbo_confirm: "Are you sure you want to delete this chat?" %> <% end %> <% end %> - \ No newline at end of file + diff --git a/app/views/chats/edit.html.erb b/app/views/chats/edit.html.erb index 1ad488af..0c165ec5 100644 --- a/app/views/chats/edit.html.erb +++ b/app/views/chats/edit.html.erb @@ -1,8 +1,8 @@ <%= turbo_frame_tag dom_id(@chat, :title), class: "block" do %> <% bg_class = params[:ctx] == "chat" ? "bg-white" : "bg-container-inset" %> - <%= styled_form_with model: @chat, - class: class_names("p-1 rounded-md font-medium text-primary w-full", bg_class), + <%= styled_form_with model: @chat, + class: class_names("p-1 rounded-md font-medium text-primary w-full", bg_class), data: { controller: "auto-submit-form", auto_submit_form_trigger_event_value: "blur" } do |f| %> <%= f.text_field :title, data: { auto_submit_form_target: "auto" }, inline: true %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/chats/index.html.erb b/app/views/chats/index.html.erb index 08b9723d..bdb16b9d 100644 --- a/app/views/chats/index.html.erb +++ b/app/views/chats/index.html.erb @@ -28,4 +28,4 @@ <%= render "messages/chat_form" %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/chats/new.html.erb b/app/views/chats/new.html.erb index f96e879f..4a00ceec 100644 --- a/app/views/chats/new.html.erb +++ b/app/views/chats/new.html.erb @@ -8,4 +8,4 @@ <%= render "messages/chat_form", chat: @chat %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/chats/show.html.erb b/app/views/chats/show.html.erb index e3ea3604..dc82263e 100644 --- a/app/views/chats/show.html.erb +++ b/app/views/chats/show.html.erb @@ -12,11 +12,11 @@
<% if @chat.conversation_messages.any? %> <% @chat.conversation_messages.each do |message| %> - <%= render "messages/message", message: message %> + <%= render message %> <% end %> <% else %>
- <%= render "chats/ai_greeting", context: 'chat' %> + <%= render "chats/ai_greeting", context: "chat" %>
<% end %>
@@ -26,4 +26,4 @@ <%= render "messages/chat_form", chat: @chat %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/developer_messages/_developer_message.html.erb b/app/views/developer_messages/_developer_message.html.erb index c95ae5c8..73a93287 100644 --- a/app/views/developer_messages/_developer_message.html.erb +++ b/app/views/developer_messages/_developer_message.html.erb @@ -1 +1,9 @@ -

Developer message

\ No newline at end of file +<%# locals: (developer_message:) %> + +
+
+
+
<%= markdown(developer_message.content) %>
+
+
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 923c3bb9..5f6ca668 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -36,7 +36,7 @@ <% end %> <% end %> - <% + <% left_sidebar_open = Current.user.show_sidebar? right_sidebar_open = Current.user.show_ai_sidebar? content_width_class = if left_sidebar_open && right_sidebar_open @@ -71,8 +71,8 @@ <% end %> <%# AI chat sidebar %> - <%= tag.div id: "chat-container", - class: class_names("flex flex-col justify-between shrink-0 transition-all duration-300", right_sidebar_open ? "w-[400px]" : "w-0"), + <%= tag.div id: "chat-container", + class: class_names("flex flex-col justify-between shrink-0 transition-all duration-300", right_sidebar_open ? "w-[400px]" : "w-0"), data: { controller: "chat hotkey", sidebar_target: "rightPanel", turbo_permanent: true } do %> <% if Current.user.ai_enabled? %> @@ -83,7 +83,7 @@ <% end %> <% else %> <%= render "chats/ai_consent" %> - <% end%> + <% end %> <% end %> <% end %> diff --git a/app/views/layouts/shared/_breadcrumbs.html.erb b/app/views/layouts/shared/_breadcrumbs.html.erb index 4c6d4a4f..d02ba36c 100644 --- a/app/views/layouts/shared/_breadcrumbs.html.erb +++ b/app/views/layouts/shared/_breadcrumbs.html.erb @@ -22,7 +22,7 @@ <% end %> <% end %> - +
diff --git a/app/views/messages/_debug_message.html.erb b/app/views/messages/_debug_message.html.erb index 90af380b..d5ef41da 100644 --- a/app/views/messages/_debug_message.html.erb +++ b/app/views/messages/_debug_message.html.erb @@ -6,7 +6,7 @@
<%= content.split("\n").first %>
<% if content.include?("```json") %> - <% + <% json_start = content.index("```json") json_end = content.index("```", json_start + 7) if json_start && json_end @@ -18,9 +18,9 @@ formatted_json = json_content end end - %> + %>
<%= formatted_json %>
<% end %> - \ No newline at end of file + diff --git a/app/views/messages/_message.html.erb b/app/views/messages/_message.html.erb deleted file mode 100644 index 399d3d4c..00000000 --- a/app/views/messages/_message.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%# locals: (message:) %> - -
-
- <%= render "chats/ai_avatar" %> -
-
<%= markdown(message.content) %>
-
-
-
\ No newline at end of file diff --git a/app/views/messages/_thinking_message.html.erb b/app/views/messages/_thinking_message.html.erb index d3047391..8ade76a0 100644 --- a/app/views/messages/_thinking_message.html.erb +++ b/app/views/messages/_thinking_message.html.erb @@ -3,4 +3,4 @@
<%= render "chats/ai_avatar" %>

<%= message %>

-
\ No newline at end of file + diff --git a/app/views/messages/create.turbo_stream.erb b/app/views/messages/create.turbo_stream.erb index baa7b57c..f834bbfb 100644 --- a/app/views/messages/create.turbo_stream.erb +++ b/app/views/messages/create.turbo_stream.erb @@ -1,3 +1,3 @@ <%= turbo_stream.replace "chat-form" do %> <%= render "messages/chat_form", chat: @chat %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/user_messages/_user_message.html.erb b/app/views/user_messages/_user_message.html.erb index 3974bd13..6a842f3d 100644 --- a/app/views/user_messages/_user_message.html.erb +++ b/app/views/user_messages/_user_message.html.erb @@ -1 +1,9 @@ -

User message

\ No newline at end of file +<%# locals: (user_message:) %> + +
+
+
+
<%= markdown(user_message.content) %>
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index 37e113ff..150882a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,8 +11,8 @@ Rails.application.routes.draw do # Uses basic auth - see config/initializers/sidekiq.rb mount Sidekiq::Web => "/sidekiq" - # AI chats - resources :chats do + # AI chats + resources :chats do resources :messages, only: :create end diff --git a/test/models/provider/openai_test.rb b/test/models/provider/openai_test.rb index dbe1bf43..9215b2c0 100644 --- a/test/models/provider/openai_test.rb +++ b/test/models/provider/openai_test.rb @@ -1,10 +1,10 @@ require "test_helper" -class Provider::OpenAITest < ActiveSupport::TestCase +class Provider::OpenaiTest < ActiveSupport::TestCase include LLMInterfaceTest setup do - @subject = @openai = Provider::OpenAI.new(ENV.fetch("OPENAI_ACCESS_TOKEN")) + @subject = @openai = Provider::Openai.new(ENV.fetch("OPENAI_ACCESS_TOKEN")) @subject_model = "gpt-4o" end