ollama_chat 0.0.7 → 0.0.9

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: b2f4b23386064513dc339fa0b3479e70c8e15b091b146bfcf700602fd1497b87
4
- data.tar.gz: ce9857a08de2bec94a1e19b5e28a13535657ebdab3ca977fe2b5582a86708bb7
3
+ metadata.gz: c66eb0eb6290d5161516ac786036a66c381339db5ea9a91039efc0c26b069591
4
+ data.tar.gz: a762ad194903ce17b01d07fa44af1b2e2fc832049ae5ec665da0236291a58561
5
5
  SHA512:
6
- metadata.gz: c7bcfbc3966c7189cc3d93b6ac3e09a49d79b1dd3bbfd5ed729a7ae5484ef7fcdadd194705363c574f18dd43f11c6c8d204577292516c3f9b286ba4380417e41
7
- data.tar.gz: 855accf3d5d72aa6c8a6cdd9fc8e534db40d97a4533bee03fc6a240cc5a12b8da46f304d02cf1c71378f592347866b84a95e9b18f9046975f630902996dd409a
6
+ metadata.gz: b133ad766292019028dc584a6197d8cc84503e8260307a9fbf141a9635a1b798bffe5f24dbe2de88c6a62408b51fbed0a9826fa0a9716fafc22c0b3c63092a2a
7
+ data.tar.gz: d200903b0f20a6135c8603f831e454fdcdbc272bf646984ca733566e932fa2590fb89848d7776e1ae2ac7f37143966b18b489c73ec30c1b56e348dbf154435e7
data/CHANGES.md CHANGED
@@ -1,8 +1,30 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-05-26 v0.0.9
4
+
5
+ * Improved tag parsing in OllamaChat:
6
+ * Added regex validation for valid tags to `Documentrix::Utils::Tags`.
7
+ * Modified `parse_content` method in `OllamaChat::Parsing` to handle valid tag formats.
8
+ * Updated `scan` methods in `content` processing to more correctly identify tags.
9
+ * Added option to explicitly open socket for receiving input from `ollama_chat_send`:
10
+ * Added new command-line option `-S` to enable server socket functionality.
11
+ * Updated `OllamaChat::Chat` class to include server socket initialization based on the new option.
12
+ * Modified usage message in `README.md` and `information.rb` files.
13
+
14
+ ## 2025-05-23 v0.0.8
15
+
16
+ * Introduce `fix_config` method to rescue `ComplexConfig` exceptions and prompt
17
+ user for correction.
18
+ * Added section to README.md on using `ollama_chat_send` to send input to a
19
+ running `ollama_chat` process.
20
+ * Fix path existence check and cleanup on server socket initialization.
21
+ * Added check for existing path at
22
+ `OllamaChat::ServerSocket.server_socket_path` to prevent overwrite.
23
+ * Clean up server socket file if it exists when leaving thread.
24
+
3
25
  ## 2025-05-22 v0.0.7
4
26
 
5
- * Added `ollama_chat_send` executable in `/bin`, required 'ollama_chat' gem,
27
+ * Added `ollama_chat_send` executable in `/bin`, required `ollama_chat` gem,
6
28
  sent user input to Ollama server via
7
29
  `OllamaChat::ServerSocket.send_to_server_socket` method and handled
8
30
  exceptions and exit with non-zero status code if an error occurs.
data/README.md CHANGED
@@ -31,6 +31,7 @@ Usage: ollama_chat [OPTIONS]
31
31
  -D DOCUMENT load document and add to embeddings collection (multiple)
32
32
  -M use (empty) MemoryCache for this chat session
33
33
  -E disable embeddings for this chat session
34
+ -S open a socket to receive input from ollama_chat_send
34
35
  -V display the current version number and quit
35
36
  -h this help
36
37
  ```
@@ -144,6 +145,27 @@ The following commands can be given inside the chat, if prefixed by a `/`:
144
145
  /help to view this help
145
146
  ```
146
147
 
