ollama_chat 0.0.19 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56f1fbbeb7e84fe906636ac0e16d5223f4968a063ee73c862398bdd575b8409b
4
- data.tar.gz: f9ffc5725d73ad54efbd55239c55a615f0cd630c682d293c11fa461b72be17d9
3
+ metadata.gz: 91a8452d2970be06a595b83e8dfdc4ee8be0388b37171967ef884139ad97b492
4
+ data.tar.gz: 116ca9055525145d36a65abc5d38341a603fbc62ccf4d52257876ddaa3a3f0d9
5
5
  SHA512:
6
- metadata.gz: b331c3ca96198b45e8cf6531a1e7e0f7542607a13512d516767180ae7a21c4cc6ba3eda280a24ee0472a9bf24a45a2acaba586f635dc8e1fe3f6e459b567f574
7
- data.tar.gz: 0f2da5cc8c319d414d812af7067701567f463c8b9db6507f1cdb34eec880bb05204ddd1111a448bad289e8299858a59534315da2091287b5b033e0a85d28c7f1
6
+ metadata.gz: 710139d1db7d25ed49218eaf6c22f61cea64352bbd2d8d1c418ccaba67f190c6157b14d8c5ec41da18e83669177310143b0e3683d5df7b2d7e9c68e3edf72df7
7
+ data.tar.gz: ef6f2705cfacb4c4523ead9e3361ce980aef227e06b6bc3a7a639d6e492d82cbd03f6c1ca4b82383b29cb95d740d9b815fff3d5c57336baf5f885e1e43e81277
data/CHANGES.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-08-11 v0.0.20
4
+
5
+ ### Documentation
6
+
7
+ - Added more YARD-style documentation to all public methods throughout the codebase.
8
+
9
+ ### Fixed
10
+
11
+ - **Message Output**:
12
+ - Corrected `output(filename)` method to pass the message object to
13
+ `write_file_unless_exist` for proper content writing.
14
+
3
15
  ## 2025-08-11 v0.0.19
4
16
 
5
17
  * Added `/last` command to show last assistant message:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.19
1
+ 0.0.21
@@ -34,6 +34,33 @@ class OllamaChat::Chat
34
34
  include OllamaChat::History
35
35
  include OllamaChat::ServerSocket
36
36
 
37
+ # Initializes a new OllamaChat::Chat instance with the given command-line
38
+ # arguments.
39
+ #
40
+ # Sets up the chat environment including configuration parsing, Ollama client
41
+ # initialization, model selection, system prompt handling, document
42
+ # processing setup, and history management. This method handles all the
43
+ # bootstrapping necessary to create a functional chat session that can
44
+ # communicate with an Ollama server and process various input types including
45
+ # text, documents, web content, and images.
46
+ #
47
+ # The initialization process includes parsing command-line options using
48
+ # Tins::GO for robust argument handling, setting up the Ollama client with
49
+ # configurable timeouts (connect, read, write), validating Ollama API version
50
+ # compatibility (requires >= 0.9.0 for features used), configuring model
51
+ # selection based on command-line or configuration defaults, initializing
52
+ # system prompts from files or inline content, setting up document processing
53
+ # pipeline with embedding capabilities through Documentrix::Documents,
54
+ # creating message history management through OllamaChat::MessageList,
55
+ # initializing cache systems for document embeddings, setting up
56
+ # voice support and image handling for multimodal interactions, enabling
57
+ # optional server socket functionality for remote input, and handling
58
+ # configuration errors with interactive recovery mechanisms.
59
+ #
60
+ # @param argv [Array<String>] Command-line arguments to parse (defaults to ARGV.dup)
61
+ #
62
+ # @raise [ArgumentError] If the Ollama API version is less than 0.9.0, indicating
63
+ # incompatibility with required API features
37
64
  def initialize(argv: ARGV.dup)
38
65
  @opts = go 'f:u:m:s:c:C:D:MESVh', argv
39
66
  @opts[?h] and exit usage
@@ -80,28 +107,66 @@ class OllamaChat::Chat
80
107
  fix_config(e)
81
108
  end
82
109
 
110
+ # The ollama reader returns the Ollama API client instance.
111
+ #
112
+ # @return [Ollama::Client] the configured Ollama API client
83
113
  attr_reader :ollama
84
114
 
