Class: Artificial::Validators::RoleValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/artificial/validators/role_validator.rb

Constant Summary collapse

VALID_SYSTEM_ROLES =
%w[
  expert assistant helper instructor teacher guide analyst
  specialist consultant advisor reviewer critic evaluator
  researcher scientist engineer developer programmer
  writer editor translator interpreter
].freeze
ROLE_PATTERNS =
{
  domain_expert: /^you are (?:a|an) (.+) expert/i,
  professional: /^you are (?:a|an) (.+) professional/i,
  specialist: /^you are (?:a|an) (.+) specialist/i,
  assistant: /^you are (?:a|an) (?:helpful|knowledgeable|.+) assistant/i
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system_prompt) ⇒ RoleValidator



22
23
24
25
26
27
# File 'lib/artificial/validators/role_validator.rb', line 22

def initialize(system_prompt)
  @system_prompt = system_prompt
  @role_type = nil
  @errors = []
  @suggestions = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



20
21
22
# File 'lib/artificial/validators/role_validator.rb', line 20

def errors
  @errors
end

#role_typeObject (readonly)

Returns the value of attribute role_type.



20
21
22
# File 'lib/artificial/validators/role_validator.rb', line 20

def role_type
  @role_type
end

#suggestionsObject (readonly)

Returns the value of attribute suggestions.



20
21
22
# File 'lib/artificial/validators/role_validator.rb', line 20

def suggestions
  @suggestions
end

#system_promptObject (readonly)

Returns the value of attribute system_prompt.



20
21
22
# File 'lib/artificial/validators/role_validator.rb', line 20

def system_prompt
  @system_prompt
end

Instance Method Details

#effective?Boolean



47
48
49
50
# File 'lib/artificial/validators/role_validator.rb', line 47

def effective?
  validate unless @role_type
  @role_type != :generic
end

#error_messagesObject



52
53
54
# File 'lib/artificial/validators/role_validator.rb', line 52

def error_messages
  @errors
end

#optimization_suggestionsObject



56
57
58
# File 'lib/artificial/validators/role_validator.rb', line 56

def optimization_suggestions
  @suggestions
end

#valid?Boolean



42
43
44
45
# File 'lib/artificial/validators/role_validator.rb', line 42

def valid?
  validate if @errors.empty?
  @errors.empty?
end

#validateObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/artificial/validators/role_validator.rb', line 29

def validate
  @errors.clear
  @suggestions.clear

  return add_error('System prompt cannot be empty') if @system_prompt.nil? || @system_prompt.strip.empty?

  analyze_role_effectiveness
  check_role_clarity
  provide_optimization_suggestions

  self
end