Module: Insika::Evals::PersonaLoader
- Defined in:
- lib/insika/evals/persona.rb
Overview
Loads + validates a persona mapping (the persona: key of a golden, or the
--persona file of the simulate CLI). Fails LOUD on a malformed persona —
a silently relaxed max_turns or a missing knows would produce a simulation
that tests nothing.
Defined Under Namespace
Classes: InvalidPersona
Class Method Summary collapse
Class Method Details
.build(raw, source: "(inline)") ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/insika/evals/persona.rb', line 65 def build(raw, source: "(inline)") raise InvalidPersona, "#{source}: persona must be a mapping" unless raw.is_a?(Hash) goal = presence(raw["goal"]) raise InvalidPersona, "#{source}: persona needs a non-empty 'goal'" if goal.nil? knows = raw["knows"] unless knows.is_a?(Hash) && !knows.empty? raise InvalidPersona, "#{source}: persona needs a non-empty 'knows' mapping (the only facts it may assert)" end opens = presence(raw["opens_with"]) raise InvalidPersona, "#{source}: persona needs a non-empty 'opens_with'" if opens.nil? max = raw["max_turns"] unless max.is_a?(Integer) && max.positive? raise InvalidPersona, "#{source}: persona needs 'max_turns' as a positive integer" end Persona.new( goal: goal, style: presence(raw["style"]), opens_with: opens, knows: knows.transform_keys(&:to_s).transform_values(&:to_s), max_turns: max ) end |
.presence(v) ⇒ Object
92 93 94 95 |
# File 'lib/insika/evals/persona.rb', line 92 def presence(v) s = v.to_s.strip s.empty? ? nil : s end |