115
+
116
+ # Returns the documents set for this object, initializing it lazily if needed.
117
+ #
118
+ # The documents set is memoized, meaning it will only be created once per
119
+ # object instance and subsequent calls will return the same
120
+ # Documentrix::Documents instance.
121
+ #
122
+ # @return [Documentrix::Documents] A Documentrix::Documents object containing
123
+ # all documents associated with this instance
85
124
  attr_reader :documents
86
125
 
126
+ # Returns the messages set for this object, initializing it lazily if needed.
127
+ #
128
+ # The messages set is memoized, meaning it will only be created once per
129
+ # object instance and subsequent calls will return the same
130
+ # OllamaChat::MessageList instance.
131
+ #
132
+ # @return [OllamaChat::MessageList] A MessageList object containing all
133
+ # messages associated with this instance
87
134
  attr_reader :messages
88
135
 
136
+ # Returns the links set for this object, initializing it lazily if needed.
137
+ #
138
+ # The links set is memoized, meaning it will only be created once per object
139
+ # instance and subsequent calls will return the same Set instance.
140
+ #
141
+ # @return [Set] A Set object containing all links associated with this instance
89
142
  def links
90
143
  @links ||= Set.new
91
144
  end
92
145
 
93
146
  class << self
147
+ # The config attribute accessor provides read and write access to the
148
+ # configuration object associated with this instance.
94
149
  attr_accessor :config
95
150
  end
96
151
 
152
+ # The config= method assigns a new configuration object to the class.
153
+ #
154
+ # @param config [ ComplexConfig::Settings ] the configuration object to be set
97
155
  def config=(config)
98
156
  self.class.config = config
99
157
  end
100
158
 
159
+ # The config method returns the configuration object associated with the
160
+ # class.
161
+ #
162
+ # @return [ ComplexConfig::Settings ] the configuration instance
101
163
  def config
102
164
  self.class.config
103
165
  end
104
166
 
167
+ # The start method initializes the chat session by displaying information and
168
+ # conversation history, then prompts the user for input to begin interacting
169
+ # with the chat.
105
170
  def start
106
171
  info
107
172
  if messages.size > 1
@@ -235,7 +300,7 @@ class OllamaChat::Chat
235
300
  if messages.save_conversation(filename)
236
301
  STDOUT.puts "Saved conversation to #{filename.inspect}."
237
302
  else
238
- STDOUT.puts "Saving conversation to #{filename.inspect} failed."
303
+ STDERR.puts "Saving conversation to #{filename.inspect} failed."
239
304
  end
240
305
  :next
241
306
  when %r(^/links(?:\s+(clear))?$)
@@ -250,7 +315,7 @@ class OllamaChat::Chat
250
315
  if success
251
316
  STDOUT.puts "Loaded conversation from #{filename.inspect}."
252
317
  else
253
- STDOUT.puts "Loading conversation from #{filename.inspect} failed."
318
+ STDERR.puts "Loading conversation from #{filename.inspect} failed."
254
319
  end
255
320
  :next
256
321
  when %r(^/pipe\s+(.+)$)
@@ -259,6 +324,13 @@ class OllamaChat::Chat
259
324
  when %r(^/output\s+(.+)$)
260
325
  output($1)
261
326
  :next
327
+ when %r(^/vim(?:\s+(.+))?$)
328
+ if message = messages.last
329
+ OllamaChat::Vim.new($1).insert message.content
330
+ else
331
+ STDERR.puts "Warning: No message found to insert into Vim"
332
+ end
333
+ :next
262
334
  when %r(^/config$)
263
335
  display_config
264
336
  :next
@@ -274,6 +346,14 @@ class OllamaChat::Chat
274
346
  end
275
347
  end
276
348
 
349
+ # The web method searches for URLs based on a query and processes them by
350
+ # fetching, embedding, and summarizing their content, then formats the
351
+ # results into a prompt string.
352
+ #
353
+ # @param count [ String ] the number of URLs to search for
354
+ # @param query [ String ] the search query string
355
+ #
356
+ # @return [ String ] the formatted prompt string containing the query and summarized results
277
357
  def web(count, query)
278
358
  urls = search_web(query, count.to_i) or return :next
279
359
  urls.each do |url|
@@ -285,6 +365,16 @@ class OllamaChat::Chat
285
365
  config.prompts.web % { query:, results: }
