Update openai class naming to avoid conflicts

This commit is contained in:
Zach Gollwitzer
2025-03-24 17:26:46 -04:00
parent 8cca82d360
commit 96d4a1ae1e
24 changed files with 64 additions and 49 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class Provider::OpenAI < Provider
class Provider::Openai < Provider
include Assistant::Provideable
MODELS = %w[gpt-4o]

View File

@@ -34,6 +34,6 @@ module Providers
return nil unless access_token.present?
Provider::OpenAI.new(access_token)
Provider::Openai.new(access_token)
end
end

View File

@@ -1 +1,10 @@
<p>Assistant message</p>
<%# locals: (assistant_message:) %>
<div id="<%= dom_id(assistant_message) %>">
<div class="flex items-start">
<%= render "chats/ai_avatar" %>
<div class="pr-2 max-w-[85%] text-primary">
<div class="prose prose-sm prose-gray break-words"><%= markdown(assistant_message.content) %></div>
</div>
</div>
</div>

View File

@@ -1,3 +1,3 @@
<div class="w-16 h-16 flex-shrink-0 -ml-3 -mt-3">
<%= image_tag "ai.svg", alt: "AI", class: "w-full h-full" %>
</div>
</div>

View File

@@ -30,4 +30,4 @@
<% end %>
<% end %>
</div>
</div>
</div>

View File

@@ -2,7 +2,7 @@
<%= render "chats/ai_avatar" %>
<div class="max-w-[85%] text-sm space-y-4 text-primary">
<p>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.</p>
<p>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.</p>
<p>
You can use <span class="bg-white border border-gray-200 px-1.5 py-0.5 rounded font-mono text-xs">/</span> 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 @@
<div class="space-y-2.5">
<% questions.each do |question| %>
<button data-action="chat#submitSampleQuestion"
data-chat-question-param="<%= question[:text] %>"
<button data-action="chat#submitSampleQuestion"
data-chat-question-param="<%= question[:text] %>"
class="w-full flex items-center gap-2 border border-tertiary rounded-full py-1.5 px-2.5 hover:bg-gray-100">
<%= icon(question[:icon]) %> <%= question[:text] %>
</button>
@@ -37,4 +37,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -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 %>
<% end %>

View File

@@ -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 %>
</nav>
</nav>

View File

@@ -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 %>
<% end %>

View File

@@ -28,4 +28,4 @@
<%= render "messages/chat_form" %>
</div>
<% end %>
<% end %>

View File

@@ -8,4 +8,4 @@
<%= render "messages/chat_form", chat: @chat %>
</div>
<% end %>
<% end %>

View File

@@ -12,11 +12,11 @@
<div class="p-4 space-y-6">
<% if @chat.conversation_messages.any? %>
<% @chat.conversation_messages.each do |message| %>
<%= render "messages/message", message: message %>
<%= render message %>
<% end %>
<% else %>
<div class="mt-auto">
<%= render "chats/ai_greeting", context: 'chat' %>
<%= render "chats/ai_greeting", context: "chat" %>
</div>
<% end %>
</div>
@@ -26,4 +26,4 @@
<%= render "messages/chat_form", chat: @chat %>
</div>
</div>
<% end %>
<% end %>

View File

@@ -1 +1,9 @@
<p>Developer message</p>
<%# locals: (developer_message:) %>
<div id="<%= dom_id(developer_message) %>">
<div class="flex items-start">
<div class="pr-2 max-w-[85%] text-primary">
<div class="prose prose-sm prose-gray break-words"><%= markdown(developer_message.content) %></div>
</div>
</div>
</div>

View File

@@ -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 %>
</div>
<% end %>

View File

@@ -22,7 +22,7 @@
<% end %>
<% end %>
</div>
<div class="ml-auto">
<button data-action="sidebar#toggle" data-side="right" class="p-2 inline-flex rounded-lg items-center justify-center hover:bg-gray-100 cursor-pointer" title="Toggle AI Assistant">
<%= icon("panel-right", color: "gray") %>

View File

@@ -3,7 +3,7 @@
<div id="chat-form" class="space-y-2">
<% model = chat && chat.persisted? ? [chat, Message.new] : Chat.new %>
<%= form_with model: model,
<%= form_with model: model,
class: "flex flex-col gap-2 bg-white px-2 py-1.5 rounded-lg shadow-border-xs",
data: { chat_target: "form" } do |f| %>
@@ -32,4 +32,4 @@
<% end %>
<p class="text-xs text-secondary">AI responses are informational only and are not financial advice.</p>
</div>
</div>

View File

@@ -6,7 +6,7 @@
<div class="font-semibold"><%= content.split("\n").first %></div>
</div>
<% 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
%>
%>
<div class="mt-2 overflow-x-auto">
<pre class="text-xs"><%= formatted_json %></pre>
</div>
<% end %>
</div>
</div>

View File

@@ -1,10 +0,0 @@
<%# locals: (message:) %>
<div id="<%= dom_id(message) %>">
<div class="flex items-start">
<%= render "chats/ai_avatar" %>
<div class="pr-2 max-w-[85%] text-primary">
<div class="prose prose-sm prose-gray break-words"><%= markdown(message.content) %></div>
</div>
</div>
</div>

View File

@@ -3,4 +3,4 @@
<div id="thinking-message" class="flex items-start">
<%= render "chats/ai_avatar" %>
<p class="text-sm text-secondary animate-pulse"><%= message %></p>
</div>
</div>

View File

@@ -1,3 +1,3 @@
<%= turbo_stream.replace "chat-form" do %>
<%= render "messages/chat_form", chat: @chat %>
<% end %>
<% end %>

View File

@@ -1 +1,9 @@
<p>User message</p>
<%# locals: (user_message:) %>
<div id="<%= dom_id(user_message) %>">
<div class="flex items-start">
<div class="pr-2 max-w-[85%] text-primary">
<div class="prose prose-sm prose-gray break-words"><%= markdown(user_message.content) %></div>
</div>
</div>
</div>

View File

@@ -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

View File

@@ -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