Class: Ollama::Prompt

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

Overview

Reusable prompt templates that produce Ollama::Messages.

Example DSL:

class ExplainCode < Ollama::Prompt
input(:code, :language)
system "You are a senior Ruby engineer."
user { [code, "Please review the #{language} implementation."].compact.join("\n") }
end

ExplainCode.new("def foo; end", "ruby").to_h

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*values) ⇒ Prompt

Returns a new instance of Prompt.



41
42
43
44
45
# File 'lib/ollama/prompt.rb', line 41

def initialize(*values)
  @input_values = resolve_input_values(*values)
  @messages = Messages.new
  build!
end

Class Attribute Details

.inputsObject (readonly)

Returns the value of attribute inputs.



17
18
19
# File 'lib/ollama/prompt.rb', line 17

def inputs
  @inputs
end

.system_contentObject (readonly)

Returns the value of attribute system_content.



17
18
19
# File 'lib/ollama/prompt.rb', line 17

def system_content
  @system_content
end

.user_blockObject (readonly)

Returns the value of attribute user_block.



17
18
19
# File 'lib/ollama/prompt.rb', line 17

def user_block
  @user_block
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



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

def messages
  @messages
end

Class Method Details

.input(*names) ⇒ Object



19
20
21
# File 'lib/ollama/prompt.rb', line 19

def input(*names)
  @inputs = names.freeze
end

.system(text) ⇒ Object



23
24
25
# File 'lib/ollama/prompt.rb', line 23

def system(text)
  @system_content = text
end

.user(&block) ⇒ Object



27
28
29
# File 'lib/ollama/prompt.rb', line 27

def user(&block)
  @user_block = block
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/ollama/prompt.rb', line 53

def ==(other)
  other.is_a?(Prompt) && to_h == other.to_h
end

#to_hObject



49
50
51
# File 'lib/ollama/prompt.rb', line 49

def to_h
  messages.to_h
end