286
366
  end
287
367
 
368
+ # The manage_links method handles operations on a collection of links, such
369
+ # as displaying them or clearing specific entries.
370
+ #
371
+ # It supports two main commands: 'clear' and nil (default).
372
+ # When the command is 'clear', it presents an interactive menu to either
373
+ # clear all links or individual links.
374
+ # When the command is nil, it displays the current list of links with
375
+ # hyperlinks.
376
+ #
377
+ # @param command [ String, nil ] the operation to perform on the links
288
378
  def manage_links(command)
289
379
  case command
290
380
  when 'clear'
@@ -322,10 +412,14 @@ class OllamaChat::Chat
322
412
  end
323
413
  end
324
414
 
415
+ # The clean method clears various parts of the chat session based on the
416
+ # specified parameter.
417
+ #
418
+ # @param what [ String, nil ] the type of data to clear, defaults to
419
+ # 'messages' if nil
325
420
  def clean(what)
326
- what = 'messages' if what.nil?
327
421
  case what
328
- when 'messages'
422
+ when 'messages', nil
329
423
  messages.clear
330
424
  STDOUT.puts "Cleared messages."
331
425
  when 'links'
@@ -350,6 +444,11 @@ class OllamaChat::Chat
350
444
  end
351
445
  end
352
446
 
447
+ # The display_config method renders the configuration and displays it using a
448
+ # pager.
449
+ # It determines an appropriate pager command based on environment variables
450
+ # and available system commands, then uses Kramdown::ANSI::Pager to show the
451
+ # formatted configuration output.
353
452
  def display_config
354
453
  default_pager = ENV['PAGER'].full?
355
454
  if fallback_pager = `which less`.chomp.full? || `which more`.chomp.full?
@@ -365,6 +464,18 @@ class OllamaChat::Chat
365
464
  end
366
465
  end
367
466
 
467
+ # The interact_with_user method manages the interactive loop for user input
468
+ # and chat processing.
469
+ # It handles reading user input, processing commands, managing messages, and
470
+ # communicating with the Ollama server.
471
+ # The method supports command completion, prefilling prompts, socket input
472
+ # handling, and various chat features including embedding context and voice
473
+ # support.
474
+ # It processes user input through command handling, content parsing, and
475
+ # message formatting before sending requests to the Ollama server.
476
+ # The method also handles server socket messages, manages chat history, and
477
+ # ensures proper cleanup and configuration handling throughout the
478
+ # interaction.
368
479
  def interact_with_user
369
480
  loop do
370
481
  @parse_content = true
@@ -479,6 +590,13 @@ class OllamaChat::Chat
479
590
 
480
591
  private
481
592
 
593
+ # The setup_documents method initializes the document processing pipeline by
594
+ # configuring the embedding model and database connection.
595
+ # It then loads specified documents into the system and returns the
596
+ # configured document collection.
597
+ #
598
+ # @return [ Documentrix::Documents, NULL ] the initialized document
599
+ # collection if embedding is enabled, otherwise NULL
482
600
  def setup_documents
483
601
  if embedding.on?
484
602
  @embedding_model = config.embedding.model.name
@@ -501,10 +619,35 @@ class OllamaChat::Chat
501
619
  add_documents_from_argv(document_list)
502
620
  @documents
503
621
  else
504
- Tins::NULL
622
+ NULL
505
623
  end
506
624
  end
507
625
 
626
+ # Adds documents from command line arguments to the document collection
627
+ #
628
+ # Processes a list of document paths or URLs, handling both local files and
629
+ # remote resources.
630
+ #
631
+ # @param document_list [Array<String>] List of document paths or URLs to process
632
+ #
633
+ # @return [void]
634
+ #
635
+ # @example Adding local files
636
+ # add_documents_from_argv(['/path/to/file1.txt', '/path/to/file2.pdf'])
637
+ #
638
+ # @example Adding remote URLs
639
+ # add_documents_from_argv(['https://example.com/page1', 'http://example.com/page2'])
640
+ #
641
+ # @example Mixed local and remote
642
+ # add_documents_from_argv(['/local/file.txt', 'https://remote.com/document'])
643
+ #
644
+ # @note Empty entries in the document list will trigger a collection clear operation
645
+ # @note Documents are processed in batches of 25 to manage memory usage
646
+ # @note Progress is reported to STDOUT during processing
647
+ #
648
+ # @see fetch_source
649
+ # @see embed_source
650
+ # @see documents.clear
508
651
  def add_documents_from_argv(document_list)
