class GemHadar

def create_body

def create_body
  base_url = ENV['OLLAMA_URL']
  if base_url.blank? && host = ENV['OLLAMA_HOST'].full?
    base_url = 'http://%s' % host
  end
  base_url.present? or return
  log_diff = version_log_diff(to_version: version)
  model    = ENV.fetch('OLLAMA_MODEL', 'llama3.1')
  ollama   = Ollama::Client.new(base_url:, read_timeout: 600, connect_timeout: 60)
  system = <<~EOT
    You are a Ruby programmer generating changelog messages in markdown
    format for new releases, so users can see what has changed. Remember you
    are not a chatbot of any kind.
  EOT
  prompt = (<<~EOT) % { name:, version:, log_diff: }
    Output the content of a changelog for the new release of %{name} %{version}
    **Strictly** follow these guidelines:
      - Use bullet points in markdown format (`-`) to list significant changes.
      - Exclude trivial updates such as:
        * Version number increments
        * Dependency version bumps (unless they resolve critical issues)
        * Minor code style adjustments
        * Internal documentation tweaks
      - Include only verified and substantial changes that impact
        functionality, performance, or user experience.
      - If unsure about a change's significance, omit it from the output.
      - Avoid adding any comments or notes; keep the output purely factual.
    These are the log messages including patches for the new release:
    %{log_diff}
  EOT
  options = ENV['OLLAMA_OPTIONS'].full? { |o| JSON.parse(o) } || {}
  options |= { "temperature" => 0, "top_p" => 1, "min_p" => 0.1 }
  ollama.generate(model:, system:, prompt:, options:, stream: false, think: false).response
end