From 853a1d03cefa6542685b92c0b86a2d46a71eafdc Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 22 Jan 2025 16:50:21 +0800 Subject: [PATCH] refactor: clean up ai_service code formatting - Adjust formatting for message parameters in the chat call - Eliminate unnecessary blank lines in generate_prompt_request method - Ensure consistent styles for arrays and block indentation These changes improve code readability and maintain consistency in formatting for better maintainability without altering functionality. --- app/jobs/batch_generate_weather_arts_job.rb | 1 - app/services/ai_service.rb | 12 ++++++------ config/routes.rb | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/jobs/batch_generate_weather_arts_job.rb b/app/jobs/batch_generate_weather_arts_job.rb index 3c233fc..350753b 100644 --- a/app/jobs/batch_generate_weather_arts_job.rb +++ b/app/jobs/batch_generate_weather_arts_job.rb @@ -30,5 +30,4 @@ class BatchGenerateWeatherArtsJob < ApplicationJob # time = Time.current.in_time_zone(timezone) # time.hour == 2 # end - end diff --git a/app/services/ai_service.rb b/app/services/ai_service.rb index bb95cd7..39ee6c3 100644 --- a/app/services/ai_service.rb +++ b/app/services/ai_service.rb @@ -11,13 +11,13 @@ class AiService response = @client.chat( parameters: { model: "gpt-4", - messages: [{ + messages: [ { role: "system", content: "You are a professional artist creating prompts for DALL-E 3. Create realistic, artistic weather scenes featuring iconic landmarks." }, { role: "user", content: generate_prompt_request(city, weather_data) - }], + } ], temperature: 0.7, max_tokens: 300 } @@ -45,20 +45,20 @@ class AiService def generate_prompt_request(city, weather_data) <<~PROMPT Create a DALL-E 3 prompt for a weather scene in #{city.name}, #{city.country.name}. - + Weather conditions: - Temperature: #{weather_data[:temperature]}°C - Weather: #{weather_data[:description]} - Cloud cover: #{weather_data[:cloud]}% - Time: Early morning - + Requirements: - Feature iconic landmarks or architecture from #{city.name} - Realistic style - Weather conditions should be clearly visible - Atmospheric and artistic composition - + Generate a detailed, creative prompt that will produce a beautiful and realistic image. PROMPT end -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index e5c5daa..fd83a4b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,8 @@ Rails.application.routes.draw do root "home#index" - resources :cities, only: [:index, :show] do - resources :weather_arts, path: 'weather', only: [:show], param: :slug + resources :cities, only: [ :index, :show ] do + resources :weather_arts, path: "weather", only: [ :show ], param: :slug end # namespace :admin do