509
652
  if document_list.any?(&:empty?)
510
653
  STDOUT.puts "Clearing collection #{bold{documents.collection}}."
@@ -532,6 +675,11 @@ class OllamaChat::Chat
532
675
  end
533
676
  end
534
677
 
678
+ # The setup_cache method initializes and returns a Redis cache instance with
679
+ # expiring keys if a Redis URL is configured.
680
+ #
681
+ # @return [ Documentrix::Documents::RedisCache, nil ] the configured Redis
682
+ # cache instance or nil if no URL is set.
535
683
  def setup_cache
536
684
  if url = config.redis.expiring.url?
537
685
  ex = config.redis.expiring.ex?.to_i
@@ -543,6 +691,14 @@ class OllamaChat::Chat
543
691
  end
544
692
  end
545
693
 
694
+ # The fix_config method handles configuration file errors by informing the
695
+ # user about the exception and prompting them to fix it.
696
+ # It then executes a diff tool to compare the current config file with the
697
+ # default one.
698
+ # This method exits the program after handling the configuration error
699
+ #
700
+ # @param exception [ Exception ] the exception that occurred while reading
701
+ # the config file
546
702
  def fix_config(exception)
547
703
  STDOUT.puts "When reading the config file, a #{exception.class} "\
548
704
  "exception was caught: #{exception.message.inspect}"
@@ -558,6 +714,17 @@ class OllamaChat::Chat
558
714
  end
559
715
  end
560
716
 
717
+ # Enables tab completion for chat commands within the interactive session
718
+ #
719
+ # Temporarily replaces the current Reline completion procedure with a custom
720
+ # one that provides command completion based on the chat help message.
721
+ #
722
+ # @param block [Proc] The block to execute with enhanced tab completion enabled
723
+ #
724
+ # @return [Object] The return value of the executed block
725
+ #
726
+ # @see display_chat_help_message
727
+ # @see Reline.completion_proc
561
728
  def enable_command_completion(&block)
562
729
  old = Reline.completion_proc
563
730
  commands = display_chat_help_message.scan(/^\s*(\S+)/).inject(&:concat)
@@ -1,5 +1,4 @@
1
1
  module OllamaChat::Clipboard
2
-
3
2
  # Copy the last assistant's message to the system clipboard.
4
3
  #
5
4
  # This method checks if there is a last message from an assistant in the `@messages`
@@ -1,4 +1,12 @@
1
1
  module OllamaChat::Dialog
2
+ # The model_with_size method formats a model's size for display
3
+ # by creating a formatted string that includes the model name and its size
4
+ # in a human-readable format with appropriate units.
5
+ #
6
+ # @param model [ Object ] the model object that has name and size attributes
7
+ #
8
+ # @return [ Object ] a result object with an overridden to_s method
9
+ # that combines the model name and formatted size
2
10
  private def model_with_size(model)
3
11
  result = model.name
