ollama_chat 0.0.27 → 0.0.29

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: c2155f3ea224b97ac3a471848b53530b60308b685b21804a23138ce31e752891
4
- data.tar.gz: f96db1b34a1d1a95bad394d6c0ac0ba43f7bc1c481344aa7d0d19565c4889149
3
+ metadata.gz: c4521bf944235fe5a3507f46e8c1ff8016faab3c178c2c8981d223c02c32ad1e
4
+ data.tar.gz: 8266fb46c588c5e456c00574a2c291b89da9aab453e8d33690a32c9b5e23762a
5
5
  SHA512:
6
- metadata.gz: 6dfc776afc77a3cfdb3b5ab6d6d4d41e188345c15d4e8341495c00e90d4c03aefef4ac01af1d8ffae4b1a20deb11c8cfe3f063e8d4d11c53aaa8253fd66d5466
7
- data.tar.gz: aee0b2f2fe0a17af19d09384df6dca08a3848fb6ebea981d71f93f1e8dc56858e6e293619b1755ea97aaefd2f7174925d50387cb5b9782c976ef477270d4e373
6
+ metadata.gz: b3bf3bc435c932230a7ac671f52fb41890abf8e673dd31bf8784eac721ef859e7726c06a164f5a15f7a474351274213bbbd82fe8973c9340ef3cd5463343799d
7
+ data.tar.gz: 7a05cc98e971adaac2e1ae834ac732533bfea925bc6c7e084068bad4dc4fc16292f3eac936406ff8abca9253cafc5b61f61f1597af8945595bd62a0084c85aba
data/.utilsrc ADDED
@@ -0,0 +1,68 @@
1
+ # vim: set ft=ruby:
2
+
3
+ search do
4
+ prune_dirs /\A(\.svn|\.git|\.terraform|CVS|tmp|coverage|corpus|pkg|\.yardoc|doc)\z/
5
+ skip_files /(\A\.|\.sw[pon]\z|\.(log|fnm|jpg|jpeg|png|pdf|svg)\z|\A(tags|cscope\.out)\z|~\z)/i
6
+ end
7
+
8
+ discover do
9
+ prune_dirs /\A(\.svn|\.git|\.terraform|\.yardoc|CVS|tmp|coverage|corpus|pkg|\.yardoc|doc)\z/
10
+ skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
11
+ index_expire_after 3_600
12
+ end
13
+
14
+ strip_spaces do
15
+ prune_dirs /\A(\..*|CVS|pkg|\.yardoc)\z/
16
+ skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
17
+ end
18
+
19
+ probe do
20
+ test_framework :rspec
21
+ end
22
+
23
+ ssh_tunnel do
24
+ terminal_multiplexer :tmux
25
+ login_session "/home/#{ENV['USER']}"
26
+ end
27
+
28
+ classify do
29
+ shift_path_by_default 1
30
+ end
31
+
32
+ code_indexer do
33
+ verbose false
34
+
35
+ gems = %w[
36
+ amatch
37
+ base64
38
+ bigdecimal
39
+ complex_config
40
+ date
41
+ documentrix
42
+ excon
43
+ json
44
+ kramdown-ansi
45
+ mize
46
+ more_math
47
+ ollama-ruby
48
+ ostruct
49
+ reverse_markdown
50
+ rspec
51
+ rspec-core
52
+ rspec-expectations
53
+ rspec-mocks
54
+ rspec-support
55
+ search_ui
56
+ sqlite3
57
+ stringio
58
+ term-ansicolor
59
+ tins
60
+ unix_socks
61
+ webmock
62
+ xdg
63
+ ]
64
+
65
+ paths {
66
+ %w[ lib ] + gems.map { `bundle show #{it}` }.map(&:chomp)
67
+ }
68
+ end
data/CHANGES.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-09-08 v0.0.29
4
+
5
+ - Refactored conversation persistence into a dedicated
6
+ `OllamaChat::Conversation` module
7
+ - Added automatic backup saving in the `fix_config` method using
8
+ **backup.json**
9
+ - Simplified `/save` and `/load` commands to delegate to module methods
10
+ - Introduced document processing policies for web search results with three
11
+ modes: **embedding**, **summarizing**, and **importing**
12
+ - Added `@document_policy` configuration to control result processing mode
13
+ - Updated `/web` command help text and added new prompt templates for summarization and importing modes
14
+ - Modified conditional logic from `@embedding.on?` to `@document_policy == 'embedding' && @embedding.on?`
15
+
16
+ ## 2025-09-08 v0.0.28
17
+
18
+ - Replaced `server_socket_runtime_dir` config option with
19
+ `working_dir_dependent_socket`
20
+ - Used `Digest::MD5` to generate unique socket names based on working directory
21
+ - Socket names now follow format `ollama_chat-<hash>.sock` instead of fixed
22
+ name
23
+ - Updated `unix_socks` dependency version constraint from >= 0.0.1 to ~> 0.1
24
+ - Added new `.utilsrc` configuration file for code indexing and search
25
+ utilities
26
+ - Added return type documentation to `CacheFetcher#get` method
27
+
3
28
  ## 2025-09-05 v0.0.27
