ollama_chat 0.0.57 → 0.0.58

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: '0812722ef6dcc9b968a058ad3e4d96a8944ba61aaf347e39b064881e67704c3c'
4
- data.tar.gz: 03ceba63e04403a982eac23c0a1d5bbf9ff50512f83a721a2def8c5ed8ebec46
3
+ metadata.gz: e977681ee5ceb8267b4c2d9f2ad7f9c22ac168791a14cf12a6ae5d8696d58c24
4
+ data.tar.gz: f5277d49ba8ccd5af55f83e742dfcb5b9818395151478547f183873669024d09
5
5
  SHA512:
6
- metadata.gz: 14949a812f2040b5f4ec0fb767abcb8e41e8ff2f64af2502cc9278d8245f9794e1d7f9bcab0b1b99214c80aa135b1c9b68551a5d208356fa521f3fb36bb8e7f3
7
- data.tar.gz: 44a2dfcccaa933286b5c0a0a93d6916e4bfd8e2af516d16d3524b4c26ffb76a59fd50557aef8262416fd00e7cb88e12d73fab653a6fda3c470f23f9be937d767
6
+ metadata.gz: c39142b8c05b16591d285f66d80dbbda12e20058a8fb5b533e219c029bc08e66ade15e5c87a90228a9598929f0444e71b1fdf6cfe18abb4426a423f177716086
7
+ data.tar.gz: 734d78b497080fce515f6fa326396cb031f0540b18d565cdd324eeb4f1d16010840afd1177c55ac0cf24f7dc49b7101d108d17cf499de5d75b1daf54559ef7a3
data/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-02 v0.0.58
4
+
5
+ - Updated Redis image to version to valkey **9.0.1** in docker-compose.yml
6
+ - Added `errors.lst` to `.gitignore` and updated packaging to ignore this file
7
+ - Added `utils` gem as a development dependency in `Rakefile` and
8
+ `ollama_chat.gemspec`
9
+ - Enhanced documentation consistency with standardized leading spaces for doc
10
+ comment continuation lines
11
+ - Standardized parameter and return value descriptions for methods to align
12
+ with YARD documentation standards
13
+ - Ensured all method signatures and descriptions comply with YARD documentation
14
+ standards
15
+
3
16
  ## 2026-01-21 v0.0.57
4
17
 
5
18
  - Introduce `OllamaChat::StateSelectors` module with `StateSelector` class for
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ GemHadar do
22
22
  test_dir 'spec'
23
23
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.AppleDouble', '.bundle',
24
24
  '.yardoc', 'doc', 'tags', 'corpus', 'coverage', '/config/searxng/*',
25
- '.starscope.db', 'cscope.out'
25
+ '.starscope.db', 'cscope.out', 'errors.lst'
26
26
  package_ignore '.all_images.yml', '.tool-versions', '.gitignore', 'VERSION',
27
27
  '.rspec', '.github', '.contexts', '.envrc', '.yardopts'
28
28
 
@@ -66,6 +66,7 @@ GemHadar do
66
66
  development_dependency 'debug'
67
67
  development_dependency 'simplecov'
68
68
  development_dependency 'context_spook'
69
+ development_dependency 'utils'
69
70
 
70
71
  licenses << 'MIT'
71
72
 
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  services:
2
2
  redis:
3
3
  container_name: redis
4
- image: valkey/valkey:8.1.5-alpine
4
+ image: valkey/valkey:9.0.1-alpine
5
5
  restart: unless-stopped
6
6
  ports: [ "127.0.0.1:9736:6379" ]
7
7
  volumes:
@@ -79,7 +79,7 @@ class OllamaChat::Chat
79
79
  #
80
80
  # @param argv [Array<String>] Command-line arguments to parse (defaults to ARGV.dup)
81
81
  #
82
- # @raise [ArgumentError] If the Ollama API version is less than 0.9.0, indicating
82
+ # @raise [RuntimeError] If the Ollama API version is less than 0.9.0, indicating
83
83
  # incompatibility with required API features
84
84
  def initialize(argv: ARGV.dup)
85
85
  @opts = go 'f:u:m:s:c:C:D:MESVh', argv
@@ -90,10 +90,7 @@ class OllamaChat::Chat
90
90
  self.config = @ollama_chat_config.config