148
+ ### Using `ollama_chat_send` to send input to a running `ollama_chat`
149
+
150
+ You can do this from the shell by pasting into the `ollama_chat_send`
151
+ executable.
152
+
153
+ ```
154
+ $ echo "Why is the sky blue?" | ollama_chat_send
155
+ ```
156
+
157
+ To send a text from inside a `vim` buffer, you can use a function/leader like
158
+ this:
159
+
160
+ ```
161
+ map <leader>o :<C-U>call OllamaChatSend(@*)<CR>
162
+
163
+ function! OllamaChatSend(input)
164
+ let input = "Take note of the following code snippet (" . &filetype . ") **AND** await further instructions:\n\n```\n" . a:input . "\n```\n"
165
+ call system('ollama_chat_send', input)
166
+ endfunction
167
+ ```
168
+
147
169
  ## Download
148
170
 
149
171
  The homepage of this app is located at
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ GemHadar do
31
31
 
32
32
  dependency 'excon', '~> 1.0'
33
33
  dependency 'ollama-ruby', '~> 1.0'
34
- dependency 'documentrix', '~> 0.0'
34
+ dependency 'documentrix', '~> 0.0', '>= 0.0.2'
35
35
  dependency 'rss', '~> 0.3'
36
36
  dependency 'term-ansicolor', '~> 1.11'
37
37
  dependency 'redis', '~> 5.0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.9
@@ -13,6 +13,7 @@ require 'pdf/reader'
13
13
  require 'csv'
14
14
  require 'xdg'
15
15
  require 'socket'
16
+ require 'shellwords'
16
17
 
17
18
  class OllamaChat::Chat
18
19
  include Tins::GO
@@ -31,7 +32,7 @@ class OllamaChat::Chat
31
32
  include OllamaChat::ServerSocket
32
33
 
33
34
  def initialize(argv: ARGV.dup)
34
- @opts = go 'f:u:m:s:c:C:D:MEVh', argv
35
+ @opts = go 'f:u:m:s:c:C:D:MESVh', argv
35
36
  @opts[?h] and exit usage
36
37
  @opts[?V] and exit version
37
38
  @ollama_chat_config = OllamaChat::OllamaChatConfig.new(@opts[?f])
@@ -66,7 +67,9 @@ class OllamaChat::Chat
66
67
  @current_voice = config.voice.default
67
68
  @images = []
68
69
  init_chat_history
69
- init_server_socket
70
+ @opts[?S] and init_server_socket
71
+ rescue ComplexConfig::AttributeMissing, ComplexConfig::ConfigurationSyntaxError => e
72
+ fix_config(e)
70
73
  end
71
74
 
72
75
  attr_reader :ollama
@@ -328,7 +331,7 @@ class OllamaChat::Chat
328
331
  content, tags = if parse_content
329
332
  parse_content(content, @images)
330
333
  else