4
29
 
5
30
  - Enhanced cache hit notifications to properly handle content type with
@@ -49,22 +74,31 @@
49
74
  ## 2025-08-17 v0.0.24
50
75
 
51
76
  - Updated `kramdown-ansi` dependency version constraint from **0.0** to **0.1**
52
- - Modified both Rakefile and ollama_chat.gemspec files to reflect new version
77
+ - Modified both Rakefile and `ollama_chat.gemspec` files to reflect new version
53
78
  constraint for `kramdown-ansi`
54
79
 
55
80
  ## 2025-08-17 v0.0.23
56
81
 
57
- - Added `OllamaChat::KramdownANSI` module with `configure_kramdown_ansi_styles` and `kramdown_ansi_parse` methods for consistent Markdown formatting
58
- - Replaced direct calls to `Kramdown::ANSI.parse` with `@chat.kramdown_ansi_parse` in `FollowChat` and `MessageList`
82
+ - Added `OllamaChat::KramdownANSI` module with `configure_kramdown_ansi_styles`
83
+ and `kramdown_ansi_parse` methods for consistent Markdown formatting
84
+ - Replaced direct calls to `Kramdown::ANSI.parse` with
85
+ `@chat.kramdown_ansi_parse` in `FollowChat` and `MessageList`
59
86
  - Integrated `OllamaChat::KramdownANSI` module into `OllamaChat::Chat` class
60
87
  - Configured `@kramdown_ansi_styles` during chat initialization
61
- - Added support for environment variables `KRAMDOWN_ANSI_OLLAMA_CHAT_STYLES` and `KRAMDOWN_ANSI_STYLES` for styling configuration
62
- - Updated tests to mock `kramdown_ansi_parse` instead of direct `Kramdown::ANSI.parse`
63
- - Documented environment variables for customizing Markdown formatting with example JSON format
64
- - Added `lib/ollama_chat/kramdown_ansi.rb` to `extra_rdoc_files` and `files` list in gemspec
65
- - Escaped dot in regex pattern in `parsing_spec.rb` for proper image file matching
66
- - Implemented `File.expand_path` to resolve `~` shortcuts before existence check in parsing module
67
- - Added error handling for malformed paths by rescuing `ArgumentError` exceptions
88
+ - Added support for environment variables `KRAMDOWN_ANSI_OLLAMA_CHAT_STYLES`
89
+ and `KRAMDOWN_ANSI_STYLES` for styling configuration
90
+ - Updated tests to mock `kramdown_ansi_parse` instead of direct
91
+ `Kramdown::ANSI.parse`
92
+ - Documented environment variables for customizing Markdown formatting with
93
+ example JSON format
94
+ - Added `lib/ollama_chat/kramdown_ansi.rb` to `extra_rdoc_files` and `files`
95
+ list in gemspec
96
+ - Escaped dot in regex pattern in `parsing_spec.rb` for proper image file
97
+ matching
98
+ - Implemented `File.expand_path` to resolve `~` shortcuts before existence
99
+ check in parsing module
100
+ - Added error handling for malformed paths by rescuing `ArgumentError`
101
+ exceptions
68
102
  - Skipped invalid file paths during processing loop using `next` statement
69
103
  - Maintained backward compatibility for standard file paths
70
104
  - Added comprehensive list of supported environment variables in documentation
@@ -72,14 +106,19 @@
72
106
  ## 2025-08-13 v0.0.22
73
107
 
74
108
  - Added new `-p` command line flag for enabling source parsing functionality
75
- - Enhanced `send_to_server_socket` method to accept and pass a `parse` parameter
109
+ - Enhanced `send_to_server_socket` method to accept and pass a `parse`
110
+ parameter
76
111
  - Modified `chat.rb` to handle the `parse` content flag from server messages
77
112
  - Updated documentation in `README.md` with example usage of the new `-p` flag