4
12
  formatted_size = Term::ANSIColor.bold {
@@ -10,6 +18,13 @@ module OllamaChat::Dialog
10
18
  result
11
19
  end
12
20
 
21
+ # The choose_model method selects a model from the available list based on
22
+ # CLI input or user interaction.
23
+ # It processes the provided CLI model parameter to determine if a regex
24
+ # selector is used, filters the models accordingly, and prompts the user to
25
+ # choose from the filtered list if needed.
26
+ # The method ensures that a model is selected and displays a connection
27
+ # message with the chosen model and base URL.
13
28
  def choose_model(cli_model, current_model)
14
29
  selector = if cli_model =~ /\A\?+(.*)\z/
15
30
  cli_model = ''
@@ -17,20 +32,35 @@ module OllamaChat::Dialog
17
32
  end
18
33
  models = ollama.tags.models.sort_by(&:name).map { |m| model_with_size(m) }
19
34
  selector and models = models.grep(selector)
20
- model = if cli_model == ''
21
- OllamaChat::Utils::Chooser.choose(models) || current_model
22
- else
23
- cli_model || current_model
24
- end
35
+ model =
36
+ if models.size == 1
37
+ models.first
38
+ elsif cli_model == ''
39
+ OllamaChat::Utils::Chooser.choose(models) || current_model
40
+ else
41
+ cli_model || current_model
42
+ end
25
43
  ensure
26
44
  STDOUT.puts green { "Connecting to #{model}@#{ollama.base_url} now…" }
27
45
  end
28
46
 
47
+ # The ask? method prompts the user with a question and returns their input.
48
+ #
49
+ # @param prompt [ String ] the message to display to the user
50
+ #
51
+ # @return [ String ] the user's response with trailing newline removed
29
52
  def ask?(prompt:)
30
53
  print prompt
31
54
  STDIN.gets.chomp
32
55
  end
33
56
 
57
+ # The choose_collection method presents a menu to select or create a document
58
+ # collection. It displays existing collections along with options to create a
59
+ # new one or exit.
60
+ # The method prompts the user for input and updates the document collection
61
+ # accordingly.
62
+ #
63
+ # @param current_collection [ String, nil ] the name of the currently active collection
34
64
  def choose_collection(current_collection)
35
65
  collections = [ current_collection ] + @documents.collections
36
66
  collections = collections.compact.map(&:to_s).uniq.sort
@@ -49,8 +79,19 @@ module OllamaChat::Dialog
49
79
  info
50
80
  end
51
81
 
82
+ # The document_policy method sets the policy for handling document imports.
83
+ #
84
+ # @param value [ String ] the document policy to be set
52
85
  attr_writer :document_policy
53
86
 
87
+ # The choose_document_policy method presents a menu to select a document policy.
88
+ # It allows the user to choose from importing, embedding, summarizing, or
89
+ # ignoring documents.
90
+ # The method displays available policies and sets the selected policy as the
91
+ # current document policy.
92
+ # If no valid policy is found, it defaults to the first option.
93
+ # After selection, it outputs the chosen policy and displays the current
94
+ # configuration information.
54
95
  def choose_document_policy
55
96
  policies = %w[ importing embedding summarizing ignoring ].sort
56
97
  current = if policies.index(@document_policy)
@@ -73,6 +114,15 @@ module OllamaChat::Dialog
73
114
  info
74
115
  end
75
116
 
117
+ # The change_system_prompt method allows the user to select or enter a new
118
+ # system prompt for the chat session.
119
+ # It provides an interactive chooser when multiple prompts match the given
120
+ # selector, and sets the selected prompt as the current system prompt for the
121
+ # messages.
122
+ #
123
+ # @param default [ String ] the default system prompt to fall back to
124
+ # @param system [ String ] the system prompt identifier or pattern to
125
+ # search for
76
126
  def change_system_prompt(default, system: nil)
77
127
  selector = if system =~ /\A\?(.+)\z/
78
128
  Regexp.new($1)
@@ -103,6 +153,11 @@ module OllamaChat::Dialog
103
153
  @messages.set_system_prompt(system)
104
154
  end
105
155
 
156
+ # The choose_prompt method presents a menu of available prompts for selection.
157
+ # It retrieves the list of prompt attributes from the configuration,
158
+ # adds an '[EXIT]' option to the list, and displays it to the user.
159
+ # After the user makes a choice, the method either exits the chooser
160
+ # or applies the selected prompt configuration.
106
161
  def choose_prompt
107
162
  prompts = config.prompts.attribute_names.sort
108
163
  prompts.unshift('[EXIT]')
@@ -115,11 +170,20 @@ module OllamaChat::Dialog
115
170
  end
116
171
  end
117
172
 
173
+ # The change_voice method allows the user to select a voice from a list of
174
+ # available options. It uses the chooser to present the options and sets the
175
+ # selected voice as the current voice.
176
+ #
177
+ # @return [ String ] the full name of the chosen voice
118
178
  def change_voice
119
179
  chosen = OllamaChat::Utils::Chooser.choose(config.voice.list)
120
180
  @current_voice = chosen.full? || config.voice.default
121
181
  end
122
182
 
183
+ # The message_list method creates and returns a new MessageList instance
184
+ # initialized with the current object as its argument.
185
+ #
186
+ # @return [ MessageList ] a new MessageList object
123
187
  def message_list
124
188
  MessageList.new(self)
125
189
  end
@@ -1,8 +1,20 @@
1
1
  module OllamaChat::DocumentCache
2
+ # The document_cache_class method returns the cache class specified in the
3
+ # configuration.
4
+ #
5
+ # @return [ Class ] the cache class defined by the config.cache setting
2
6
  def document_cache_class
3
7
  Object.const_get(config.cache)
4
8
  end
5
9
 
10
+ # The configure_cache method determines the appropriate cache class to use
11
+ # for document storage.
12
+ # It checks if the -M option was specified to use MemoryCache, otherwise it
13
+ # attempts to use the configured cache class.
14
+ # If an error occurs during this process, it falls back to using MemoryCache
15
+ # and reports the error.
16
+ #
17
+ # @return [ Class ] the selected cache class to be used for document caching
6
18
  def configure_cache
7
19
  if @opts[?M]
8
20
  Documentrix::Documents::MemoryCache
@@ -4,7 +4,6 @@ class OllamaChat::FollowChat
4
4
  include Term::ANSIColor
5
5
  include OllamaChat::MessageFormat
6
6
 
7
-
8
7
  # Initializes a new instance of OllamaChat::FollowChat.
9
8
  #
10
9
  # @param [OllamaChat::Chat] chat The chat object, which represents the conversation context.
@@ -61,6 +60,13 @@ class OllamaChat::FollowChat
61
60
 
62
61
  private
63
62
 
63
+ # The ensure_assistant_response_exists method ensures that the last message
64
+ # in the conversation is from the assistant role.
65
+ #
66
+ # If the last message is not from an assistant, it adds a new assistant
67
+ # message with empty content and optionally includes thinking content if the
68
+ # chat's think mode is enabled. It also updates the user display variable to
69
+ # reflect the assistant's message type and styling.
64
70
  def ensure_assistant_response_exists
65
71
  if @messages&.last&.role != 'assistant'
66
72
  @messages << Message.new(
@@ -73,6 +79,12 @@ class OllamaChat::FollowChat
73
79
  end
74
80
  end
75
81
 
82
+ # The update_last_message method appends the content of a response to the
83
+ # last message in the conversation. It also appends thinking content to the
84
+ # last message if thinking is enabled and thinking content is present.
85
+ #
86
+ # @param response [ Object ] the response object containing message content
87
+ # and thinking
76
88
  def update_last_message(response)
77
89
  @messages.last.content << response.message&.content
78
90
  if @chat.think.on? and response_thinking = response.message&.thinking.full?
@@ -80,6 +92,13 @@ class OllamaChat::FollowChat
80
92
  end
81
93
  end
82
94
 
95
+ # The display_formatted_terminal_output method formats and outputs the
96
+ # terminal content by processing the last message's content and thinking,
97
+ # then prints it to the output. It handles markdown parsing and annotation
98
+ # based on chat settings, and ensures proper formatting with clear screen and
99
+ # move home commands. The method takes into account whether markdown and
100
+ # thinking modes are enabled to determine how to process and display the
101
+ # content.
83
102
  def display_formatted_terminal_output
84
103
  content, thinking = @messages.last.content, @messages.last.thinking
85
104
  if @chat.markdown.on?
@@ -96,6 +115,14 @@ class OllamaChat::FollowChat
96
115
  ].compact))
