Class: OllamaChat::FollowChat
- Inherits:
-
Object
- Object
- OllamaChat::FollowChat
- Includes:
- Ollama, Ollama::Handlers::Concern, MessageFormat, Term::ANSIColor
- Defined in:
- lib/ollama_chat/follow_chat.rb
Instance Attribute Summary collapse
-
#messages ⇒ OllamaChat::MessageList<Ollama::Message>
readonly
Returns the conversation history (an array of message objects).
Instance Method Summary collapse
-
#call(response) ⇒ OllamaChat::FollowChat
Invokes the chat flow based on the provided Ollama server response.
-
#initialize(chat:, messages:, voice: nil, output: STDOUT) ⇒ OllamaChat::FollowChat
constructor
Initializes a new instance of OllamaChat::FollowChat.
Methods included from MessageFormat
#message_type, #talk_annotate, #think_annotate
Constructor Details
#initialize(chat:, messages:, voice: nil, output: STDOUT) ⇒ OllamaChat::FollowChat
Initializes a new instance of OllamaChat::FollowChat.
15 16 17 18 19 20 21 22 |
# File 'lib/ollama_chat/follow_chat.rb', line 15 def initialize(chat:, messages:, voice: nil, output: STDOUT) super(output:) @chat = chat @output.sync = true @say = voice ? Handlers::Say.new(voice:) : NOP = @user = nil end |
Instance Attribute Details
#messages ⇒ OllamaChat::MessageList<Ollama::Message> (readonly)
Returns the conversation history (an array of message objects).
27 28 29 |
# File 'lib/ollama_chat/follow_chat.rb', line 27 def end |
Instance Method Details
#call(response) ⇒ OllamaChat::FollowChat
Invokes the chat flow based on the provided Ollama server response.
The response is expected to be a parsed JSON object containing information about the user input and the assistant’s response.
If the response indicates an assistant message, this method:
1. Ensures that an assistant response exists in the history (if not already present).
2. Updates the last with the new content and thinking (if applicable).
3. Displays the formatted terminal output for the user.
4. Outputs the voice response (if configured).
Regardless of whether an assistant message is present, this method also outputs evaluation statistics (if applicable).
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ollama_chat/follow_chat.rb', line 46 def call(response) debug_output(response) if response&.&.role == 'assistant' ensure_assistant_response_exists (response) display_formatted_terminal_output @say.call(response) end output_eval_stats(response) self end |