78
- - Added comprehensive tests for the new parsing functionality in `server_socket_spec.rb`
79
- - Improved method documentation in `server_socket.rb` with detailed parameter descriptions
80
- - Replaced `messages.list_conversation(2)` with `messages.show_last` in `/drop` command behavior
113
+ - Added comprehensive tests for the new parsing functionality in
114
+ `server_socket_spec.rb`
115
+ - Improved method documentation in `server_socket.rb` with detailed parameter
116
+ descriptions
117
+ - Replaced `messages.list_conversation(2)` with `messages.show_last` in `/drop`
118
+ command behavior
81
119
  - Updated `gem_hadar` development dependency from version **1.27** to **2.0**
82
- - Simplified SimpleCov setup by using `GemHadar::SimpleCov.start` instead of manual configuration
120
+ - Simplified SimpleCov setup by using `GemHadar::SimpleCov.start` instead of
121
+ manual configuration
83
122
 
84
123
  ## 2025-08-11 v0.0.21
85
124
 
@@ -101,7 +140,8 @@
101
140
 
102
141
  ### Documentation
103
142
 
104
- - Added more YARD-style documentation to all public methods throughout the codebase.
143
+ - Added more YARD-style documentation to all public methods throughout the
144
+ codebase.
105
145
 
106
146
  ### Fixed
107
147
 
@@ -174,8 +214,10 @@
174
214
  - **Enhancements**
175
215
  - Improved logging with debug output for received server socket messages.
176
216
  - Refactored server socket handling:
177
- - Created `create_socket_server` method for UnixSocks setup with configurable runtime directories.
178
- - Updated `send_to_server_socket` and `init_server_socket` methods to use the new helper.
217
+ - Created `create_socket_server` method for UnixSocks setup with
218
+ configurable runtime directories.
219
+ - Updated `send_to_server_socket` and `init_server_socket` methods to use
220
+ the new helper.
179
221
  - Changed evaluation rate metrics from 'c/s' to 't/s' for better clarity.
180
222
 
181
223
  - **Documentation**
@@ -233,37 +275,48 @@
233
275
 
234
276
  * **Think Mode Implementation**:
235
277
  + Introduced `@think_mode` attribute to read think mode setting from config
236
- + Implemented `remove_think_blocks` method to filter out thought blocks from chat messages sent to the LLM model.
237
- + Added conditional logic based on `@think_mode` value to handle different modes
278
+ + Implemented `remove_think_blocks` method to filter out thought blocks from
279
+ chat messages sent to the LLM model.
280
+ + Added conditional logic based on `@think_mode` value to handle different
281
+ modes
238
282
  * **User Interface Improvements**:
239
283
  + Added `/think_mode` command to help users understand think mode options
240
284
  + Updated session output to include current think mode
241
- + Added think mode chooser to OllamaChat::Dialog, allowing users to select their preferred think mode
285
+ + Added think mode chooser to OllamaChat::Dialog, allowing users to select
286
+ their preferred think mode
242
287
  * **Output Handling Enhancements**:
243
288
  + Improved markdown handling for think blocks in OllamaChat::FollowChat class
244
- + Modified output to print clear screen, move home, and user info before printing content
289
+ + Modified output to print clear screen, move home, and user info before
290
+ printing content
245
291
  * **Configuration Updates**:
246
292
  + Added `think_mode` key with value `"display"` to `default_config.yml`
247
293
 
248
294
  ## 2025-05-28 v0.0.10
249
295
 
250
296
  * Simplify and improve command handling logic.
251
- * Update chat input handling to use a single `handle_input` method for all commands.
297
+ * Update chat input handling to use a single `handle_input` method for all
298
+ commands.
252
299
  * Add tests for various chat commands, including input handling, document
253
300
  policy selection, summarization, and more.
254
- * Improve test coverage for `DocumentCache`, `Information`, and other modules.
255
- * Improved handling of commands, e.g. **don't** when sending via `ollama_chat_send` by default.
301
+ * Improve test coverage for `DocumentCache`, `Information`, and other
302
+ modules.
303
+ * Improved handling of commands, e.g. **don't** when sending via
304
+ `ollama_chat_send` by default.
256
305
  * Added support for sending content to server socket with specific type.
257
306
 
258
307
  ## 2025-05-26 v0.0.9
259
308
 
260
309
  * Improved tag parsing in OllamaChat:
261
310
  * Added regex validation for valid tags to `Documentrix::Utils::Tags`.
