From 6f21fe001ef2b011261039b277565ec87cf9fb1e Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 11 Feb 2025 17:59:44 +0800 Subject: [PATCH 1/2] fix: remove trailing whitespace in admin files - Clean up trailing whitespace in app/admin/state.rb - Clean up trailing whitespace in app/admin/subregions.rb - Clean up trailing whitespace in app/admin/users.rb - Adjust formatting in cities_controller.rb for consistency These changes improve code readability and maintainability by removing unnecessary whitespace. It is a small clean-up that prepares files for better version control parsing and reduces the diff clutter. --- app/admin/states.rb | 1 - app/admin/subregions.rb | 1 - app/admin/users.rb | 1 - app/controllers/cities_controller.rb | 5 ++--- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/admin/states.rb b/app/admin/states.rb index ff4edf5..2ab9104 100644 --- a/app/admin/states.rb +++ b/app/admin/states.rb @@ -15,5 +15,4 @@ ActiveAdmin.register State do # permitted << :other if params[:action] == 'create' && current_user.admin? # permitted # end - end diff --git a/app/admin/subregions.rb b/app/admin/subregions.rb index 303eb68..d03e234 100644 --- a/app/admin/subregions.rb +++ b/app/admin/subregions.rb @@ -15,5 +15,4 @@ ActiveAdmin.register Subregion do # permitted << :other if params[:action] == 'create' && current_user.admin? # permitted # end - end diff --git a/app/admin/users.rb b/app/admin/users.rb index 594f14b..54e81e3 100644 --- a/app/admin/users.rb +++ b/app/admin/users.rb @@ -15,5 +15,4 @@ ActiveAdmin.register User do # permitted << :other if params[:action] == 'create' && current_user.admin? # permitted # end - end diff --git a/app/controllers/cities_controller.rb b/app/controllers/cities_controller.rb index 47aaf36..6f616d9 100644 --- a/app/controllers/cities_controller.rb +++ b/app/controllers/cities_controller.rb @@ -1,6 +1,6 @@ class CitiesController < ApplicationController - before_action :authenticate_user!, only: [:generate_weather_art] - before_action :require_admin, only: [:generate_weather_art] + before_action :authenticate_user!, only: [ :generate_weather_art ] + before_action :require_admin, only: [ :generate_weather_art ] def index @regions = Region.includes(:countries).order(:name) @@ -63,5 +63,4 @@ class CitiesController < ApplicationController redirect_to root_path end end - end From e39c87ac5c9ea324ff5a95fc3a9c3f3a50697f07 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 12 Feb 2025 10:02:09 +0800 Subject: [PATCH 2/2] feat: improve prompt generation with location details - Include state, country, and region in the DALL-E prompt - Enhance context for the generated weather scene This change improves the specificity of the prompts generated for the AI, providing more contextual information such as state, country, and region alongside the city name. This enhancement can lead to more accurate and relevant outputs from the DALL-E 3 model for weather scenes. --- app/services/ai_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/ai_service.rb b/app/services/ai_service.rb index a9abdfa..9f86b40 100644 --- a/app/services/ai_service.rb +++ b/app/services/ai_service.rb @@ -43,8 +43,12 @@ class AiService private def generate_prompt_request(city, weather_data) + region = city.country.region&.name || "" + country = city.country.name || "" + state = city.state&.name || "" + <<~PROMPT - Create a DALL-E 3 prompt for a weather scene in #{city.name}, #{city.country.name}. + Create a DALL-E 3 prompt for a weather scene in #{city.name}, #{state}, #{country}, #{region}. Weather conditions: - Temperature: #{weather_data[:temperature]}°C