Skip to content

Commit

Permalink
uses image url for open_ai. allows app_host
Browse files Browse the repository at this point in the history
  • Loading branch information
jlvallelonga committed Oct 29, 2024
1 parent 94f3dec commit c8fa398
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def has_image?(variant = nil)
file.attached?
end

def image_path(variant, fallback: nil)
def image_url(variant, fallback: nil)
return nil unless has_image?

if has_file_variant_processed?(variant)
Expand Down
4 changes: 2 additions & 2 deletions app/models/message/document_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def has_document_image?(variant = nil)
documents.present? && documents.first.has_image?(variant)
end

def document_image_path(variant, fallback: nil)
def document_image_url(variant, fallback: nil)
return nil unless has_document_image?

documents.first.image_path(variant, fallback: fallback)
documents.first.image_url(variant, fallback: fallback)
end
end
2 changes: 1 addition & 1 deletion app/services/ai_backend/open_ai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def preceding_conversation_messages

content_with_images = [{ type: "text", text: message.content_text }]
content_with_images += message.documents.collect do |document|
{ type: "image_url", image_url: { url: document.file_data_url(:large) }}
{ type: "image_url", image_url: { url: document.image_url(:large) }}
end

{
Expand Down
8 changes: 4 additions & 4 deletions app/views/messages/_message.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ end %>
role: "image-preview",
controller: "image-loader",
image_loader_message_scroller_outlet: "[data-role='inner-message']",
image_loader_url_value: message.document_image_path(:small),
image_loader_url_value: message.document_image_url(:small),
action: "modal#open",
} do %>
<%= image_tag message.document_image_path(:small, fallback: ""),
<%= image_tag message.document_image_url(:small, fallback: ""),
class: %|
my-0
mx-auto
Expand Down Expand Up @@ -254,10 +254,10 @@ end %>
class="flex flex-col md:flex-row justify-center"
data-controller="image-loader"
data-image-loader-message-scroller-outlet="[data-role='inner-message']"
data-image-loader-url-value="<%= message.document_image_path(:large) %>"
data-image-loader-url-value="<%= message.document_image_url(:large) %>"
data-turbo-permanent
>
<%= image_tag message.document_image_path(:large, fallback: ""),
<%= image_tag message.document_image_url(:large, fallback: ""),
class: "w-full h-auto",
data: {
image_loader_target: "image",
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Application < Rails::Application
config.app_url_port = Setting.app_url_port
config.app_url = "#{Setting.app_url_protocol}://#{Setting.app_url_host}:#{Setting.app_url_port}"

config.hosts << Setting.app_url_host

# Active Storage
if Feature.cloudflare_storage?
config.active_storage.service = :cloudflare
Expand Down
13 changes: 7 additions & 6 deletions lib/active_storage/service/postgresql_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ def url_helpers
end

def url_options
opts = { protocol: Rails.application.config.app_url_protocol, host: Rails.application.config.app_url_host, port: Rails.application.config.app_url_port }

if ActiveStorage::Current.respond_to?(:url_options)
# url_opts = ActiveStorage::Current.url_options
# opts = url_opts if url_opts.is_a?(Hash)
opts = ActiveStorage::Current.url_options
url_opts = ActiveStorage::Current.url_options
return url_opts if url_opts.is_a?(Hash)
end

return opts
return {
protocol: Rails.application.config.app_url_protocol,
host: Rails.application.config.app_url_host,
port: Rails.application.config.app_url_port,
}
end
end
end

0 comments on commit c8fa398

Please sign in to comment.