97
116
  end
98
117
 
118
+ # The eval_stats method processes response statistics and formats them into a
119
+ # colored, readable string output.
120
+ #
121
+ # @param response [ Object ] the response object containing evaluation metrics
122
+ #
123
+ # @return [ String ] a formatted string with statistical information about
124
+ # the evaluation process including durations, counts, and rates, styled with
125
+ # colors and formatting
99
126
  def eval_stats(response)
100
127
  eval_duration = response.eval_duration / 1e9
101
128
  prompt_eval_duration = response.prompt_eval_duration / 1e9
@@ -114,11 +141,19 @@ class OllamaChat::FollowChat
114
141
  }
115
142
  end
116
143
 
144
+ # The output_eval_stats method outputs evaluation statistics to the specified
145
+ # output stream.
146
+ #
147
+ # @param response [ Object ] the response object containing evaluation data
117
148
  def output_eval_stats(response)
118
149
  response.done or return
119
150
  @output.puts "", eval_stats(response)
120
151
  end
121
152
 
153
+ # The debug_output method conditionally outputs the response object using jj
154
+ # when debugging is enabled.
155
+ #
156
+ # @param response [ Object ] the response object to be outputted
122
157
  def debug_output(response)
123
158
  OllamaChat::Chat.config.debug and jj response