91
91
  setup_switches(config)
92
92
  setup_state_selectors(config)
93
- @ollama = connect_ollama
94
- if server_version.version < '0.9.0'.version
95
- raise ArgumentError, 'require ollama API version 0.9.0 or higher'
96
- end
93
+ connect_ollama
97
94
  @model = choose_model(@opts[?m], config.model.name)
98
95
  @model_options = Ollama::Options[config.model.options]
99
96
  model_system = pull_model_unless_present(@model, @model_options)
@@ -218,7 +215,7 @@ class OllamaChat::Chat
218
215
  case content
219
216
  when %r(^/reconnect)
220
217
  STDERR.print green { "Reconnecting to ollama #{base_url.to_s.inspect}…" }
221
- @ollama = connect_ollama
218
+ connect_ollama
222
219
  STDERR.puts green { " Done." }
223
220
  :next
224
221
  when %r(^/copy$)
@@ -688,12 +685,27 @@ class OllamaChat::Chat
688
685
 
689
686
  private
690
687
 
688
+ # The base_url method returns the Ollama server URL from command-line options
689
+ # or environment configuration.
690
+ #
691
+ # @return [String] the base URL used for connecting to the Ollama API
691
692
  def base_url
692
693
  @opts[?u] || OllamaChat::EnvConfig::OLLAMA::URL
693
694
  end
694
695
 
696
+ # The connect_ollama method establishes a connection to the Ollama API server.
697
+ #
698
+ # This method initializes a new Ollama::Client instance with configured timeouts
699
+ # and connection parameters, then verifies that the connected server meets
700
+ # the minimum required API version (0.9.0). It sets the @ollama instance
701
+ # variable to the configured client and stores the server version in @server_version.
702
+ #
703
+ # @return [Ollama::Client] the configured Ollama client instance
704
+ # @raise [RuntimeError] if the connected Ollama server API version is less
705
+ # than 0.9.0
695
706
  def connect_ollama
