class Wco::AiWriter

def self.run_headline headline

def self.run_headline headline
  prompt = "Rephrase the following article title using less than 250 characters: #{headline.name}"
  new_title = self.run_prompt prompt
  new_title = new_title[0..255]
  # puts! new_title, 'new_title'
  prompt = "Write an article about the following topic: #{headline.name}"
  new_body = self.run_prompt prompt
  new_body.gsub!("\r", '')
  new_body = new_body.split("\n\n").map { |ppp| "<p>#{ppp}</p>" }.join
  new_body = new_body.gsub("\n", "<br />")
  # puts! new_body[0...200], 'new_body'
  report = Wco::Report.create!({
    title: new_title,
    # slug:  new_title,
    body:  new_body,
    author: Wco::Profile.ai_writer,
  })
  return report
end