Class: LLM::Prompt
- Inherits:
-
Object
- Object
- LLM::Prompt
- Defined in:
- lib/llm/prompt.rb
Overview
LLM::Prompt is a small object for
composing a single request from multiple role-aware messages. A
prompt is not just a string. It is an ordered chain of messages with
explicit roles (for example system and
user). Use Session#prompt when
building a prompt inside a session. Use
LLM::Prompt.new(provider) directly when you want to
construct or pass prompt objects around explicitly.
Instance Method Summary collapse
-
#initialize(provider,
&b) ⇒ Prompt constructor
A new instance of Prompt.
- #talk(content, role: @provider.user_role) ⇒ void (also: #chat)
- #user(content) ⇒ void
- #system(content) ⇒ void
- #developer(content) ⇒ void
-
#to_a ⇒
Array<LLM::Message>
Returns the prompt messages in order.
Constructor Details
#initialize(provider, &b) ⇒ Prompt
Returns a new instance of Prompt.
30 31 32 33 34 35 36 |
# File 'lib/llm/prompt.rb', line 30 def initialize(provider, &b) @provider = provider @buffer = [] unless b.nil? (b.arity == 1) ? b.call(self) : instance_eval(&b) end end |
Instance Method Details
#talk(content, role: @provider.user_role) ⇒ void Also known as: chat
This method returns an undefined value.
44 45 46 47 48 49 50 51 52 |
# File 'lib/llm/prompt.rb', line 44 def talk(content, role: @provider.user_role) role = case role.to_sym when :system then @provider.system_role when :user then @provider.user_role when :developer then @provider.developer_role else role end @buffer << LLM::Message.new(role, content) end |
#user(content) ⇒ void
This method returns an undefined value.
59 60 61 |
# File 'lib/llm/prompt.rb', line 59 def user(content) chat(content, role: @provider.user_role) end |
#system(content) ⇒ void
This method returns an undefined value.
67 68 69 |
# File 'lib/llm/prompt.rb', line 67 def system(content) chat(content, role: @provider.system_role) end |
#developer(content) ⇒ void
This method returns an undefined value.
75 76 77 |
# File 'lib/llm/prompt.rb', line 75 def developer(content) chat(content, role: @provider.developer_role) end |
#to_a ⇒ Array<LLM::Message>
Returns the prompt messages in order.
82 83 84 |
# File 'lib/llm/prompt.rb', line 82 def to_a @buffer.dup end |