Module: OllamaChat::MessageFormat

Included in:
Chat, FollowChat, MessageList
Defined in:
lib/ollama_chat/message_format.rb

Overview

A module that provides formatting functionality for chat messages.

The MessageFormat module encapsulates methods for determining message icons based on whether images are present, and for conditionally annotating content with thinking or talk indicators. It supports customizable formatting of message text for display in terminal interfaces.

Examples:

Using message_type to determine icon based on images

message_type([])        # => "📨"
message_type(["image"]) # => "📸"

Annotating content with thinking indicator

think_annotate { "Thinking..." } # => "💭\nThinking...\n" (when think is enabled)

Annotating content with talk indicator

talk_annotate { "Speaking..." } # => "💬\nSpeaking...\n" (when think is enabled)

Instance Method Summary collapse

Instance Method Details

#message_type(images) ⇒ String

The message_type method determines the appropriate message icon based on whether images are present.



24
25
26
# File 'lib/ollama_chat/message_format.rb', line 24

def message_type(images)
  images.present? ? ?

#talk_annotate(&block) ⇒ String?

The talk_annotate method processes a string output by a block and conditionally adds annotation.



48
49
50
51
52
53
54
55
56
# File 'lib/ollama_chat/message_format.rb', line 48

def talk_annotate(&block)
  string = block.()
  string.to_s.size == 0 and return
  if @chat.think?
    "💬\n#{string}\n"
  else
    string
  end
end

#think_annotate(&block) ⇒ String?

The think_annotate method processes a string and conditionally annotates it with a thinking emoji if the think feature is enabled.



34
35
36
37
38
39
40
# File 'lib/ollama_chat/message_format.rb', line 34

def think_annotate(&block)
  string = block.()
  string.to_s.size == 0 and return
  if @chat.think?
    "💭\n#{string}\n"
  end
end