262
- * Modified `parse_content` method in `OllamaChat::Parsing` to handle valid tag formats.
263
- * Updated `scan` methods in `content` processing to more correctly identify tags.
264
- * Added option to explicitly open socket for receiving input from `ollama_chat_send`:
311
+ * Modified `parse_content` method in `OllamaChat::Parsing` to handle valid
312
+ tag formats.
313
+ * Updated `scan` methods in `content` processing to more correctly identify
314
+ tags.
315
+ * Added option to explicitly open socket for receiving input from
316
+ `ollama_chat_send`:
265
317
  * Added new command-line option `-S` to enable server socket functionality.
266
- * Updated `OllamaChat::Chat` class to include server socket initialization based on the new option.
318
+ * Updated `OllamaChat::Chat` class to include server socket initialization
319
+ based on the new option.
267
320
  * Modified usage message in `README.md` and `information.rb` files.
268
321
 
269
322
  ## 2025-05-23 v0.0.8
@@ -305,9 +358,12 @@
305
358
  ## 2025-04-15 v0.0.6
306
359
 
307
360
  * Updated Rakefile to use `ollama-ruby` version **1.0**.
308
- * Modified `model_present?` method in `lib/ollama_chat/model_handling.rb` to use `ollama.show(model:)`.
309
- * Changed `pull_model_from_remote` method in `lib/ollama_chat/model_handling.rb` to use `ollama.pull(model:).
310
- * Updated `ollama_chat.gemspec` to use `ollama-ruby` version **1.0** and updated date to **2025-04-14**.
361
+ * Modified `model_present?` method in `lib/ollama_chat/model_handling.rb` to
362
+ use `ollama.show(model:)`.
363
+ * Changed `pull_model_from_remote` method in
364
+ `lib/ollama_chat/model_handling.rb` to use `ollama.pull(model:).
365
+ * Updated `ollama_chat.gemspec` to use `ollama-ruby` version **1.0** and
366
+ updated date to **2025-04-14**.
311
367
  * Attempt to capture stderr as well by redirecting stderr to stdout for
312
368
  commands that output to it always or in the error case.
313
369
  * Updated development dependencies in `ollama_chat.gemspec`.
@@ -316,7 +372,8 @@
316
372
 
317
373
  * Updated default config to use environment variable for Searxng URL:
318
374
  * Changed `url` field in `searxng` section of `default_config.yml`.
319
- * Replaced hardcoded URL with expression that fetches value from `OLLAMA_SEARXNG_URL` environment variable.
375
+ * Replaced hardcoded URL with expression that fetches value from
376
+ `OLLAMA_SEARXNG_URL` environment variable.
320
377
  * Handle Ollama server disconnection:
321
378
  * Added error handling for `Ollama::Errors::TimeoutError`.
322
379
  * Print error message when connection is lost.
@@ -336,18 +393,23 @@
336
393
  for web searching with all engines.
337
394
  + Updated `ollama_chat/chat.rb` to use the new `web_searching` module and
338
395
  updated the `search_web` method to return results from either engine.
339
- + Added specs in `spec/ollama_chat/web_searching_spec.rb` to test the new functionality.
396
+ + Added specs in `spec/ollama_chat/web_searching_spec.rb` to test the new
397
+ functionality.
340
398
  * Added ollama chat version display to information module and spec:
341
- + Added `STDOUT.puts` for displaying ollama chat version in `lib/ollama_chat/information.rb`
342
- + Updated test in `spec/ollama_chat/chat_spec.rb` to include new output string
399
+ + Added `STDOUT.puts` for displaying ollama chat version in
400
+ `lib/ollama_chat/information.rb`
401
+ + Updated test in `spec/ollama_chat/chat_spec.rb` to include new output
402
+ string
343
403
  * Update chat document redis cache expiration time default to 0.
344
404
 
345
405
  ## 2025-02-17 v0.0.3
346
406
 
347
407
  * Support setting of request headers:
