Class: Artificial::Prompt

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = nil, **options) ⇒ Prompt

Returns a new instance of Prompt.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/artificial/prompt.rb', line 14

def initialize(input = nil, **options)
  @format = options[:format] || 'xml'
  @context = {}
  @examples = []
  @constraints = []
  @grounding = {}
  @tools = []
  @documents = []

  parse_input(input, options)
  apply_options(options)
end

Instance Attribute Details

#assistant_prefillObject

Returns the value of attribute assistant_prefill.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def assistant_prefill
  @assistant_prefill
end

#citation_styleObject

Returns the value of attribute citation_style.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def citation_style
  @citation_style
end

#constraintsObject

Returns the value of attribute constraints.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def constraints
  @constraints
end

#contextObject

Returns the value of attribute context.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def context
  @context
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def data
  @data
end

#documentsObject

Returns the value of attribute documents.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def documents
  @documents
end

#examplesObject

Returns the value of attribute examples.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def examples
  @examples
end

#formatObject

Returns the value of attribute format.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def format
  @format
end

#groundingObject

Returns the value of attribute grounding.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def grounding
  @grounding
end

#instructionsObject

Returns the value of attribute instructions.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def instructions
  @instructions
end

#messagesObject

Returns the value of attribute messages.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def messages
  @messages
end

#optimizationObject

Returns the value of attribute optimization.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def optimization
  @optimization
end

#output_formatObject

Returns the value of attribute output_format.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def output_format
  @output_format
end

#retrievalObject

Returns the value of attribute retrieval.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def retrieval
  @retrieval
end

#systemObject

Returns the value of attribute system.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def system
  @system
end

#textObject

Returns the value of attribute text.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def text
  @text
end

#thinkingObject

Returns the value of attribute thinking.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def thinking
  @thinking
end

#toneObject

Returns the value of attribute tone.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def tone
  @tone
end

#toolsObject

Returns the value of attribute tools.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def tools
  @tools
end

#validationObject

Returns the value of attribute validation.



9
10
11
# File 'lib/artificial/prompt.rb', line 9

def validation
  @validation
end

Instance Method Details

#to_sObject

Generate the final prompt structure



28
29
30
31
32
33
34
35
36
37
# File 'lib/artificial/prompt.rb', line 28

def to_s
  case @format
  when 'xml'
    generate_xml_prompt
  when 'string'
    generate_string_prompt
  else
    generate_xml_prompt
  end
end

#with_constraints(*constraint_list) ⇒ Object



70
71
72
73
# File 'lib/artificial/prompt.rb', line 70

def with_constraints(*constraint_list)
  @constraints.concat(constraint_list)
  self
end

#with_context(**context_options) ⇒ Object



46
47
48
49
# File 'lib/artificial/prompt.rb', line 46

def with_context(**context_options)
  @context.merge!(context_options)
  self
end

#with_data(data_hash) ⇒ Object



80
81
82
83
# File 'lib/artificial/prompt.rb', line 80

def with_data(data_hash)
  @data = data_hash
  self
end

#with_documents(*document_list) ⇒ Object



85
86
87
88
# File 'lib/artificial/prompt.rb', line 85

def with_documents(*document_list)
  @documents.concat(document_list)
  self
end

#with_examples(*example_list) ⇒ Object



51
52
53
54
# File 'lib/artificial/prompt.rb', line 51

def with_examples(*example_list)
  @examples.concat(example_list)
  self
end

#with_grounding(require_quotes: false, require_sources: false, allow_uncertainty: false) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/artificial/prompt.rb', line 61

def with_grounding(require_quotes: false, require_sources: false, allow_uncertainty: false)
  @grounding = {
    require_quotes: require_quotes,
    require_sources: require_sources,
    allow_uncertainty: allow_uncertainty
  }
  self
end

#with_prefill(prefill_text) ⇒ Object



90
91
92
93
# File 'lib/artificial/prompt.rb', line 90

def with_prefill(prefill_text)
  @assistant_prefill = prefill_text
  self
end

#with_system(system_prompt) ⇒ Object

Method chaining support



40
41
42
43
44
# File 'lib/artificial/prompt.rb', line 40

def with_system(system_prompt)
  validate_system_prompt(system_prompt) if system_prompt
  @system = system_prompt
  self
end

#with_thinking(enabled: true, style: 'step_by_step', show_reasoning: true) ⇒ Object



56
57
58
59
# File 'lib/artificial/prompt.rb', line 56

def with_thinking(enabled: true, style: 'step_by_step', show_reasoning: true)
  @thinking = { enabled: enabled, style: style, show_reasoning: show_reasoning }
  self
end

#with_tools(*tool_list) ⇒ Object



75
76
77
78
# File 'lib/artificial/prompt.rb', line 75

def with_tools(*tool_list)
  @tools.concat(tool_list)
  self
end