124
159
  end
@@ -7,15 +7,31 @@ module OllamaChat::Information
7
7
  end
8
8
 
9
9
  module UserAgent
10
+ # The progname method returns the name of the application.
11
+ #
12
+ # @return [ String ] the application name "ollama_chat"
10
13
  def progname
11
14
  'ollama_chat'
12
15
  end
13
16
 
17
+ # The user_agent method constructs and returns a user agent string
18
+ # that combines the program name and the OllamaChat version
19
+ # separated by a forward slash.
20
+ #
21
+ # @return [ String ] the formatted user agent string
14
22
  def user_agent
15
23
  [ progname, OllamaChat::VERSION ] * ?/
16
24
  end
17
25
  end
18
26
 
27
+ # The collection_stats method displays statistics about the current document
28
+ # collection.
29
+ #
30
+ # This method outputs information regarding the active document collection,
31
+ # including the collection name, total number of embeddings, and a list of
32
+ # tags.
33
+ #
34
+ # @return [ nil ] This method always returns nil.
19
35
  def collection_stats
20
36
  STDOUT.puts <<~EOT
21
37
  Current Collection
@@ -27,6 +43,13 @@ module OllamaChat::Information
27
43
  nil
28
44
  end
29
45
 
46
+ # The info method displays comprehensive information about the current state
47
+ # of the ollama_chat instance.
48
+ # This includes version details, server connection status, model
49
+ # configurations, embedding settings, and various operational switches.
50
+ #
51
+ # @return [ nil ] This method does not return a value; it outputs information
52
+ # directly to standard output.
30
53
  def info
31
54
  STDOUT.puts "Running ollama_chat version: #{bold(OllamaChat::VERSION)}"
32
55
  STDOUT.puts "Connected to ollama server version: #{bold(server_version)} on: #{bold(server_url)}"
@@ -58,6 +81,9 @@ module OllamaChat::Information
58
81
  nil
59
82
  end
60
83
 
84
+ # The display_chat_help_message method returns a formatted string containing
85
+ # all available command-line options and their descriptions for the chat
86
+ # interface.
61
87
  private def display_chat_help_message
62
88
  <<~EOT
63
89
  /copy to copy last response to clipboard
@@ -90,16 +116,24 @@ module OllamaChat::Information
90
116
  /load filename load conversation messages
91
117
  /output filename save last response to filename
92
118
  /pipe command write last response to command's stdin
119
+ /vim insert the last message into a vim server
93
120
  /quit to quit
94
121
  /help to view this help
95
122
  EOT
96
123
  end
97
124
 
125
+ # The display_chat_help method outputs the chat help message to standard output.
126
+ #
127
+ # @return [ nil ] This method always returns nil after printing the help message.
98
128
  def display_chat_help
99
129
  STDOUT.puts display_chat_help_message
100
130
  nil
101
131
  end
102
132
 
133
+ # The usage method displays the command-line interface help text
134
+ # and returns an exit code of 0.
135
+ #
136
+ # @return [ Integer ] always returns 0 indicating successful help display
103
137
  def usage
104
138
  STDOUT.puts <<~EOT
105
139
  Usage: #{progname} [OPTIONS]
@@ -123,15 +157,25 @@ module OllamaChat::Information
123
157
  0
124
158
  end
125
159
 
160
+ # The version method outputs the program name and its version number to
161
+ # standard output.
162
+ #
163
+ # @return [ Integer ] returns 0 indicating successful execution
126
164
  def version
127
165
  STDOUT.puts "%s %s" % [ progname, OllamaChat::VERSION ]
128
166
  0
129
167
  end
130
168
 
169
+ # The server_version method retrieves the version of the Ollama server.
170
+ #
171
+ # @return [ String ] the version string of the connected Ollama server
131
172
  def server_version
132
173
  @server_version ||= ollama.version.version
133
174
  end
134
175
 
176
+ # The server_url method returns the base URL of the Ollama server connection.
177
+ #
178
+ # @return [ String ] the base URL used for communicating with the Ollama API
135
179
  def server_url
136
180
  @server_url ||= ollama.base_url
137
181
  end