Method: OllamaChat::FollowChat#call

Defined in:
lib/ollama_chat/follow_chat.rb

#call(response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ollama_chat/follow_chat.rb', line 16

def call(response)
  OllamaChat::Chat.config.debug and jj response
  if response&.message&.role == 'assistant'
    if @messages&.last&.role != 'assistant'
      @messages << Message.new(role: 'assistant', content: '')
      @user = message_type(@messages.last.images) + " " +
        bold { color(111) { 'assistant:' } }
      @output.puts @user unless @chat.markdown.on?
    end
    if content = response.message&.content
      content = content.gsub(%r(<think>), "šŸ’­\n").gsub(%r(</think>), "\nšŸ’¬")
    end
    @messages.last.content << content
    if @chat.markdown.on? and content = @messages.last.content.full?
      markdown_content = Kramdown::ANSI.parse(content)
      @output.print clear_screen, move_home, @user, ?\n, markdown_content
    else
      @output.print content
    end
    @say.call(response)
  end
  if response.done
    @output.puts "", eval_stats(response)
  end
  self
end