ollama_chat 0.0.55 → 0.0.56

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: b2e00c933dc3118c04db47cbe4361fadcc500004a4f5ddd5aded07cea3bf6119
4
- data.tar.gz: 5b959cdf55031620153e8176f69aaa1bb815872a03d8e1ae172fcc0e4b3d2977
3
+ metadata.gz: 683c0bf5fdb8756030c0c5b69767d95f8ae852094a0048cb61b4cf7166f6a045
4
+ data.tar.gz: 8e7f9022cfd1e9c32f987b76196222d346100cd5ceaa6d59e6dc5c30257e5dbb
5
5
  SHA512:
6
- metadata.gz: ba54894c682fec7e4c3756d6875eb0644b0104a8affcb95b6b55d15416998ffdf667e8e308c21fb04a5191a67a646d7c4d11a2a0516fa20d122e25d825f00d62
7
- data.tar.gz: e0590805be446b6512ff0fbe3e44e960360be18681e9cd557de20bda2f2c8b44cd59e96059a62bdca4db311a6dcdcf3cb7c0e710e3e56570ba980e3e20dc7948
6
+ metadata.gz: 854af0ea07ced05e3f2f36741dd98592a2f6968e3307662e10c14bcb9a10b2168a1dde962de32f44e73719d177547cbccd8eee76c0554878a0de7ce2e1811772
7
+ data.tar.gz: 86b71f7b0748be19d0f772213b1a21ea8c7f838296bcd48348076ef39372e0a0f07db20c59a1c1b56f8a7592d100993a7ffa6b6507b4febbbca2977f0375baff
data/CHANGES.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-01-17 v0.0.56
4
+
5
+ - Updated `context_spook` dependency from version **1.4** to **1.5**
6
+ - Expanded context file inclusion to support YAML files
7
+ - Updated `context_spook` method to pass `format` parameter to
8
+ `ContextSpook::generate_context` calls
9
+ - Added `context` section to default configuration with `format: JSON` setting
10
+ - Added `/reconnect` command to reset Ollama connection
11
+ - Introduced `connect_ollama` method to create new Ollama client instances with
12
+ current configuration
13
+ - Added `base_url` method to resolve connection URL from command-line or
14
+ environment config
15
+ - Updated `handle_input` to process `/reconnect` command and trigger
16
+ reconnection
17
+ - Enhanced `OllamaChat::InputContent#input` method to select and read multiple
18
+ files matching a glob pattern
19
+ - Updated `OllamaChat::InputContent#choose_filename` to accept a `chosen`
20
+ parameter for tracking selections
21
+ - Modified test cases in `spec/ollama_chat/input_content_spec.rb` to verify
22
+ multiple file selection behavior
23
+ - Files are now concatenated with filename headers in the output
24
+ - Maintains backward compatibility with single file selection
25
+ - Uses `Set` for efficient duplicate prevention during selection
26
+ - Removed specialized CSV parsing functionality from `OllamaChat::Parsing`
27
+ module
28
+ - Handle nil from `STDIN.gets` to prevent `NoMethodError`
29
+
3
30
  ## 2026-01-08 v0.0.55
4
31
 
5
32
  - Added `OllamaChat::Vim` class for inserting text into Vim buffers using the
data/README.md CHANGED
@@ -151,6 +151,7 @@ subject - the young, blue-eyed cat.
151
151
  The following commands can be given inside the chat, if prefixed by a `/`:
152
152
 