696
- Ollama::Client.new(
707
+ @server_version = nil
708
+ @ollama = Ollama::Client.new(
697
709
  connect_timeout: config.timeouts.connect_timeout?,
698
710
  read_timeout: config.timeouts.read_timeout?,
699
711
  write_timeout: config.timeouts.write_timeout?,
@@ -701,6 +713,10 @@ class OllamaChat::Chat
701
713
  debug: ,
702
714
  user_agent:
703
715
  )
716
+ if server_version.version < '0.9.0'.version
717
+ raise 'require ollama API version 0.9.0 or higher'
718
+ end
719
+ @ollama
704
720
  end
705
721
 
706
722
  # The setup_documents method initializes the document processing pipeline by
@@ -13,10 +13,11 @@
13
13
  module OllamaChat::Clipboard
14
14
  # Copy the last assistant's message to the system clipboard.
15
15
  #
16
- # This method checks if there is a last message from an assistant in the `@messages`
17
- # array and copies its content to the clipboard using the specified command from `config.copy`.
18
- # If no assistant response is available or the clipboard command is not found, appropriate
19
- # error messages are displayed.
16
+ # This method checks if there is a last message from an assistant in the
17
+ # `@messages` array and copies its content to the clipboard using the
18
+ # specified command from `config.copy`.
19
+ # If no assistant response is available or the clipboard command is not
20
+ # found, appropriate error messages are displayed.
20
21
  #
21
22
  # @return [NilClass] Always returns nil.
22
23
  def copy_to_clipboard
@@ -38,9 +39,9 @@ module OllamaChat::Clipboard
38
39
 
39
40
  # Paste content from the input.
40
41
  #
41
- # Prompts the user to paste their content and then press C-d (Ctrl+D) to terminate
42
- # input. Reads all lines from standard input until Ctrl+D is pressed and returns
43
- # the pasted content as a string.
42
+ # Prompts the user to paste their content and then press C-d (Ctrl+D) to
43
+ # terminate input. Reads all lines from standard input until Ctrl+D is
44
+ # pressed and returns the pasted content as a string.
44
45
  #
45
46
  # @return [String] The pasted content entered by the user.
46
47
  def paste_from_input
@@ -19,7 +19,7 @@ module OllamaChat::Conversation
19
19
  # format.
20
20
  #
21
21
  # @param filename [String] The path to the file where the conversation should
22
- # be saved
22
+ # be saved
23
23
  #
24
24
  # @example Save conversation with explicit filename
25
25
  # chat.save_conversation('conversations/2023-10-15_my_session.json')
@@ -43,7 +43,7 @@ module OllamaChat::Conversation
43
43
  # for confirmation.
44
44
  #
45
45
  # @param filename [String] The path to the file containing the conversation
46
- # to load
46
+ # to load
47
47
  #
48
48
  # @example Load a conversation from a specific file
49
49
  # chat.load_conversation('conversations/2023-10-15_my_session.json')
@@ -109,7 +109,7 @@ module OllamaChat::Dialog
109
109
  #
110
110
  # @param default [ String ] the default system prompt to fall back to
111
111
  # @param system [ String ] the system prompt identifier or pattern to
112
- # search for
112
+ # search for
113
113
  def change_system_prompt(default, system: nil)
114
114
  selector = case system
115
115
  when /\A\?(.+)\z/
@@ -12,9 +12,9 @@ module OllamaChat::DocumentCache
12
12
  # configuration to dynamically load the appropriate cache implementation.
13
13
  #
14
14
  # @return [Class] The cache class referenced by the configuration's cache
15
- # setting.
15
+ # setting.
16
16
  # @raise [NameError] If the configured cache class name does not correspond
17
- # to an existing constant.
17
+ # to an existing constant.
18
18
  def document_cache_class
19
19
  Object.const_get(config.cache)
20
20
  end
@@ -22,17 +22,18 @@ module OllamaChat::DocumentCache
22
22
  # Configures and returns the appropriate cache class based on command-line
23
23
  # options.
24
24
  #
25
- # Determines which cache implementation to use based on command-line flags: -
26
- # If the `-M` flag is set, uses {Documentrix::Documents::MemoryCache} -
27
- # Otherwise, resolves and returns the cache class specified in configuration
25
+ # Determines which cache implementation to use based on command-line flags:
26
+ # - If the `-M` flag is set, uses {Documentrix::Documents::MemoryCache}
27
+ # - Otherwise, resolves and returns the cache class specified in
28
+ # configuration
28
29
  #
29
30
  # Falls back to {Documentrix::Documents::MemoryCache} if configuration
30
31
  # resolution fails.
31
32
  #
32
33
  # @return [Class] The selected cache class for document storage and
33
- # retrieval.
34
+ # retrieval.
34
35
  # @raise [StandardError] If there is an error resolving the configured cache
35
- # class, logs the error to standard error and falls back to MemoryCache.
36
+ # class, logs the error to standard error and falls back to MemoryCache.
36
37
  def configure_cache
37
38
  if @opts[?M]
38
39
  Documentrix::Documents::MemoryCache
@@ -19,12 +19,12 @@ class OllamaChat::FollowChat
19
19
  # Initializes a new instance of OllamaChat::FollowChat.
20
20
  #
21
21
  # @param [OllamaChat::Chat] chat The chat object, which represents the
22
- # conversation context.
22
+ # conversation context.
23
23
  # @param [#to_a] messages A collection of message objects, representing the
24
- # conversation history.
24
+ # conversation history.
25
25
  # @param [String] voice (optional) to speek with if any.
26
26
  # @param [IO] output (optional) The output stream where terminal output
27
- # should be printed. Defaults to STDOUT.
27
+ # should be printed. Defaults to STDOUT.
28
28
  #
29
29
  # @return [OllamaChat::FollowChat] A new instance of OllamaChat::FollowChat.
30
30
  def initialize(chat:, messages:, voice: nil, output: STDOUT)
@@ -39,7 +39,7 @@ class OllamaChat::FollowChat
39
39
  # Returns the conversation history (an array of message objects).
40
40
  #
41
41
  # @return [OllamaChat::MessageList<Ollama::Message>] The array of messages in
42
- # the conversation.
42
+ # the conversation.
43
43
  attr_reader :messages
44
44
 
45
45
  # Invokes the chat flow based on the provided Ollama server response.
@@ -59,7 +59,7 @@ class OllamaChat::FollowChat
59
59
  # outputs evaluation statistics (if applicable).
60
60
  #
61
61
  # @param [Ollama::Response] response The parsed JSON response from the Ollama
62
- # server.
62
+ # server.
63
63
  #
64
64
  # @return [OllamaChat::FollowChat] The current instance for method chaining.
65
65
  def call(response)
@@ -128,7 +128,7 @@ class OllamaChat::FollowChat
128
128
  # last message if thinking is enabled and thinking content is present.
129
129
  #
130
130
  # @param response [ Object ] the response object containing message content
131
- # and thinking
131
+ # and thinking
132
132
  def update_last_message(response)
133
133
  @messages.last.content << response.message&.content
134
134
  if @chat.think_loud? and response_thinking = response.message&.thinking.full?
@@ -212,8 +212,8 @@ class OllamaChat::FollowChat
212
212
  # @param response [ Object ] the response object containing evaluation metrics
213
213
  #
214
214
  # @return [ String ] a formatted string with statistical information about
215
- # the evaluation process including durations, counts, and rates, styled with
216
- # colors and formatting
215
+ # the evaluation process including durations, counts, and rates, styled
216
+ # with colors and formatting
217
217
  def eval_stats(response)
218
218
  eval_duration = response.eval_duration / 1e9
219
219
  prompt_eval_duration = response.prompt_eval_duration / 1e9
@@ -24,7 +24,7 @@ module OllamaChat::History
24
24
  # reliably for reading from or writing to the chat history file.
25
25
  #
26
26
  # @return [String] the absolute file path to the chat history file as
27
- # specified in the configuration
27
+ # specified in the configuration
28
28
  def chat_history_filename
29
29
  File.expand_path(OllamaChat::EnvConfig::OLLAMA::CHAT::HISTORY)
30
30
  end
@@ -80,7 +80,7 @@ module OllamaChat::Information
80
80
  # configurations, embedding settings, and various operational switches.
81
81
  #
82
82
  # @return [ nil ] This method does not return a value; it outputs information
83
- # directly to standard output.
83
+ # directly to standard output.
84
84
  def info
85
85
  STDOUT.puts "Running ollama_chat version: #{bold(OllamaChat::VERSION)}"
86
86
  STDOUT.puts "Connected to ollama server version: #{bold(server_version)} on: #{bold(server_url)}"
@@ -16,7 +16,7 @@ module OllamaChat::KramdownANSI
16
16
  # falling back to default styles.
17
17
  #
18
18
  # @return [ Hash ] a hash of ANSI styles configured either from environment
19
- # variables or using default settings
19
+ # variables or using default settings
20
20
  def configure_kramdown_ansi_styles
21
21
  if json = OllamaChat::EnvConfig::KRAMDOWN_ANSI_OLLAMA_CHAT_STYLES?
22
22
  Kramdown::ANSI::Styles.from_json(json).ansi_styles
@@ -37,7 +37,7 @@ module OllamaChat::KramdownANSI
37
37
  # If nil, returns an empty string.
38
38
  #
39
39
  # @return [ String ] the content formatted with ANSI escape sequences
40
- # according to the configured styles
40
+ # according to the configured styles
41
41
  def kramdown_ansi_parse(content)
42
42
  content.nil? and return ''
43
43
  Kramdown::ANSI.parse(content, ansi_styles: @kramdown_ansi_styles)
@@ -35,7 +35,7 @@ class OllamaChat::MessageList
35
35
  # The initialize method sets up the message list for an OllamaChat session.
36
36
  #
37
37
  # @param chat [ OllamaChat::Chat ] the chat object that this message list
38
- # belongs to
38
+ # belongs to
39
39
  def initialize(chat)
40
40
  @chat = chat
41
41
  @messages = []
@@ -54,7 +54,7 @@ class OllamaChat::MessageList
54
54
  # OllamaChat::MessageList instance.
55
55
  #
56
56
  # @attr_reader [OllamaChat::MessageList] A MessageList object containing all
57
- # messages associated with this instance
57
+ # messages associated with this instance
58
58
  attr_reader :messages
59
59
 
60
60
  # Returns the number of messages stored in the message list.
@@ -202,9 +202,11 @@ class OllamaChat::MessageList
202
202
 
203
203
  # Sets the system prompt for the chat session.
204
204
  #
205
- # @param system [String, nil] The new system prompt. If `nil` or `false`, clears the system prompt.
205
+ # @param system [String, nil] The new system prompt. If `nil` or `false`,
206
+ # clears the system prompt.
206
207
  #
207
- # @return [OllamaChat::MessageList] Returns `self` to allow chaining of method calls.
208
+ # @return [OllamaChat::MessageList] Returns `self` to allow chaining of
209
+ # method calls.
208
210
  #
209
211
  # @note This method:
210
212
  # - Removes all existing system prompts from the message list
@@ -252,7 +254,7 @@ class OllamaChat::MessageList
252
254
  # curent location, time, and unit preferences.
253
255
  #
254
256
  # @return [Array] An array of Ollama::Message objects representing the
255
- # messages in the list.
257
+ # messages in the list.
256
258
  def to_ary
257
259
  location = at_location.full?
258
260
  add_system = !!location
@@ -18,7 +18,7 @@ module OllamaChat::MessageOutput
18
18
  #
19
19
  # @return [ OllamaChat::Chat ] returns self
20
20
  # @return [ nil ] returns nil if the command is not provided or if there is
21
- # no assistant message
21
+ # no assistant message
22
22
  def pipe(cmd)
23
23
  cmd.present? or return
24
24
  if message = @messages.last and message.role == 'assistant'
@@ -44,7 +44,7 @@ module OllamaChat::MessageOutput
44
44
  # The output method writes the last assistant message to a file.
45
45
  #
46
46
  # @param filename [ String ] the path to the file where the last assistant
47
- # message should be written
47
+ # message should be written
48
48
  #
49
49
  # @return [ OllamaChat::Chat ] returns self
50
50
  def output(filename)
@@ -72,11 +72,14 @@ module OllamaChat::MessageOutput
72
72
  # doesn't exist, the method returns early without writing. Otherwise, it
73
73
  # opens the file in write mode and writes the message content to it.
74
74
  #
75
- # @param filename [ String ] the path to the file where the content should be written
76
- # @param message [ Ollama::Message ] the message object containing the content to write
75
+ # @param filename [ String ] the path to the file where the content should be
76
+ # written
77
+ # @param message [ Ollama::Message ] the message object containing the
78
+ # content to write
77
79
  #
78
80
  # @return [ TrueClass ] returns true if the file was successfully written
79
- # @return [ nil ] returns nil if the user chose not to overwrite or if an error occurred
81
+ # @return [ nil ] returns nil if the user chose not to overwrite or if an
82
+ # error occurred
80
83
  def attempt_to_write_file(filename, message)
81
84
  path = Pathname.new(filename.to_s).expand_path
82
85
  if !path.exist? ||
@@ -21,7 +21,7 @@ module OllamaChat::ModelHandling
21
21
  # @param model [ String ] the name of the Ollama model
22
22
  #
23
23
  # @return [ String, FalseClass ] the system prompt if the model is present,
24
- # false otherwise
24
+ # false otherwise
25
25
  def model_present?(model)
26
26
  ollama.show(model:) { return _1.system.to_s }
27
27
  rescue Ollama::Errors::NotFoundError
@@ -32,8 +32,6 @@ module OllamaChat::ModelHandling
32
32
  # remote server if it is not found locally.
33
33
  #
34
34
  # @param model [ String ] the name of the model to be pulled
35
- #
36
- # @return [ nil ]
37
35
  def pull_model_from_remote(model)
38
36
  STDOUT.puts "Model #{bold{model}} not found locally, attempting to pull it from remote now…"
39
37
  ollama.pull(model:)
@@ -54,7 +52,7 @@ module OllamaChat::ModelHandling
54
52
  # @param options [ Hash ] Options for the pull_model_from_remote method.
55
53
  #
56
54
  # @return [ String, FalseClass ] the system prompt if the model and it are
57
- # present, false otherwise.
55
+ # present, false otherwise.
58
56
  def pull_model_unless_present(model, options)
59
57
  if system = model_present?(model)
60
58
  return system.full?
@@ -75,7 +75,7 @@ class OllamaChat::OllamaChatConfig
75
75
  # configuration file.
76
76
  #
77
77
  # @return [ Pathname ] a Pathname object representing the path to the
78
- # config.yml file within the configuration directory
78
+ # config.yml file within the configuration directory
79
79
  def default_path
80
80
  config_dir_path + 'config.yml'
81
81
  end
@@ -85,7 +85,7 @@ class OllamaChat::OllamaChatConfig
85
85
  # 'ollama_chat' subdirectory.
86
86
  #
87
87
  # @return [ Pathname ] the pathname object representing the configuration
88
- # directory
88
+ # directory
89
89
  def config_dir_path
90
90
  OllamaChat::EnvConfig::XDG_CONFIG_HOME
91
91
  end
@@ -18,7 +18,7 @@ module OllamaChat::Parsing
18
18
  # @param source_io [IO] the input source to be parsed
19
19
  #
20
20
  # @return [ String, nil ] the parsed content as a string or nil if the
21
- # content type is not supported
21
+ # content type is not supported
22
22
  def parse_source(source_io)
23
23
  case source_io&.content_type
24
24
  when 'text/html'
@@ -79,7 +79,7 @@ module OllamaChat::Parsing
79
79
  # @param source_io [IO] the input stream containing the RSS feed data
80
80
  #
81
81
  # @return [String] a formatted string representation of the RSS feed with
82
- # channel title and item details
82
+ # channel title and item details
83
83
  def parse_rss(source_io)
84
84
  feed = RSS::Parser.parse(source_io, false, false)
85
85
  title = <<~EOT
@@ -109,7 +109,7 @@ module OllamaChat::Parsing
109
109
  # @param source_io [IO] the input stream containing the Atom feed data
110
110
  #
111
111
  # @return [String] a formatted string representation of the Atom feed with
112
- # title, items, links, update dates, and content
112
+ # title, items, links, update dates, and content
113
113
  def parse_atom(source_io)
114
114
  feed = RSS::Parser.parse(source_io, false, false)
115
115
  title = <<~EOT
@@ -147,7 +147,8 @@ module OllamaChat::Parsing
147
147
  # If Ghostscript is not available in the system path, it outputs an error message.
148
148
  #
149
149
  # @param io [IO] An IO object containing PDF data to be processed
150
- # @return [String, nil] The processed PDF content as a string, or nil if processing fails
150
+ # @return [String, nil] The processed PDF content as a string, or nil if
151
+ # processing fails
151
152
  def ps_read(io)
152
153
  gs = `which gs`.chomp
153
154
  if gs.present?
@@ -43,7 +43,7 @@ module OllamaChat::ServerSocket
43
43
  # @param parse [ TrueClass, FalseClass ] whether to parse the response, defaults to false
44
44
  #
45
45
  # @return [ UnixSocks::Message, nil ] the response from transmit_with_response if type
46
- # is :socket_input_with_response, otherwise nil
46
+ # is :socket_input_with_response, otherwise nil
47
47
  def send_to_server_socket(content, config:, type: :socket_input, runtime_dir: nil, working_dir: nil, parse: false)
48
48
  server = create_socket_server(config:, runtime_dir:, working_dir:)
49
49
  message = { content:, type:, parse: }
@@ -66,12 +66,12 @@ module OllamaChat::ServerSocket
66
66
  # for Unix domain sockets.
67
67
  #
68
68
  # @param config [ComplexConfig::Settings] the configuration object
69
- # containing server settings
69
+ # containing server settings
70
70
  # @param runtime_dir [ String ] pathname to runtime_dir of socket file
71
71
  # @param working_dir [ String ] pathname to working_dir used for deriving socket file
72
72
  #
73
73
  # @return [UnixSocks::DomainSocketServer] a configured Unix domain socket server
74
- # instance ready to receive messages
74
+ # instance ready to receive messages
75
75
  def create_socket_server(config:, runtime_dir: nil, working_dir: nil)
76
76
  working_dir ||= Dir.pwd
77
77
  if runtime_dir
@@ -91,7 +91,7 @@ module OllamaChat::ServerSocket
91
91
  # the server socket message instance variable.
92
92
  #
93
93
  # @return [ Object, nil ] the current server socket message object or nil if
94
- # not set
94
+ # not set
95
95
  attr_accessor :server_socket_message
96
96
 
97
97
  # Initializes the server socket to receive messages from the Ollama Chat
@@ -32,7 +32,7 @@ module OllamaChat::SourceFetching
32
32
  # @param url [ String ] the URL for which HTTP options are being prepared
33
33
  #
34
34
  # @return [ Hash ] a hash containing HTTP options such as ssl_verify_peer and
35
- # proxy settings
35
+ # proxy settings
36
36
  def http_options(url)
37
37
  options = {}
38
38
  if ssl_no_verify = config.ssl_no_verify?
@@ -49,7 +49,8 @@ module OllamaChat::SourceFetching
49
49
  # including commands, URLs, and file paths. It processes the source based on
50
50
  # its type and yields a temporary file handle for further processing.
51
51
  #
52
- # @param source [ String ] the source identifier which can be a command, URL, or file path
52
+ # @param source [ String ] the source identifier which can be a command, URL,
53
+ # or file path
53
54
  #
54
55
  # @yield [ tmp ]
55
56
  def fetch_source(source, check_exist: false, &block)
@@ -135,7 +136,7 @@ module OllamaChat::SourceFetching
135
136
  # @param source [ String ] the source identifier or path
136
137
  #
137
138
  # @return [ String ] a formatted message indicating the import result and the
138
- # parsed content
139
+ # parsed content
139
140
  def import_source(source_io, source)
140
141
  source = source.to_s
141
142
  document_type = source_io&.content_type.full? { |ct| italic { ct } + ' ' }
@@ -150,7 +151,7 @@ module OllamaChat::SourceFetching
150
151
  # passes the resulting IO object to the import_source method for processing.
151
152
  #
152
153
  # @param source [String] The source identifier which can be a command, URL,
153
- # or file path
154
+ # or file path
154
155
  #
155
156
  # @return [String, nil] A formatted message indicating the import result and
156
157
  # parsed content, # or nil if the operation fails
@@ -208,7 +209,7 @@ module OllamaChat::SourceFetching
208
209
  # @param count [Integer, nil] An optional counter for tracking processing order
209
210
  #
210
211
  # @return [Array, String, nil] The embedded chunks or processed content, or
211
- # nil if embedding is disabled or fails
212
+ # nil if embedding is disabled or fails
212
213
  def embed_source(source_io, source, count: nil)
213
214
  @embedding.on? or return parse_source(source_io)
214
215
  m = "Embedding #{italic { source_io&.content_type }} document #{source.to_s.inspect}."
@@ -263,10 +264,10 @@ module OllamaChat::SourceFetching
263
264
  # disabled, it falls back to generating a summary instead.
264
265
  #
265
266
  # @param source [String] The source identifier which can be a command, URL,
266
- # or file path
267
+ # or file path
267
268
  #
268
269
  # @return [String, nil] The formatted embedding result or summary message, or
269
- # nil if the operation fails
270
+ # nil if the operation fails
270
271
  def embed(source)
271
272
  if @embedding.on?
272
273
  STDOUT.puts "Now embedding #{source.to_s.inspect}."
@@ -90,7 +90,7 @@ module OllamaChat::StateSelectors
90
90
  # or exiting the chooser if the user selects '[EXIT]' or cancels the selection.
91
91
  #
92
92
  # @return [ nil ] This method does not return a value; it updates the instance
93
- # variable @selected based on user input.
93
+ # variable @selected based on user input.
94
94
  def choose
95
95
  states = @states + [ '[EXIT]' ]
96
96
  case chosen = OllamaChat::Utils::Chooser.choose(states)
@@ -64,8 +64,6 @@ module OllamaChat::Switches
64
64
  #
65
65
  # @param msg [ Hash ] a hash containing true and false messages
66
66
  # @param value [ Object ] the default state of the switch
67
- #
68
- # @return [ void ]
69
67
  def initialize(msg:, value:)
70
68
  @value = !!value
71
69
  @msg = msg
@@ -78,9 +76,9 @@ module OllamaChat::Switches
78
76
  # and optionally displays it.
79
77
  #
80
78
  # @param value [ Object ] the value to be converted to a boolean and
81
- # assigned
79
+ # assigned
82
80
  # @param show [ TrueClass, FalseClass ] determines whether to display the
83
- # value after setting
81
+ # value after setting
84
82
  def set(value, show: false)
85
83
  @value = !!value
86
84
  show && self.show
@@ -90,7 +88,7 @@ module OllamaChat::Switches
90
88
  # optionally displays it.
91
89
  #
92
90
  # @param show [ TrueClass, FalseClass ] determines whether to show the
93
- # value after toggling
91
+ # value after toggling
94
92
  def toggle(show: true)
95
93
  @value = !@value
96
94
  show && self.show
@@ -154,13 +152,13 @@ module OllamaChat::Switches
154
152
  # The embedding attribute reader returns the embedding switch object.
155
153
  #
156
154
  # @return [ OllamaChat::Switches::CombinedSwitch ] the embedding switch
157
- # instance
155
+ # instance
158
156
  attr_reader :embedding
159
157
 
160
158
  # The embedding_enabled reader returns the embedding enabled switch instance.
161
159
  #
162
160
  # @return [ OllamaChat::Switches::Switch ] the embedding enabled switch
163
- # instance
161
+ # instance
164
162
  attr_reader :embedding_enabled
165
163
 
166
164
  # The embedding_paused method returns the current state of the embedding pause flag.
@@ -181,7 +179,7 @@ module OllamaChat::Switches
181
179
  # output, voice output, embedding, and location settings.
182
180
  #
183
181
  # @param config [ ComplexConfig::Settings ] the configuration object
184
- # containing settings for the switches
182
+ # containing settings for the switches
185
183
  def setup_switches(config)
186
184
  @stream = Switch.new(
187
185
  value: config.stream,
@@ -127,7 +127,7 @@ class OllamaChat::Utils::Fetcher
127
127
  #
128
128
  # @return [ nil ] returns nil if the file does not exist
129
129
  # @return [ Object ] returns the result of the block execution if the file
130
- # exists
130
+ # exists
131
131
  def self.read(filename, &block)
132
132
  if File.exist?(filename)
133
133
  File.open(filename) do |file|
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.57'
3
+ VERSION = '0.0.58'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -21,7 +21,7 @@ module OllamaChat::WebSearching
21
21
  # @param n [ Integer ] the maximum number of results to return
22
22
  #
23
23
  # @return [ Array<String>, nil ] an array of URLs from the search results or
24
- # nil if the search engine is not implemented
24
+ # nil if the search engine is not implemented
25
25
  def search_web(query, n = nil)
26
26
  l = @messages.at_location.full? and query += " #{l}"
27
27
  n = n.to_i.clamp(1..)
@@ -70,10 +70,10 @@ module OllamaChat::WebSearching
70
70
  #
71
71
  # @param query [ String ] the search query string to be used
72
72
  # @param n [ Integer ] the maximum number of URLs to extract from the search
73
- # results
73
+ # results
74
74
  #
75
75
  # @return [ Array<String> ] an array of URL strings extracted from the search
76
- # results
76
+ # results
77
77
  def search_web_with_duckduckgo(query, n)
78
78
  url = config.web_search.engines.duckduckgo.url % { query: }
79
79
  OllamaChat::Utils::Fetcher.get(
data/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.57 ruby lib
2
+ # stub: ollama_chat 0.0.58 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.57".freeze
6
+ s.version = "0.0.58".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
33
33
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
34
34
  s.add_development_dependency(%q<context_spook>.freeze, [">= 0".freeze])
35
+ s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
35
36
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
36
37
  s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.18".freeze])
37
38
  s.add_runtime_dependency(%q<documentrix>.freeze, [">= 0.0.4".freeze])
data/spec/spec_helper.rb CHANGED
@@ -58,7 +58,7 @@ module AssetHelpers
58
58
  # @yield [ io ] yields the IO object for the asset file to the provided block
59
59
  #
60
60
  # @return [ File, nil ] returns the IO object for the asset file, or nil if a
61
- # block is provided and the block does not return a value
61
+ # block is provided and the block does not return a value
62
62
  def asset_io(name, &block)
63
63
  io = File.new(File.join(__dir__, 'assets', name))
64
64
  if block
@@ -130,7 +130,7 @@ module ProtectEnvVars
130
130
  # during test execution.
131
131
  #
132
132
  # @return [Proc] a lambda that wraps test execution with environment variable
133
- # preservation
133
+ # preservation
134
134
  def self.apply
135
135
  -> example do
136
136
  if example.metadata[:protect_env]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.57
4
+ version: 0.0.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -121,6 +121,20 @@ dependencies:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: utils
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
124
138
  - !ruby/object:Gem::Dependency
125
139
  name: excon
126
140
  requirement: !ruby/object:Gem::Requirement