Class: OllamaChat::FollowChat

Inherits:
Object
  • Object
show all
Includes:
Ollama, Ollama::Handlers::Concern, MessageFormat, Term::ANSIColor
Defined in:
lib/ollama_chat/follow_chat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageFormat

#message_type, #talk_annotate, #think_annotate

Constructor Details

#initialize(chat:, messages:, voice: nil, output: STDOUT) ⇒ FollowChat

Returns a new instance of FollowChat.



7
8
9
10
11
12
13
14
# File 'lib/ollama_chat/follow_chat.rb', line 7

def initialize(chat:, messages:, voice: nil, output: STDOUT)
  super(output:)
  @chat        = chat
  @output.sync = true
  @say         = voice ? Handlers::Say.new(voice:) : NOP
  @messages    = messages
  @user        = nil
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



16
17
18
# File 'lib/ollama_chat/follow_chat.rb', line 16

def messages
  @messages
end

Instance Method Details

#call(response) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ollama_chat/follow_chat.rb', line 18

def call(response)
  debug_output(response)

  if response&.message&.role == 'assistant'
    ensure_assistant_response_exists
    update_last_message(response)
    display_formatted_terminal_output
    @say.call(response)
  end

  output_eval_stats(response)

  self
end