Module: GitFit::LLM::Prompts

Defined in:
lib/git_fit/llm/prompts.rb

Overview

Built-in prompt templates for AI insight scenarios.

Contract: the JSON schema block (SCHEMAS) is baked at the end of every resolved template and is intentionally NOT user-customizable — ai.prompts. replaces only the body, so insights.json structured output stays stable (see wiki/AI).

Constant Summary collapse

SCENARIOS =
%i[monthly_report insights coaching].freeze
BODIES =
{
  monthly_report: <<~TXT,
  insights: <<~TXT,
  coaching: <<~TXT,
}.freeze
SCHEMAS =

Structured output contract — appended to every resolved template, never user-editable (guarantees insights.json parseability).

{
  monthly_report: <<~TXT,
  insights: <<~TXT,
  coaching: <<~TXT,
}.freeze

Class Method Summary collapse

Class Method Details

.builtin(scenario) ⇒ Object



92
93
94
# File 'lib/git_fit/llm/prompts.rb', line 92

def self.builtin(scenario)
  BODIES.fetch(scenario.to_sym)
end

.raise_unknown_scenario(scenario) ⇒ Object

Raises:



109
110
111
112
113
# File 'lib/git_fit/llm/prompts.rb', line 109

def self.raise_unknown_scenario(scenario)
  raise ConfigError,
        "LLM: unknown prompt scenario '#{scenario}'\n" \
        "  Fix: use one of #{SCENARIOS.map(&:to_s).join(', ')}"
end

.resolve(scenario, overrides = {}) ⇒ Object

Resolves a scenario template: user override (config ai.prompts) if present, else the built-in body; then appends the baked schema block.



102
103
104
105
106
107
# File 'lib/git_fit/llm/prompts.rb', line 102

def self.resolve(scenario, overrides = {})
  key = scenario.to_sym
  raise_unknown_scenario(scenario) unless BODIES.key?(key)
  body = overrides.is_a?(Hash) ? (overrides[scenario.to_s] || overrides[key.to_s] || BODIES[key]) : nil
  "#{body.to_s.rstrip}\n\n#{SCHEMAS[key].rstrip}"
end

.schema(scenario) ⇒ Object



96
97
98
# File 'lib/git_fit/llm/prompts.rb', line 96

def self.schema(scenario)
  SCHEMAS.fetch(scenario.to_sym)
end