348
408
  * Added `request_headers` option to `default_config.yml
349
- * Updated `OllamaChat::SourceFetching` module to pass `config.request_headers?.to_h` to `Fetcher.get`
350
- * Updated `OllamaChat::Utils::Fetcher.get` method to take an optional `headers:` parameter
409
+ * Updated `OllamaChat::SourceFetching` module to pass
410
+ `config.request_headers?.to_h` to `Fetcher.get`
411
+ * Updated `OllamaChat::Utils::Fetcher.get` method to take an optional
412
+ `headers:` parameter
351
413
  * Updated tests for Fetcher utility to include new headers option
352
414
  * Refactoring
353
415
  * Added `connect_to_ollama_server` method to `spec_helper.rb`
@@ -379,8 +441,10 @@
379
441
  ## 2025-02-02 v0.0.1
380
442
 
381
443
  * Renamed `documents` variable to `@documents` in `OllamaChat::Chat`
382
- * Modified `add_documents_from_argv` method to accept only `document_list` as argument
383
- * Updated spec for `OllamaChat::Chat` to reflect changes in `add_documents_from_argv` method
444
+ * Modified `add_documents_from_argv` method to accept only `document_list`
445
+ as argument
446
+ * Updated spec for `OllamaChat::Chat` to reflect changes in
447
+ `add_documents_from_argv` method
384
448
  * Use `clamp(1..)` instead of manual checks for `n.to_i` in source fetching
385
449
  * Dropped is now used consistently in the code for message popping
386
450
  * Set up Redis environment and service for development:
data/README.md CHANGED
@@ -171,7 +171,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
171
171
  /summarize [n] source summarize the source's content in n words
172
172
  /embedding toggle embedding paused or not
173
173
  /embed source embed the source's content
174
- /web [n] query query web search & return n or 1 results
174
+ /web [n] query query web & for n(=1) results (policy: importing)
175
175
  /links [clear] display (or clear) links used in the chat
176
176
  /save filename store conversation messages
177
177
  /load filename load conversation messages
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ GemHadar do
36
36
  dependency 'excon', '~> 1.0'
37
37
  dependency 'ollama-ruby', '~> 1.6'
38
38
  dependency 'documentrix', '~> 0.0', '>= 0.0.2'
39
- dependency 'unix_socks', '>= 0.0.1'
39
+ dependency 'unix_socks', '~> 0.1'
40
40
  dependency 'rss', '~> 0.3'
41
41
  dependency 'term-ansicolor', '~> 1.11'
42
42
  dependency 'redis', '~> 5.0'
@@ -48,6 +48,7 @@ class OllamaChat::Chat
48
48
  include OllamaChat::History
49
49
  include OllamaChat::ServerSocket
50
50
  include OllamaChat::KramdownANSI
51
+ include OllamaChat::Conversation
51
52
 
52
53
  # Initializes a new OllamaChat::Chat instance with the given command-line
53
54
  # arguments.
@@ -312,27 +313,13 @@ class OllamaChat::Chat
312
313
  @parse_content = false
313
314
  web($1, $2)
314
315
  when %r(^/save\s+(.+)$)
315
- filename = $1
316
- if messages.save_conversation(filename)
317
- STDOUT.puts "Saved conversation to #{filename.inspect}."
318
- else
319
- STDERR.puts "Saving conversation to #{filename.inspect} failed."
320
- end
316
+ save_conversation($1)
321
317
  :next
322
318
  when %r(^/links(?:\s+(clear))?$)
323
319
  manage_links($1)
324
320
  :next
325
321
  when %r(^/load\s+(.+)$)
326
- filename = $1
327
- success = messages.load_conversation(filename)
328
- if messages.size > 1
329
- messages.list_conversation(2)
330
- end
331
- if success
332
- STDOUT.puts "Loaded conversation from #{filename.inspect}."
333
- else
334
- STDERR.puts "Loading conversation from #{filename.inspect} failed."
335
- end
322
+ load_conversation($1)
336
323
  :next
337
324
  when %r(^/pipe\s+(.+)$)
338
325
  pipe($1)
@@ -362,31 +349,60 @@ class OllamaChat::Chat
362
349
  end
363
350
  end
364
351
 
365
- # The web method performs a web search and processes the results based on
366
- # embedding configuration.
367
- #
368
- # It searches for the given query using the configured search engine and
369
- # processes up to the specified number of URLs. If embeddings are enabled, it
370
- # embeds each result and interpolates the query into the web_embed prompt.
371
- # Otherwise, it imports each result and interpolates both the query and
372
- # results into the web_import prompt.
373
- #
374
- # @param count [ String ] the maximum number of search results to process
375
- # @param query [ String ] the search query string
376
- #
377
- # @return [ String, Symbol ] the interpolated prompt content or :next if no URLs were found
352
+ # Performs a web search and processes the results based on document processing configuration.
353
+ #
354
+ # Searches for the given query using the configured search engine and processes up to
355
+ # the specified number of URLs. The processing approach varies based on the current
356
+ # document policy and embedding status:
357
+ #
358
+ # - **Embedding mode**: When `@document_policy == 'embedding'` AND `@embedding.on?` is true,
359
+ # each result is embedded and the query is interpolated into the `web_embed` prompt.
360
+ # - **Summarizing mode**: When `@document_policy == 'summarizing'`,
361
+ # each result is summarized and both query and results are interpolated into the
362
+ # `web_summarize` prompt.
363
+ # - **Importing mode**: For all other cases, each result is imported and both query and
364
+ # results are interpolated into the `web_import` prompt.
365
+ #
366
+ # @param count [String] The maximum number of search results to process (defaults to 1)
367
+ # @param query [String] The search query string
368
+ #
369
+ # @return [String, Symbol] The interpolated prompt content when successful,
370
+ # or :next if no URLs were found or processing failed
371
+ #
372
+ # @example Basic web search
373
+ # web('3', 'ruby programming tutorials')
374
+ #
375
+ # @example Web search with embedding policy
376
+ # # With @document_policy == 'embedding' and @embedding.on?
377
+ # # Processes results through embedding pipeline
378
+ #
379
+ # @example Web search with summarizing policy
380
+ # # With @document_policy == 'summarizing'
381
+ # # Processes results through summarization pipeline
382
+ #
383
+ # @see #search_web
384
+ # @see #fetch_source
385
+ # @see #embed_source
386
+ # @see #import
387
+ # @see #summarize
378
388
  def web(count, query)
379
389
  urls = search_web(query, count.to_i) or return :next
380
- if @embedding.on?
390
+ if @document_policy == 'embedding' && @embedding.on?
381
391
  prompt = config.prompts.web_embed
382
392
  urls.each do |url|
383
393
  fetch_source(url) { |url_io| embed_source(url_io, url) }
384
394
  end
385
395
  prompt.named_placeholders_interpolate({query:})
396
+ elsif @document_policy == 'summarizing'
397
+ prompt = config.prompts.web_summarize
398
+ results = urls.each_with_object('') do |url, content|
399
+ import(url).full? { |c| content << c }
400
+ end
401
+ prompt.named_placeholders_interpolate({query:, results:})
386
402
  else
387
403
  prompt = config.prompts.web_import
388
404
  results = urls.each_with_object('') do |url, content|
389
- import(url).full? { |c| content << c }
405
+ summarize(url).full? { |c| content << c }
390
406
  end
391
407
  prompt.named_placeholders_interpolate({query:, results:})
392
408
  end
@@ -727,6 +743,7 @@ class OllamaChat::Chat
727
743
  # @param exception [ Exception ] the exception that occurred while reading
728
744
  # the config file
729
745
  def fix_config(exception)
746
+ save_conversation('backup.json')
730
747
  STDOUT.puts "When reading the config file, a #{exception.class} "\
731
748
  "exception was caught: #{exception.message.inspect}"
732
749
  if ask?(prompt: 'Do you want to fix the config? (y/n) ') =~ /\Ay/i
@@ -0,0 +1,58 @@
1
+ # A module that provides conversation persistence functionality for the
2
+ # OllamaChat::Chat class.
3
+ #
4
+ # This module encapsulates the logic for saving and loading chat conversations
5
+ # to/from JSON files. It delegates the actual file operations to the `messages`
6
+ # object, which is expected to respond to `save_conversation` and
7
+ # `load_conversation` methods.
8
+ #
9
+ # @example Save a conversation
10
+ # chat.save_conversation('my_chat.json')
11
+ #
12
+ # @example Load a conversation
13
+ # chat.load_conversation('my_chat.json')
14
+ module OllamaChat::Conversation
15
+ # Saves the current conversation to a JSON file.
16
+ #
17
+ # This method delegates to the `messages` object's `save_conversation`
18
+ # method, which handles the actual serialization of messages into JSON
19
+ # format.
20
+ #
21
+ # @param filename [String] The path to the file where the conversation should
22
+ # be saved
23
+ #
24
+ # @example Save conversation with explicit filename
25
+ # chat.save_conversation('conversations/2023-10-15_my_session.json')
26
+ def save_conversation(filename)
27
+ if messages.save_conversation(filename)
28
+ STDOUT.puts "Saved conversation to #{filename.inspect}."
29
+ else
30
+ STDERR.puts "Saving conversation to #{filename.inspect} failed."
31
+ end
32
+ end
33
+
34
+ # Loads a conversation from a JSON file and replaces the current message
35
+ # history.
36
+ #
37
+ # This method delegates to the `messages` object's `load_conversation`
38
+ # method, which handles deserialization of messages from JSON format. After
39
+ # loading, if there are more than one message, it lists the last two messages
40
+ # for confirmation.
41
+ #
42
+ # @param filename [String] The path to the file containing the conversation
43
+ # to load
44
+ #
45
+ # @example Load a conversation from a specific file
46
+ # chat.load_conversation('conversations/2023-10-15_my_session.json')
47
+ def load_conversation(filename)
48
+ success = messages.load_conversation(filename)
49
+ if messages.size > 1
50
+ messages.list_conversation(2)
51
+ end
52
+ if success
53
+ STDOUT.puts "Loaded conversation from #{filename.inspect}."
54
+ else
55
+ STDERR.puts "Loading conversation from #{filename.inspect} failed."
56
+ end
57
+ end
58
+ end
@@ -141,7 +141,7 @@ module OllamaChat::Information
141
141
  /summarize [n] source summarize the source's content in n words
142
142
  /embedding toggle embedding paused or not
143
143
  /embed source embed the source's content
144
- /web [n] query query web search & return n or 1 results
144
+ /web [n] query query web & for n(=1) results (policy: #@document_policy)
145
145
  /links [clear] display (or clear) links used in the chat
146
146
  /save filename store conversation messages
147
147
  /load filename load conversation messages
@@ -24,7 +24,11 @@ prompts:
24
24
  web_embed: |
25
25
  Answer the the query %{query} using the provided chunks.
26
26
  web_import: |
27
- Answer the the query %{query} using these imported source:
27
+ Answer the the query %{query} using these imported sources:
28
+
29
+ %{results}
30
+ web_summarize: |
31
+ Answer the the query %{query} using these summarized sources:
28
32
 
29
33
  %{results}
30
34
  location: You are at %{location_name}, %{location_decimal_degrees}, on %{localtime}, preferring %{units}
@@ -64,7 +68,7 @@ redis:
64
68
  url: <%= ENV.fetch('REDIS_EXPIRING_URL', 'null') %>
65
69
  ex: 86400
66
70
  chat_history_filename: <%= ENV.fetch('OLLAMA_CHAT_HISTORY', '~/.ollama_chat_history') %>
67
- server_socket_runtime_dir: .
71
+ working_dir_dependent_socket: true
68
72
  debug: <%= ENV['OLLAMA_CHAT_DEBUG'].to_i == 1 ? true : false %>
69
73
  request_headers:
70
74
  Accept: 'text/*,application/*,image/*'
@@ -1,3 +1,5 @@
1
+ require 'digest/md5'
2
+
1
3
  # A module that provides server socket functionality for OllamaChat
2
4
  #
3
5
  # The ServerSocket module encapsulates the logic for creating and managing Unix
@@ -70,8 +72,10 @@ module OllamaChat::ServerSocket
70
72
  if runtime_dir
71
73
  return UnixSocks::Server.new(socket_name: 'ollama_chat.sock', runtime_dir:)
72
74
  end
73
- if runtime_dir = config.server_socket_runtime_dir
74
- UnixSocks::Server.new(socket_name: 'ollama_chat.sock', runtime_dir:)
75
+ if config.working_dir_dependent_socket
76
+ path = File.expand_path(Dir.pwd)
77
+ digest = Digest::MD5.hexdigest(path)
78
+ UnixSocks::Server.new(socket_name: "ollama_chat-#{digest}.sock")
75
79
  else
76
80
  UnixSocks::Server.new(socket_name: 'ollama_chat.sock')
77
81
  end
@@ -34,6 +34,7 @@ class OllamaChat::Utils::CacheFetcher
34
34
  # @param url [ String ] the URL used as a key for caching
35
35
  #
36
36
  # @yield [ io ] yields the cached IO object if found
37
+ # @return [ io ] the cached IO object if found
37
38
  def get(url, &block)
38
39
  block or raise ArgumentError, 'require block argument'
39
40
  body = @cache[key(:body, url)]
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.27'
3
+ VERSION = '0.0.29'
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/lib/ollama_chat.rb CHANGED
@@ -33,4 +33,5 @@ require 'ollama_chat/document_cache'
33
33
  require 'ollama_chat/history'
34
34
  require 'ollama_chat/server_socket'
35
35
  require 'ollama_chat/kramdown_ansi'
36
+ require 'ollama_chat/conversation'
36
37
  require 'ollama_chat/chat'
data/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.27 ruby lib
2
+ # stub: ollama_chat 0.0.29 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.27".freeze
6
+ s.version = "0.0.29".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]
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = "The app provides a command-line interface (CLI) to an Ollama AI model,\nallowing users to engage in text-based conversations and generate\nhuman-like responses. Users can import data from local files or web pages,\nwhich are then processed through three different modes: fully importing the\ncontent into the conversation context, summarizing the information for\nconcise reference, or storing it in an embedding vector database for later\nretrieval based on the conversation.\n".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ollama_chat".freeze, "ollama_chat_send".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze]
16
- s.files = ["CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".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/kramdown_ansi_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/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_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/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze]
16
+ s.files = [".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".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/kramdown_ansi_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/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_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/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
17
17
  s.homepage = "https://github.com/flori/ollama_chat".freeze
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]
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
36
36
  s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.6".freeze])
37
37
  s.add_runtime_dependency(%q<documentrix>.freeze, ["~> 0.0".freeze, ">= 0.0.2".freeze])
38
- s.add_runtime_dependency(%q<unix_socks>.freeze, [">= 0.0.1".freeze])
38
+ s.add_runtime_dependency(%q<unix_socks>.freeze, ["~> 0.1".freeze])
39
39
  s.add_runtime_dependency(%q<rss>.freeze, ["~> 0.3".freeze])
40
40
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
41
41
  s.add_runtime_dependency(%q<redis>.freeze, ["~> 5.0".freeze])
@@ -102,12 +102,11 @@ describe OllamaChat::ServerSocket do
102
102
  end
103
103
 
104
104
  describe '#create_socket_server' do
105
- context 'with configured runtime_dir' do
105
+ context 'with working dir dependent socket' do
106
106
  it 'can be created with configured runtime_dir' do
107
- config = double('Config', server_socket_runtime_dir: '/custom/runtime')
107
+ config = double('Config', working_dir_dependent_socket: true)
108
108
  expect(UnixSocks::Server).to receive(:new).with(
109
- socket_name: 'ollama_chat.sock',
110
- runtime_dir: '/custom/runtime'
109
+ socket_name: /\Aollama_chat-\h{32}.sock\z/,
111
110
  ).and_return :unix_socks_server
112
111
 
113
112
  result = OllamaChat::ServerSocket.create_socket_server(config: config)
@@ -115,9 +114,9 @@ describe OllamaChat::ServerSocket do
115
114
  end
116
115
  end
117
116
 
118
- context 'with default runtime_dir' do
117
+ context 'with default runtime_dir and name' do
119
118
  it 'can be created with default runtime_dir' do
120
- config = double('Config', server_socket_runtime_dir: nil)
119
+ config = double('Config', working_dir_dependent_socket: false)
121
120
  expect(UnixSocks::Server).to receive(:new).with(
122
121
  socket_name: 'ollama_chat.sock'
123
122
  ).and_return :unix_socks_server
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.27
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -173,16 +173,16 @@ dependencies:
173
173
  name: unix_socks
174
174
  requirement: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - ">="
176
+ - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 0.0.1
178
+ version: '0.1'
179
179
  type: :runtime
180
180
  prerelease: false
181
181
  version_requirements: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - ">="
183
+ - - "~>"
184
184
  - !ruby/object:Gem::Version
185
- version: 0.0.1
185
+ version: '0.1'
186
186
  - !ruby/object:Gem::Dependency
187
187
  name: rss
188
188
  requirement: !ruby/object:Gem::Requirement
@@ -389,6 +389,7 @@ extra_rdoc_files:
389
389
  - lib/ollama_chat.rb
390
390
  - lib/ollama_chat/chat.rb
391
391
  - lib/ollama_chat/clipboard.rb
392
+ - lib/ollama_chat/conversation.rb
392
393
  - lib/ollama_chat/dialog.rb
393
394
  - lib/ollama_chat/document_cache.rb
394
395
  - lib/ollama_chat/follow_chat.rb
@@ -413,6 +414,7 @@ extra_rdoc_files:
413
414
  - lib/ollama_chat/vim.rb
414
415
  - lib/ollama_chat/web_searching.rb
415
416
  files:
417
+ - ".utilsrc"
416
418
  - CHANGES.md
417
419
  - Gemfile
418
420
  - README.md
@@ -424,6 +426,7 @@ files:
424
426
  - lib/ollama_chat.rb
425
427
  - lib/ollama_chat/chat.rb
426
428
  - lib/ollama_chat/clipboard.rb
429
+ - lib/ollama_chat/conversation.rb
427
430
  - lib/ollama_chat/dialog.rb
428
431
  - lib/ollama_chat/document_cache.rb
429
432
  - lib/ollama_chat/follow_chat.rb