331
- [ content, Documentrix::Utils::Tags.new ]
334
+ [ content, Documentrix::Utils::Tags.new(valid_tag: /\A#*([\w\]\[]+)/) ]
332
335
  end
333
336
 
334
337
  if embedding.on? && content
@@ -376,6 +379,8 @@ class OllamaChat::Chat
376
379
  STDOUT.puts "Type /quit to quit."
377
380
  end
378
381
  0
382
+ rescue ComplexConfig::AttributeMissing, ComplexConfig::ConfigurationSyntaxError => e
383
+ fix_config(e)
379
384
  ensure
380
385
  save_history
381
386
  end
@@ -445,4 +450,19 @@ class OllamaChat::Chat
445
450
  )
446
451
  end
447
452
  end
453
+
454
+ def fix_config(exception)
455
+ STDOUT.puts "When reading the config file, a #{exception.class} "\
456
+ "exception was caught: #{exception.message.inspect}"
457
+ if ask?(prompt: 'Do you want to fix the config? (y/n) ') =~ /\Ay/i
458
+ system Shellwords.join([
459
+ @ollama_chat_config.diff_tool,
460
+ @ollama_chat_config.filename,
461
+ @ollama_chat_config.default_config_path,
462
+ ])
463
+ exit 0
464
+ else
465
+ exit 1
466
+ end
467
+ end
448
468
  end
@@ -102,6 +102,7 @@ module OllamaChat::Information
102
102
  -D DOCUMENT load document and add to embeddings collection (multiple)
103
103
  -M use (empty) MemoryCache for this chat session
104
104
  -E disable embeddings for this chat session
105
+ -S open a socket to receive input from ollama_chat_send
105
106
  -V display the current version number and quit
106
107
  -h this help
107
108
 
@@ -4,9 +4,10 @@ class OllamaChat::OllamaChatConfig
4
4
  include ComplexConfig
5
5
  include FileUtils
6
6
 
7
- DEFAULT_CONFIG = File.read(
8
- Pathname.new(__FILE__).dirname.join('ollama_chat_config/default_config.yml')
9
- )
7
+ DEFAULT_CONFIG_PATH = Pathname.new(__FILE__).dirname.
8
+ join('ollama_chat_config/default_config.yml')
9
+
10
+ DEFAULT_CONFIG = File.read(DEFAULT_CONFIG_PATH)
10
11
 
11
12
  def initialize(filename = nil)
12
13
  @filename = filename || default_path
@@ -30,6 +31,10 @@ class OllamaChat::OllamaChatConfig
30
31
 
31
32
  attr_reader :config
32
33
 
34
+ def default_config_path
35
+ DEFAULT_CONFIG_PATH
36
+ end
37
+
33
38
  def default_path
34
39
  config_dir_path + 'config.yml'
35
40
  end
@@ -45,4 +50,8 @@ class OllamaChat::OllamaChatConfig
45
50
  def database_path
46
51
  cache_dir_path + 'documents.db'
47
52
  end
53
+
54
+ def diff_tool
55
+ ENV.fetch('DIFF_TOOL', 'vimdiff')
56
+ end
48
57
  end
@@ -113,10 +113,10 @@ module OllamaChat::Parsing
113
113
 
114
114
  def parse_content(content, images)
115
115
  images.clear
116
- tags = Documentrix::Utils::Tags.new
116
+ tags = Documentrix::Utils::Tags.new valid_tag: /\A#*([\w\]\[]+)/
117
117
 
118
118
  contents = [ content ]
119
- content.scan(%r((https?://\S+)|(#\S+)|(?:file://)?(\S*\/\S+))).each do |url, tag, file|
119
+ content.scan(%r((https?://\S+)|(?<![a-zA-Z\d])#+([\w\]\[]+)|(?:file://)?(\S*\/\S+))).each do |url, tag, file|
120
120
  case
121
121
  when tag
122
122
  tags.add(tag)
@@ -21,6 +21,9 @@ module OllamaChat::ServerSocket
21
21
 
22
22
  def init_server_socket
23
23
  FileUtils.mkdir_p OllamaChat::ServerSocket.runtime_dir
24
+ if File.exist?(OllamaChat::ServerSocket.server_socket_path)
25
+ raise Errno::EEXIST, "Path already exists #{OllamaChat::ServerSocket.server_socket_path.inspect}"
26
+ end
24
27
  Thread.new do
25
28
  Socket.unix_server_loop(OllamaChat::ServerSocket.server_socket_path) do |sock, client_addrinfo|
26
29
  begin
@@ -33,6 +36,8 @@ module OllamaChat::ServerSocket
33
36
  end
34
37
  end
35
38
  rescue Errno::ENOENT
39
+ ensure
40
+ FileUtils.rm_f OllamaChat::ServerSocket.server_socket_path
36
41
  end
37
42
  end
38
43
  end
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.9'
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.7 ruby lib
2
+ # stub: ollama_chat 0.0.9 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.7".freeze
6
+ s.version = "0.0.9".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]
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
34
34
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
35
35
  s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.0".freeze])
36
- s.add_runtime_dependency(%q<documentrix>.freeze, ["~> 0.0".freeze])
36
+ s.add_runtime_dependency(%q<documentrix>.freeze, ["~> 0.0".freeze, ">= 0.0.2".freeze])
37
37
  s.add_runtime_dependency(%q<rss>.freeze, ["~> 0.3".freeze])
38
38
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
39
39
  s.add_runtime_dependency(%q<redis>.freeze, ["~> 5.0".freeze])
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.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -142,6 +142,9 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0.0'
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 0.0.2
145
148
  type: :runtime
146
149
  prerelease: false
147
150
  version_requirements: !ruby/object:Gem::Requirement
@@ -149,6 +152,9 @@ dependencies:
149
152
  - - "~>"
150
153
  - !ruby/object:Gem::Version
151
154
  version: '0.0'
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: 0.0.2
152
158
  - !ruby/object:Gem::Dependency
153
159
  name: rss
154
160
  requirement: !ruby/object:Gem::Requirement