Class: Roast::Cogs::Chat::Input

Inherits:
Roast::Cog::Input show all
Defined in:
lib/roast/cogs/chat/input.rb

Overview

Input specification for the chat cog

The chat cog requires a prompt that will be sent to the language model for processing. This enables single-turn interactions with the LLM without maintaining conversation context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#promptObject

The prompt to send to the language model for processing

#### Notes The chat cog does not maintain any conversational context with the LLM provider. If you want the LLM to be aware of previous conversational history, you must provide the full transcript (or relevant subset) in the prompt.

: String?



20
21
22
# File 'lib/roast/cogs/chat/input.rb', line 20

def prompt
  @prompt
end

#sessionObject

Optional session identifier for maintaining conversation context

When provided, the chat cog will use this session to maintain context across multiple invocations, allowing for conversational interactions.

The chat cog will fork a new session from this point, so multiple conversations can be resumed from the same session state.

: Session?



31
32
33
# File 'lib/roast/cogs/chat/input.rb', line 31

def session
  @session
end

Instance Method Details

#coerce(input_return_value) ⇒ Object

Coerce the input from the return value of the input block

If the input block returns a String, it will be used as the prompt value.

#### See Also

  • ‘validate!`

: (untyped) -> void



53
54
55
56
57
# File 'lib/roast/cogs/chat/input.rb', line 53

def coerce(input_return_value)
  if input_return_value.is_a?(String)
    self.prompt = input_return_value
  end
end

#valid_prompt!Object

Get the validated prompt value

Returns the prompt if it is present, otherwise raises an ‘InvalidInputError`.

#### See Also

  • ‘prompt`

  • ‘validate!`

: () -> String



68
69
70
71
72
73
# File 'lib/roast/cogs/chat/input.rb', line 68

def valid_prompt!
  valid_prompt = @prompt
  raise Cog::Input::InvalidInputError, "'prompt' is required" unless valid_prompt.present?

  valid_prompt
end

#valid_sessionObject

Get the session value if one was provided

Returns the session object if present, otherwise returns ‘nil`. This method does not raise an error when the session is absent; providing a session is optional.

#### See Also

  • ‘session`

: () -> Session?



84
85
86
# File 'lib/roast/cogs/chat/input.rb', line 84

def valid_session
  @session
end

#validate!Object

Validate that the input has all required parameters

This method ensures that a prompt has been provided before the chat cog executes.

#### See Also

  • ‘coerce`

: () -> void



41
42
43
# File 'lib/roast/cogs/chat/input.rb', line 41

def validate!
  valid_prompt!
end