153
153
  ```
154
+ /reconnect reconnect to current ollama server
154
155
  /copy to copy last response to clipboard
155
156
  /paste to paste content
156
157
  /markdown toggle markdown output
data/Rakefile CHANGED
@@ -58,7 +58,7 @@ GemHadar do
58
58
  dependency 'bigdecimal', '~> 3.1'
59
59
  dependency 'csv', '~> 3.0'
60
60
  dependency 'const_conf', '~> 0.3'
61
- dependency 'context_spook', '~> 1.1'
61
+ dependency 'context_spook', '~> 1.5'
62
62
  development_dependency 'all_images', '~> 0.6'
63
63
  development_dependency 'rspec', '~> 3.2'
64
64
  development_dependency 'kramdown', '~> 2.0'
@@ -88,15 +88,7 @@ class OllamaChat::Chat
88
88
  @ollama_chat_config = OllamaChat::OllamaChatConfig.new(@opts[?f])
89
89
  self.config = @ollama_chat_config.config
90
90
  setup_switches(config)
91
- base_url = @opts[?u] || OllamaChat::EnvConfig::OLLAMA::URL
92
- @ollama = Ollama::Client.new(
93
- connect_timeout: config.timeouts.connect_timeout?,
94
- read_timeout: config.timeouts.read_timeout?,
95
- write_timeout: config.timeouts.write_timeout?,
96
- base_url: base_url,
97
- debug: ,
98
- user_agent:
99
- )
91
+ @ollama = connect_ollama
100
92
  if server_version.version < '0.9.0'.version
101
93
  raise ArgumentError, 'require ollama API version 0.9.0 or higher'
102
94
  end
@@ -213,6 +205,11 @@ class OllamaChat::Chat
213
205
  # the content to be processed, or nil for no action needed
214
206
  def handle_input(content)
215
207
  case content
208
+ when %r(^/reconnect)
209
+ STDERR.print green { "Reconnecting to ollama #{base_url.to_s.inspect}…" }
210
+ @ollama = connect_ollama
211
+ STDERR.puts green { " Done." }
212
+ :next
216
213
  when %r(^/copy$)
217
214
  copy_to_clipboard
218
215
  :next
@@ -680,6 +677,21 @@ class OllamaChat::Chat
680
677
 
681
678
  private
682
679
 
680
+ def base_url
681
+ @opts[?u] || OllamaChat::EnvConfig::OLLAMA::URL
682
+ end
683
+
684
+ def connect_ollama
685
+ Ollama::Client.new(
686
+ connect_timeout: config.timeouts.connect_timeout?,
687
+ read_timeout: config.timeouts.read_timeout?,
688
+ write_timeout: config.timeouts.write_timeout?,
689
+ base_url: base_url,
690
+ debug: ,
691
+ user_agent:
692
+ )
693
+ end
694
+
683
695
  # The setup_documents method initializes the document processing pipeline by
684
696
  # configuring the embedding model and database connection.
685
697
  # It then loads specified documents into the system and returns the
@@ -76,7 +76,7 @@ module OllamaChat::Dialog
76
76
  # @return [ String ] the user's response with trailing newline removed
77
77
  def ask?(prompt:)
78
78
  print prompt
79
- STDIN.gets.chomp
79
+ STDIN.gets.to_s.chomp
80
80
  end
81
81
 
82
82
  # The choose_collection method presents a menu to select or create a document
@@ -118,6 +118,7 @@ module OllamaChat::Information
118
118
  # interface.
119
119
  private def display_chat_help_message
120
120
  <<~EOT
121
+ /reconnect reconnect to current ollama server
121
122
  /copy to copy last response to clipboard
122
123
  /paste to paste content
123
124
  /markdown toggle markdown output
@@ -8,35 +8,40 @@ require 'tempfile'
8
8
  # interactive file selection and context collection for enhancing chat
9
9
  # interactions with local or remote content.
10
10
  module OllamaChat::InputContent
11
- # The input method reads and returns the content of a selected file.
11
+ # The input method selects and reads content from files matching a pattern.
12
12
  #
13
- # This method searches for files matching the given pattern and presents them
14
- # in an interactive chooser menu. If a file is selected, its content is read
15
- # and returned. If the user chooses to exit or no file is selected, the
16
- # method returns nil.
13
+ # This method prompts the user to select files matching the given glob
14
+ # pattern, reads their content, and returns a concatenated string with each
15
+ # file's content preceded by its filename.
17
16
  #
18
- # @param pattern [ String ] the glob pattern to search for files (defaults to '**/*')
17
+ # @param pattern [String] the glob pattern to search for files (defaults to '**/*')
19
18
  #
20
- # @return [ String, nil ] the content of the selected file or nil if no file
21
- # was chosen
19
+ # @return [String] a concatenated string of file contents with filenames as headers
22
20
  def input(pattern)
23
21
  pattern ||= '**/*'
24
- if filename = choose_filename(pattern)
25
- File.read(filename)
22
+ files = Set[]
23
+ while filename = choose_filename(pattern, chosen: files)
24
+ files << filename
26
25
  end
26
+ result = ''
27
+ files.each do |filename|
28
+ result << ("%s:\n\n%s\n\n" % [ filename, File.read(filename) ])
29
+ end
30
+ result.full?
27
31
  end
28
32
 
29
- # The choose_filename method selects a file from a list of matching files.
30
- #
31
- # This method searches for files matching the given glob pattern, presents
32
- # them in an interactive chooser menu, and returns the selected filename. If
33
- # the user chooses to exit or no file is selected, the method returns nil.
33
+ # The choose_filename method selects a file from a list of matching files. It
34
+ # searches for files matching the given pattern, excludes already chosen
35
+ # files, and presents them in an interactive chooser menu.
34
36
  #
35
- # @param pattern [ String ] the glob pattern to search for files (defaults to '**/*')
37
+ # @param pattern [ String ] the glob pattern to search for files
38
+ # @param chosen [ Set ] a set of already chosen filenames to exclude from
39
+ # selection
36
40
  #
37
- # @return [ String, nil ] the path to the selected file or nil if no file was chosen
38
- def choose_filename(pattern)
39
- files = Dir.glob(pattern).select { File.file?(_1) }
41
+ # @return [ String, nil ] the selected filename or nil if no file was chosen or user exited
42
+ def choose_filename(pattern, chosen: nil)
43
+ files = Dir.glob(pattern).reject { chosen&.member?(_1) }.
44
+ select { File.file?(_1) }
40
45
  files.unshift('[EXIT]')
41
46
  case chosen = OllamaChat::Utils::Chooser.choose(files)
42
47
  when '[EXIT]', nil
@@ -75,8 +80,9 @@ module OllamaChat::InputContent
75
80
  # @example Load default context
76
81
  # context_spook(nil)
77
82
  def context_spook(patterns)
83
+ format = config.context.format
78
84
  if patterns
79
- ContextSpook::generate_context(verbose: true) do |context|
85
+ ContextSpook::generate_context(verbose: true, format:) do |context|
80
86
  context do
81
87
  Dir.glob(patterns).each do |filename|
82
88
  File.file?(filename) or next
@@ -86,7 +92,7 @@ module OllamaChat::InputContent
86
92
  end.to_json
87
93
  else
88
94
  if context_filename = choose_filename('.contexts/*.rb')
89
- ContextSpook.generate_context(context_filename, verbose: true).to_json
95
+ ContextSpook.generate_context(context_filename, verbose: true, format:).to_json
90
96
  end
91
97
  end
92
98
  end
@@ -43,6 +43,8 @@ stream: true
43
43
  document_policy: importing
44
44
  think: false
45
45
  think_loud: true
46
+ context:
47
+ format: JSON
46
48
  embedding:
47
49
  enabled: true
48
50
  paused: false
@@ -30,8 +30,6 @@ module OllamaChat::Parsing
30
30
  end
31
31
  source_io.rewind
32
32
  source_io.read
33
- when 'text/csv'
34
- parse_csv(source_io)
35
33
  when 'application/rss+xml'
36
34
  parse_rss(source_io)
37
35
  when 'application/atom+xml'
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.55'
3
+ VERSION = '0.0.56'
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:
data/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.55 ruby lib
2
+ # stub: ollama_chat 0.0.56 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.55".freeze
6
+ s.version = "0.0.56".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]
@@ -18,13 +18,13 @@ Gem::Specification.new do |s|
18
18
  s.licenses = ["MIT".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "OllamaChat - A command-line interface (CLI) for interacting with an Ollama AI model.".freeze, "--main".freeze, "README.md".freeze]
20
20
  s.required_ruby_version = Gem::Requirement.new(">= 3.2".freeze)
21
- s.rubygems_version = "4.0.2".freeze
21
+ s.rubygems_version = "4.0.3".freeze
22
22
  s.summary = "A command-line interface (CLI) for interacting with an Ollama AI model.".freeze
23
23
  s.test_files = ["spec/assets/example.rb".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/think_control_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze]
24
24
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.16.3".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.17.0".freeze])
28
28
  s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
30
30
  s.add_development_dependency(%q<kramdown>.freeze, ["~> 2.0".freeze])
@@ -50,5 +50,5 @@ Gem::Specification.new do |s|
50
50
  s.add_runtime_dependency(%q<bigdecimal>.freeze, ["~> 3.1".freeze])
51
51
  s.add_runtime_dependency(%q<csv>.freeze, ["~> 3.0".freeze])
52
52
  s.add_runtime_dependency(%q<const_conf>.freeze, ["~> 0.3".freeze])
53
- s.add_runtime_dependency(%q<context_spook>.freeze, ["~> 1.1".freeze])
53
+ s.add_runtime_dependency(%q<context_spook>.freeze, ["~> 1.5".freeze])
54
54
  end
@@ -28,6 +28,11 @@ describe OllamaChat::Chat, protect_env: true do
28
28
  describe 'handle_input' do
29
29
  connect_to_ollama_server
30
30
 
31
+ it 'returns :next when input is "/reconnect"' do
32
+ expect(chat).to receive(:connect_ollama).and_return double('ollama')
33
+ expect(chat.handle_input("/reconnect")).to eq :next
34
+ end
35
+
31
36
  it 'returns :next when input is "/copy"' do
32
37
  expect(chat).to receive(:copy_to_clipboard)
33
38
  expect(chat.handle_input("/copy")).to eq :next
@@ -9,9 +9,12 @@ describe OllamaChat::InputContent do
9
9
 
10
10
  describe '#input' do
11
11
  it 'can read content from a selected file' do
12
+ selected_filename = 'spec/assets/example.rb'
12
13
  # Mock the file selection process
13
- expect(chat).to receive(:choose_filename).with('**/*').
14
- and_return('spec/assets/example.rb')
14
+ expect(chat).to receive(:choose_filename).with('**/*', chosen: Set[]).
15
+ and_return(selected_filename)
16
+ expect(chat).to receive(:choose_filename).with('**/*', chosen: Set[selected_filename]).
17
+ and_return nil
15
18
 
16
19
  # Test that it returns the file content
17
20
  result = chat.input(nil)
@@ -19,13 +22,19 @@ describe OllamaChat::InputContent do
19
22
  end
20
23
 
21
24
  it 'returns nil when no file is selected' do
22
- expect(chat).to receive(:choose_filename).with('**/*').and_return(nil)
25
+ expect(chat).to receive(:choose_filename).with('**/*', chosen: Set[]).
26
+ and_return(nil)
23
27
  expect(chat.input(nil)).to be_nil
24
28
  end
25
29
 
26
30
  it 'can read content with specific pattern' do
27
- expect(chat).to receive(:choose_filename).with('spec/assets/*').
28
- and_return('spec/assets/example.rb')
31
+ selected_filename = 'spec/assets/example.rb'
32
+ expect(chat).to receive(:choose_filename).
33
+ with('spec/assets/*', chosen: Set[]).
34
+ and_return(selected_filename)
35
+ expect(chat).to receive(:choose_filename).
36
+ with('spec/assets/*', chosen: Set[selected_filename]).
37
+ and_return nil
29
38
  result = chat.input('spec/assets/*')
30
39
  expect(result).to include('puts "Hello World!"')
31
40
  end
@@ -49,24 +49,7 @@ describe OllamaChat::Parsing do
49
49
  def io.content_type
50
50
  'text/csv'
51
51
  end
52
- expect(chat.parse_source(io)).to eq(<<EOT)
53
- name: John Doe
54
- age: 32
55
- occupation: Software Engineer
56
-
57
- name: Jane Smith
58
- age: 28
59
- occupation: Marketing Manager
60
-
61
- name: Bob Johnson
62
- age: 45
63
- occupation: Retired
64
-
65
- name: Alice Brown
66
- age: 25
67
- occupation: Student
68
-
69
- EOT
52
+ expect(chat.parse_source(io)).to eq(asset_content('example.csv'))
70
53
  end
71
54
  end
72
55
 
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.55
4
+ version: 0.0.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 2.16.3
18
+ version: 2.17.0
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 2.16.3
25
+ version: 2.17.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: all_images
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -385,14 +385,14 @@ dependencies:
385
385
  requirements:
386
386
  - - "~>"
387
387
  - !ruby/object:Gem::Version
388
- version: '1.1'
388
+ version: '1.5'
389
389
  type: :runtime
390
390
  prerelease: false
391
391
  version_requirements: !ruby/object:Gem::Requirement
392
392
  requirements:
393
393
  - - "~>"
394
394
  - !ruby/object:Gem::Version
395
- version: '1.1'
395
+ version: '1.5'
396
396
  description: |
397
397
  The app provides a command-line interface (CLI) to an Ollama AI model,
398
398
  allowing users to engage in text-based conversations and generate
@@ -547,7 +547,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
547
547
  - !ruby/object:Gem::Version
548
548
  version: '0'
549
549
  requirements: []
550
- rubygems_version: 4.0.2
550
+ rubygems_version: 4.0.3
551
551
  specification_version: 4
552
552
  summary: A command-line interface (CLI) for interacting with an Ollama AI model.
553
553
  test_files: