ollama_chat 0.0.68 → 0.0.69
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 +4 -4
- data/CHANGES.md +99 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/ollama_chat/chat.rb +30 -86
- data/lib/ollama_chat/clipboard.rb +2 -0
- data/lib/ollama_chat/config_handling.rb +99 -0
- data/lib/ollama_chat/conversation.rb +2 -0
- data/lib/ollama_chat/dialog.rb +7 -50
- data/lib/ollama_chat/document_cache.rb +2 -0
- data/lib/ollama_chat/env_config.rb +2 -2
- data/lib/ollama_chat/follow_chat.rb +8 -3
- data/lib/ollama_chat/history.rb +2 -0
- data/lib/ollama_chat/information.rb +2 -1
- data/lib/ollama_chat/input_content.rb +2 -0
- data/lib/ollama_chat/message_editing.rb +2 -0
- data/lib/ollama_chat/model_handling.rb +47 -0
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +63 -61
- data/lib/ollama_chat/ollama_chat_config.rb +1 -1
- data/lib/ollama_chat/server_socket.rb +2 -0
- data/lib/ollama_chat/switches.rb +13 -0
- data/lib/ollama_chat/tool_calling.rb +53 -11
- data/lib/ollama_chat/tools/directory_structure.rb +1 -1
- data/lib/ollama_chat/tools/execute_grep.rb +1 -1
- data/lib/ollama_chat/tools/file_context.rb +1 -1
- data/lib/ollama_chat/tools/get_current_weather.rb +1 -1
- data/lib/ollama_chat/tools/get_cve.rb +1 -1
- data/lib/ollama_chat/tools/get_endoflife.rb +1 -1
- data/lib/ollama_chat/tools/import_url.rb +1 -1
- data/lib/ollama_chat/tools/read_file.rb +1 -1
- data/lib/ollama_chat/tools/search_web.rb +1 -1
- data/lib/ollama_chat/tools/write_file.rb +1 -1
- data/lib/ollama_chat/utils/fetcher.rb +2 -2
- data/lib/ollama_chat/version.rb +1 -1
- data/lib/ollama_chat.rb +1 -0
- data/ollama_chat.gemspec +5 -5
- data/spec/ollama_chat/chat_spec.rb +2 -1
- data/spec/ollama_chat/clipboard_spec.rb +1 -1
- data/spec/ollama_chat/input_content_spec.rb +1 -1
- data/spec/ollama_chat/message_editing_spec.rb +1 -1
- data/spec/ollama_chat/model_handling_spec.rb +1 -1
- data/spec/ollama_chat/server_socket_spec.rb +1 -1
- data/spec/ollama_chat/source_fetching_spec.rb +1 -1
- data/spec/ollama_chat/tools/gem_path_lookup_spec.rb +3 -28
- data/spec/ollama_chat/tools/get_cve_spec.rb +2 -2
- data/spec/ollama_chat/tools/get_endoflife_spec.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4c1e0e4af70239c191a9b7fb36bafb5e813bebbe99b3884a19ed1350074937c
|
|
4
|
+
data.tar.gz: 39ff2ea149df672fdf021fc367681d578e701fe9d8fe7b4a4b202e9e73575cee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7bb2eb1885554be1140c8748adad8168c4eec9cfc85b267ea3af8f046643489c5611787a43da878a41fe3382828930caeb80be10b24f0059bae865f56d8f1e8b
|
|
7
|
+
data.tar.gz: a1c629f1678eb8b763b04ba0def7666e00f0d76ca346d5a285efc9aa8ad3b71dd13dba04482a778e2b7b178e1cbe43e10895f0cac69ad01145d276771789e574
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,104 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-02-23 v0.0.69
|
|
4
|
+
|
|
5
|
+
- Reorganized access modifiers in `module OllamaChat::Dialog`, moving `ask?` to
|
|
6
|
+
be public before the `private` keyword.
|
|
7
|
+
- Moved `links`, `debug`, `config=`, and `config` from public to private in
|
|
8
|
+
`lib/ollama_chat/chat.rb`.
|
|
9
|
+
- Added a `class_methods` block in `lib/ollama_chat/config_handling.rb`
|
|
10
|
+
declaring a class‑level `config` accessor via `Tins::Concern`.
|
|
11
|
+
- Added a private `config=` method in `config_handling.rb` to write to the
|
|
12
|
+
class‑level `config`.
|
|
13
|
+
- Kept a public `config` method that returns `self.class.config`.
|
|
14
|
+
- Added `private` to modules: `OllamaChat::Clipboard`,
|
|
15
|
+
`OllamaChat::Conversation`, `OllamaChat::Dialog`,
|
|
16
|
+
`OllamaChat::DocumentCache`, `OllamaChat::History`,
|
|
17
|
+
`OllamaChat::InputContent`, `OllamaChat::MessageEditing`,
|
|
18
|
+
`OllamaChat::ModelHandling`, `OllamaChat::ServerSocket` and removed the
|
|
19
|
+
`private` declaration from `OllamaChat::ToolCalling`.
|
|
20
|
+
- Updated spec files to call `expose` on `OllamaChat::Chat.new(argv:
|
|
21
|
+
chat_default_config)` and on `Object.extend(described_class)` so that private
|
|
22
|
+
helpers can be exercised during testing.
|
|
23
|
+
- Ensured the command‑handling logic in `handle_input` continues to invoke the
|
|
24
|
+
newly private methods correctly.
|
|
25
|
+
- Added `tool_function(name)` helper to `OllamaChat::ToolCalling` for
|
|
26
|
+
centralised tool config lookup.
|
|
27
|
+
- Updated `lib/ollama_chat/follow_chat.rb` to use `@chat.tool_function(name)`
|
|
28
|
+
instead of `config.tools.functions[name]`.
|
|
29
|
+
- Modified `lib/ollama_chat/switches.rb` switch messages to lower‑case
|
|
30
|
+
“support” (`"Tools support enabled."` / `"Tools support disabled."`).
|
|
31
|
+
- In `lib/ollama_chat/tool_calling.rb`, replaced `config.tools.functions[tool]`
|
|
32
|
+
with `tool_function(tool)` when printing tools and checking
|
|
33
|
+
`require_confirmation?`.
|
|
34
|
+
- Added a `private` section header in `lib/ollama_chat/tool_calling.rb` for
|
|
35
|
+
clarity.
|
|
36
|
+
- Adjusted spec regex in `spec/ollama_chat/chat_spec.rb` to match updated
|
|
37
|
+
message (`Tools support enabled`).
|
|
38
|
+
- Added `OllamaChat::ConfigHandling` module in
|
|
39
|
+
`lib/ollama_chat/config_handling.rb` with `display_config`, `fix_config`,
|
|
40
|
+
`edit_config`.
|
|
41
|
+
- Required `ollama_chat/config_handling` in `lib/ollama_chat.rb`.
|
|
42
|
+
- Included `OllamaChat::ConfigHandling` in `OllamaChat::Chat`.
|
|
43
|
+
- Updated `/config` command regex to `^/config(?:\\s+(edit))?$` and dispatched
|
|
44
|
+
to `edit_config` or `display_config`.
|
|
45
|
+
- Removed old `display_config`, `fix_config`, `edit_config` methods from
|
|
46
|
+
`chat.rb`.
|
|
47
|
+
- Added helper methods `tool_configured?`, `tool_registered?`, `tool_enabled?`
|
|
48
|
+
to `OllamaChat::ToolCalling` for cleaner tool state checks.
|
|
49
|
+
- Updated `FollowChat` to use the new helpers instead of direct config/registry
|
|
50
|
+
lookups (`@chat.config.tools.functions.attribute_set?(name)` →
|
|
51
|
+
`@chat.tool_configured?(name)`, `OllamaChat::Tools.registered?(name)` →
|
|
52
|
+
`@chat.tool_registered?(name)`, `@chat.enabled_tools.member?(name)` →
|
|
53
|
+
`@chat.tool_enabled?(name)`).
|
|
54
|
+
- Refactored `default_enabled_tools` in `OllamaChat::ToolCalling` to call
|
|
55
|
+
`tool_registered?` and adjusted `list_tools` to use `tool_enabled?` for
|
|
56
|
+
checkbox rendering.
|
|
57
|
+
- Simplified `Fetcher#fetch` signature from `fetch(url, headers: {}, options:
|
|
58
|
+
{})` to `fetch(url, opts = {})`; updated documentation to reflect the new
|
|
59
|
+
`opts` hash and optional `:headers` key.
|
|
60
|
+
- Added guard in `lib/ollama_chat/follow_chat.rb` to skip execution of disabled
|
|
61
|
+
tools and record an error in `@chat.tool_call_results`.
|
|
62
|
+
- Added `attr_reader :enabled_tools` to `OllamaChat::ToolCalling` and replaced
|
|
63
|
+
all `@enabled_tools` references with the reader.
|
|
64
|
+
- Updated `tools`, `list_tools`, `enable_tool`, and `disable_tool` to use
|
|
65
|
+
`enabled_tools` instead of the instance variable.
|
|
66
|
+
- Updated `/tools` command to accept `on`/`off` and handle them.
|
|
67
|
+
- Added `tools_support` switch in `switches.rb` reflecting
|
|
68
|
+
`config.tools.enabled`.
|
|
69
|
+
- Refactored config to use `enabled:` and `functions:` under `tools:`.
|
|
70
|
+
- Updated all tool references to `config.tools.functions`.
|
|
71
|
+
- Guard tool calls with `@tools_support.off?` in `tool_calling.rb`.
|
|
72
|
+
- Updated `default_enabled_tools` and `list_tools` to use
|
|
73
|
+
`config.tools.functions`.
|
|
74
|
+
- Added `tools_support.show` to `information.rb`.
|
|
75
|
+
- Updated tool implementations (`directory_structure`, `execute_grep`,
|
|
76
|
+
`file_context`, `get_current_weather`, `get_cve`, `get_endoflife`,
|
|
77
|
+
`import_url`, `read_file`, `search_web`, `write_file`) to use
|
|
78
|
+
`config.tools.functions`.
|
|
79
|
+
- Adjusted specs to reference `functions` and modify `gem_path_lookup` spec to
|
|
80
|
+
return a symbol.
|
|
81
|
+
- Added `OLLAMA_CHAT_TOOLS_RUN_TESTS_TEST_RUNNER` to `.envrc` for the
|
|
82
|
+
`run_tests` tool.
|
|
83
|
+
- Removed gem system updates from Dockerfile.
|
|
84
|
+
- Removed `model_with_size` and `choose_model` from
|
|
85
|
+
`lib/ollama_chat/dialog.rb`.
|
|
86
|
+
- Added `model_with_size` and `choose_model` to
|
|
87
|
+
`lib/ollama_chat/model_handling.rb`.
|
|
88
|
+
- In `lib/ollama_chat/env_config.rb`, changed `decode` lambda to use
|
|
89
|
+
`Pathname.new(_1).join('ollama_chat').expand_path` for absolute paths.
|
|
90
|
+
- In `lib/ollama_chat/ollama_chat_config.rb`, replaced
|
|
91
|
+
`File.directory?(cache_dir_path)` with `cache_dir_path.directory?`.
|
|
92
|
+
- Updated `default_path`, `config_dir_path`, `cache_dir_path`, and
|
|
93
|
+
`database_path` to consistently return `Pathname` objects.
|
|
94
|
+
- Added `and_call_original` to source fetching test.
|
|
95
|
+
- Removed `bundle update --all` from `.all_images.yml`.
|
|
96
|
+
- Added `before:` block to `.all_images.yml` that echoes 'Preparing…' and
|
|
97
|
+
deletes `Gemfile.lock`.
|
|
98
|
+
- Added `after:` block to `.all_images.yml` that checks `$RESULT` and prints
|
|
99
|
+
success/failure messages, then deletes `Gemfile.lock`.
|
|
100
|
+
- Updated dependency `all_images` to **~>0.12**.
|
|
101
|
+
|
|
3
102
|
## 2026-02-19 v0.0.68
|
|
4
103
|
|
|
5
104
|
- Added JSON serialization for directory structure in `OllamaChat::Parsing`
|
data/README.md
CHANGED
|
@@ -187,7 +187,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
|
|
|
187
187
|
/revise_last edit the last response in an external editor
|
|
188
188
|
/output filename save last response to filename
|
|
189
189
|
/pipe command write last response to command's stdin
|
|
190
|
-
/tools [enable|disable]
|
|
190
|
+
/tools [enable|disable|on|off] list enabled, enable/disable tools, support on/off
|
|
191
191
|
/vim insert the last message into a vim server
|
|
192
192
|
/quit to quit
|
|
193
193
|
/help to view this help
|
data/Rakefile
CHANGED
|
@@ -61,7 +61,7 @@ GemHadar do
|
|
|
61
61
|
dependency 'context_spook', '~> 1.5'
|
|
62
62
|
dependency 'infobar', '>= 0.13.1'
|
|
63
63
|
dependency 'rubyzip', '~> 3.0'
|
|
64
|
-
development_dependency 'all_images', '~> 0.
|
|
64
|
+
development_dependency 'all_images', '~> 0.12'
|
|
65
65
|
development_dependency 'rspec', '~> 3.2'
|
|
66
66
|
development_dependency 'kramdown', '~> 2.0'
|
|
67
67
|
development_dependency 'webmock'
|
data/lib/ollama_chat/chat.rb
CHANGED
|
@@ -55,6 +55,7 @@ class OllamaChat::Chat
|
|
|
55
55
|
include OllamaChat::MessageEditing
|
|
56
56
|
include OllamaChat::LocationHandling
|
|
57
57
|
include OllamaChat::ToolCalling
|
|
58
|
+
include OllamaChat::ConfigHandling
|
|
58
59
|
|
|
59
60
|
# Initializes a new OllamaChat::Chat instance with the given command-line
|
|
60
61
|
# arguments.
|
|
@@ -126,13 +127,6 @@ class OllamaChat::Chat
|
|
|
126
127
|
# that manages the thinking mode setting for the Ollama model interactions
|
|
127
128
|
attr_reader :think_mode
|
|
128
129
|
|
|
129
|
-
# The debug method accesses the debug configuration setting.
|
|
130
|
-
#
|
|
131
|
-
# @return [TrueClass, FalseClass] the current debug mode status
|
|
132
|
-
def debug
|
|
133
|
-
OllamaChat::EnvConfig::OLLAMA::CHAT::DEBUG
|
|
134
|
-
end
|
|
135
|
-
|
|
136
130
|
# The ollama reader returns the Ollama API client instance.
|
|
137
131
|
#
|
|
138
132
|
# @return [Ollama::Client] the configured Ollama API client
|
|
@@ -158,37 +152,6 @@ class OllamaChat::Chat
|
|
|
158
152
|
# messages associated with this instance
|
|
159
153
|
attr_reader :messages
|
|
160
154
|
|
|
161
|
-
# Returns the links set for this object, initializing it lazily if needed.
|
|
162
|
-
#
|
|
163
|
-
# The links set is memoized, meaning it will only be created once per object
|
|
164
|
-
# instance and subsequent calls will return the same Set instance.
|
|
165
|
-
#
|
|
166
|
-
# @return [Set] A Set object containing all links associated with this instance
|
|
167
|
-
def links
|
|
168
|
-
@links ||= Set.new
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
class << self
|
|
172
|
-
# The config attribute accessor provides read and write access to the
|
|
173
|
-
# configuration object associated with this instance.
|
|
174
|
-
attr_accessor :config
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# The config= method assigns a new configuration object to the class.
|
|
178
|
-
#
|
|
179
|
-
# @param config [ ComplexConfig::Settings ] the configuration object to be set
|
|
180
|
-
def config=(config)
|
|
181
|
-
self.class.config = config
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
# The config method returns the configuration object associated with the
|
|
185
|
-
# class.
|
|
186
|
-
#
|
|
187
|
-
# @return [ ComplexConfig::Settings ] the configuration instance
|
|
188
|
-
def config
|
|
189
|
-
self.class.config
|
|
190
|
-
end
|
|
191
|
-
|
|
192
155
|
# The start method initializes the chat session by displaying information and
|
|
193
156
|
# conversation history, then prompts the user for input to begin interacting
|
|
194
157
|
# with the chat.
|
|
@@ -221,8 +184,25 @@ class OllamaChat::Chat
|
|
|
221
184
|
OllamaChat::Vim.new(server_name, clientserver:)
|
|
222
185
|
end
|
|
223
186
|
|
|
187
|
+
# The debug method accesses the debug configuration setting.
|
|
188
|
+
#
|
|
189
|
+
# @return [TrueClass, FalseClass] the current debug mode status
|
|
190
|
+
def debug
|
|
191
|
+
OllamaChat::EnvConfig::OLLAMA::CHAT::DEBUG
|
|
192
|
+
end
|
|
193
|
+
|
|
224
194
|
private
|
|
225
195
|
|
|
196
|
+
# Returns the links set for this object, initializing it lazily if needed.
|
|
197
|
+
#
|
|
198
|
+
# The links set is memoized, meaning it will only be created once per object
|
|
199
|
+
# instance and subsequent calls will return the same Set instance.
|
|
200
|
+
#
|
|
201
|
+
# @return [Set] A Set object containing all links associated with this instance
|
|
202
|
+
def links
|
|
203
|
+
@links ||= Set.new
|
|
204
|
+
end
|
|
205
|
+
|
|
226
206
|
# Handles user input commands and processes chat interactions.
|
|
227
207
|
#
|
|
228
208
|
# @param content [String] The input content to process
|
|
@@ -388,7 +368,7 @@ class OllamaChat::Chat
|
|
|
388
368
|
STDERR.puts "Warning: No message found to insert into Vim"
|
|
389
369
|
end
|
|
390
370
|
:next
|
|
391
|
-
when %r(^/tools(?:\s+(enable|disable))?$)
|
|
371
|
+
when %r(^/tools(?:\s+(enable|disable|on|off))?$)
|
|
392
372
|
case $1
|
|
393
373
|
when nil
|
|
394
374
|
list_tools
|
|
@@ -396,10 +376,19 @@ class OllamaChat::Chat
|
|
|
396
376
|
enable_tool
|
|
397
377
|
when 'disable'
|
|
398
378
|
disable_tool
|
|
379
|
+
when 'on'
|
|
380
|
+
tools_support.set(true, show: true)
|
|
381
|
+
when 'off'
|
|
382
|
+
tools_support.set(false, show: true)
|
|
399
383
|
end
|
|
400
384
|
:next
|
|
401
|
-
when %r(^/config
|
|
402
|
-
|
|
385
|
+
when %r(^/config(?:\s+(edit))?$)
|
|
386
|
+
case $1
|
|
387
|
+
when 'edit'
|
|
388
|
+
edit_config
|
|
389
|
+
else
|
|
390
|
+
display_config
|
|
391
|
+
end
|
|
403
392
|
:next
|
|
404
393
|
when %r(^/quit$), nil
|
|
405
394
|
STDOUT.puts "Goodbye."
|
|
@@ -555,22 +544,6 @@ class OllamaChat::Chat
|
|
|
555
544
|
end
|
|
556
545
|
end
|
|
557
546
|
|
|
558
|
-
# The display_config method renders the configuration and displays it using a
|
|
559
|
-
# pager.
|
|
560
|
-
# It determines an appropriate pager command based on environment variables
|
|
561
|
-
# and available system commands, then uses Kramdown::ANSI::Pager to show the
|
|
562
|
-
# formatted configuration output.
|
|
563
|
-
def display_config
|
|
564
|
-
command = OllamaChat::EnvConfig::PAGER?
|
|
565
|
-
rendered = config.to_s
|
|
566
|
-
Kramdown::ANSI::Pager.pager(
|
|
567
|
-
lines: rendered.count(?\n),
|
|
568
|
-
command:
|
|
569
|
-
) do |output|
|
|
570
|
-
output.puts rendered
|
|
571
|
-
end
|
|
572
|
-
end
|
|
573
|
-
|
|
574
547
|
# The interact_with_user method manages the interactive loop for user input
|
|
575
548
|
# and chat processing.
|
|
576
549
|
# It handles reading user input, processing commands, managing messages, and
|
|
@@ -756,8 +729,6 @@ class OllamaChat::Chat
|
|
|
756
729
|
# change_system_prompt method to handle the selection. Otherwise, it
|
|
757
730
|
# retrieves the system prompt from a file or uses the default value, then
|
|
758
731
|
# sets it in the message history.
|
|
759
|
-
#
|
|
760
|
-
# @return [ void ] this method returns nil after setting up the system prompt
|
|
761
732
|
def setup_system_prompt
|
|
762
733
|
default = config.system_prompts.default? || @model_system
|
|
763
734
|
if @opts[?s] =~ /\A\?/
|
|
@@ -866,33 +837,6 @@ class OllamaChat::Chat
|
|
|
866
837
|
end
|
|
867
838
|
end
|
|
868
839
|
|
|
869
|
-
# The fix_config method handles configuration file errors by informing the
|
|
870
|
-
# user about the exception and prompting them to fix it.
|
|
871
|
-
# It then executes a diff tool to compare the current config file with the
|
|
872
|
-
# default one.
|
|
873
|
-
# This method exits the program after handling the configuration error
|
|
874
|
-
#
|
|
875
|
-
# @param exception [ Exception ] the exception that occurred while reading
|
|
876
|
-
# the config file
|
|
877
|
-
def fix_config(exception)
|
|
878
|
-
save_conversation('backup.json')
|
|
879
|
-
STDOUT.puts "When reading the config file, a #{exception.class} "\
|
|
880
|
-
"exception was caught: #{exception.message.inspect}"
|
|
881
|
-
unless diff_tool = OllamaChat::EnvConfig::DIFF_TOOL?
|
|
882
|
-
exit 1
|
|
883
|
-
end
|
|
884
|
-
if ask?(prompt: 'Do you want to fix the config? (y/n) ') =~ /\Ay/i
|
|
885
|
-
system Shellwords.join([
|
|
886
|
-
diff_tool,
|
|
887
|
-
@ollama_chat_config.filename,
|
|
888
|
-
@ollama_chat_config.default_config_path,
|
|
889
|
-
])
|
|
890
|
-
exit 0
|
|
891
|
-
else
|
|
892
|
-
exit 1
|
|
893
|
-
end
|
|
894
|
-
end
|
|
895
|
-
|
|
896
840
|
# Enables tab completion for chat commands within the interactive session
|
|
897
841
|
#
|
|
898
842
|
# Temporarily replaces the current Reline completion procedure with a custom
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
# @example Pasting content from input
|
|
12
12
|
# content = chat.paste_from_input
|
|
13
13
|
module OllamaChat::Clipboard
|
|
14
|
+
private
|
|
15
|
+
|
|
14
16
|
# Copy the last assistant's message to the system clipboard.
|
|
15
17
|
#
|
|
16
18
|
# This method checks if there is a last message from an assistant in the
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Provides functionality for handling configuration files and settings for
|
|
2
|
+
# OllamaChat. It loads configuration from YAML files, supports environment
|
|
3
|
+
# variable overrides, and offers methods to read and write configuration data.
|
|
4
|
+
# The module also ensures default values are set and validates configuration
|
|
5
|
+
# structure.
|
|
6
|
+
module OllamaChat::ConfigHandling
|
|
7
|
+
extend Tins::Concern
|
|
8
|
+
|
|
9
|
+
class_methods do
|
|
10
|
+
# The config attribute accessor provides read and write access to the
|
|
11
|
+
# configuration object associated with this instance.
|
|
12
|
+
attr_accessor :config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# The config method returns the configuration object associated with the
|
|
16
|
+
# class.
|
|
17
|
+
#
|
|
18
|
+
# @return [ ComplexConfig::Settings ] the configuration instance
|
|
19
|
+
def config
|
|
20
|
+
self.class.config
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# The config= method assigns a new configuration object to the class.
|
|
26
|
+
#
|
|
27
|
+
# @param config [ ComplexConfig::Settings ] the configuration object to be set
|
|
28
|
+
def config=(config)
|
|
29
|
+
self.class.config = config
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# The display_config method renders the configuration and displays it using a
|
|
33
|
+
# pager. It determines an appropriate pager command based on environment
|
|
34
|
+
# variables and available system commands, then uses Kramdown::ANSI::Pager to
|
|
35
|
+
# show the formatted configuration output.
|
|
36
|
+
def display_config
|
|
37
|
+
command = OllamaChat::EnvConfig::PAGER?
|
|
38
|
+
rendered = config.to_s
|
|
39
|
+
Kramdown::ANSI::Pager.pager(
|
|
40
|
+
lines: rendered.count(?\n),
|
|
41
|
+
command:
|
|
42
|
+
) do |output|
|
|
43
|
+
output.puts rendered
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# The fix_config method handles configuration file errors by informing the
|
|
48
|
+
# user about the exception and prompting them to fix it. It then executes a
|
|
49
|
+
# diff tool to compare the current config file with the default one.
|
|
50
|
+
# This method exits the program after handling the configuration error.
|
|
51
|
+
#
|
|
52
|
+
# @param exception [Exception] the exception that occurred while reading
|
|
53
|
+
# the config file
|
|
54
|
+
def fix_config(exception)
|
|
55
|
+
save_conversation('backup.json')
|
|
56
|
+
STDOUT.puts "When reading the config file, a #{exception.class} "\
|
|
57
|
+
"exception was caught: #{exception.message.inspect}"
|
|
58
|
+
unless diff_tool = OllamaChat::EnvConfig::DIFF_TOOL?
|
|
59
|
+
exit 1
|
|
60
|
+
end
|
|
61
|
+
if ask?(prompt: 'Do you want to fix the config? (y/n) ') =~ /\Ay/i
|
|
62
|
+
system Shellwords.join([
|
|
63
|
+
diff_tool,
|
|
64
|
+
@ollama_chat_config.filename,
|
|
65
|
+
@ollama_chat_config.default_config_path,
|
|
66
|
+
])
|
|
67
|
+
exit 0
|
|
68
|
+
else
|
|
69
|
+
exit 1
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Edit the current configuration file in the editor defined by the
|
|
74
|
+
# environment variable `EDITOR`.
|
|
75
|
+
#
|
|
76
|
+
# 1. Looks up the editor command via `OllamaChat::EnvConfig::EDITOR`.
|
|
77
|
+
# If the value is `nil` or empty, it prints an error message to
|
|
78
|
+
# STDERR and returns immediately.
|
|
79
|
+
# 2. Invokes the editor with the path to the active configuration
|
|
80
|
+
# file (`@ollama_chat_config.filename`). The editor is launched via
|
|
81
|
+
# `system` so that the process inherits the current terminal,
|
|
82
|
+
# allowing in‑place editing.
|
|
83
|
+
# 3. If editing was successful, prompts the user to restart
|
|
84
|
+
# `ollama_chat` if desired.
|
|
85
|
+
def edit_config
|
|
86
|
+
unless editor = OllamaChat::EnvConfig::EDITOR?
|
|
87
|
+
STDERR.puts "Need the environment variable var EDITOR defined to use an editor"
|
|
88
|
+
return
|
|
89
|
+
end
|
|
90
|
+
result = system Shellwords.join([ editor, @ollama_chat_config.filename ])
|
|
91
|
+
if result
|
|
92
|
+
if ask?(prompt: "Do you want to restart #{progname}? (y/n) ") =~ /\Ay/i
|
|
93
|
+
exec($0, *ARGV)
|
|
94
|
+
end
|
|
95
|
+
else
|
|
96
|
+
STDERR.puts "Editor returned a non-zero status!"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/ollama_chat/dialog.rb
CHANGED
|
@@ -13,50 +13,17 @@
|
|
|
13
13
|
# @example Changing the system prompt
|
|
14
14
|
# chat.change_system_prompt('default_prompt', system: '?sherlock')
|
|
15
15
|
module OllamaChat::Dialog
|
|
16
|
-
# The
|
|
17
|
-
# by creating a formatted string that includes the model name and its size
|
|
18
|
-
# in a human-readable format with appropriate units.
|
|
16
|
+
# The ask? method prompts the user with a question and returns their input.
|
|
19
17
|
#
|
|
20
|
-
# @param
|
|
18
|
+
# @param prompt [ String ] the message to display to the user
|
|
21
19
|
#
|
|
22
|
-
# @return [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
formatted_size = Term::ANSIColor.bold {
|
|
27
|
-
Tins::Unit.format(model.size, unit: ?B, prefix: 1024, format: '%.1f %U')
|
|
28
|
-
}
|
|
29
|
-
result.singleton_class.class_eval do
|
|
30
|
-
define_method(:to_s) { "%s %s" % [ model.name, formatted_size ] }
|
|
31
|
-
end
|
|
32
|
-
result
|
|
20
|
+
# @return [ String ] the user's response with trailing newline removed
|
|
21
|
+
def ask?(prompt:)
|
|
22
|
+
print prompt
|
|
23
|
+
STDIN.gets.to_s.chomp
|
|
33
24
|
end
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
# CLI input or user interaction.
|
|
37
|
-
# It processes the provided CLI model parameter to determine if a regex
|
|
38
|
-
# selector is used, filters the models accordingly, and prompts the user to
|
|
39
|
-
# choose from the filtered list if needed.
|
|
40
|
-
# The method ensures that a model is selected and displays a connection
|
|
41
|
-
# message with the chosen model and base URL.
|
|
42
|
-
def choose_model(cli_model, current_model)
|
|
43
|
-
selector = if cli_model =~ /\A\?+(.*)\z/
|
|
44
|
-
cli_model = ''
|
|
45
|
-
Regexp.new($1)
|
|
46
|
-
end
|
|
47
|
-
models = ollama.tags.models.sort_by(&:name).map { |m| model_with_size(m) }
|
|
48
|
-
selector and models = models.grep(selector)
|
|
49
|
-
model =
|
|
50
|
-
if models.size == 1
|
|
51
|
-
models.first
|
|
52
|
-
elsif cli_model == ''
|
|
53
|
-
OllamaChat::Utils::Chooser.choose(models) || current_model
|
|
54
|
-
else
|
|
55
|
-
cli_model || current_model
|
|
56
|
-
end
|
|
57
|
-
ensure
|
|
58
|
-
connect_message(model, ollama.base_url)
|
|
59
|
-
end
|
|
26
|
+
private
|
|
60
27
|
|
|
61
28
|
# The connect_message method displays a connection status message.
|
|
62
29
|
#
|
|
@@ -66,16 +33,6 @@ module OllamaChat::Dialog
|
|
|
66
33
|
STDOUT.puts green { "Connecting to #{model}@#{base_url} now…" }
|
|
67
34
|
end
|
|
68
35
|
|
|
69
|
-
# The ask? method prompts the user with a question and returns their input.
|
|
70
|
-
#
|
|
71
|
-
# @param prompt [ String ] the message to display to the user
|
|
72
|
-
#
|
|
73
|
-
# @return [ String ] the user's response with trailing newline removed
|
|
74
|
-
def ask?(prompt:)
|
|
75
|
-
print prompt
|
|
76
|
-
STDIN.gets.to_s.chomp
|
|
77
|
-
end
|
|
78
|
-
|
|
79
36
|
# The choose_collection method presents a menu to select or create a document
|
|
80
37
|
# collection. It displays existing collections along with options to create a
|
|
81
38
|
# new one or exit.
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
# document management system to enable efficient storage, retrieval, and
|
|
7
7
|
# similarity-based searching of documents using vector embeddings.
|
|
8
8
|
module OllamaChat::DocumentCache
|
|
9
|
+
private
|
|
10
|
+
|
|
9
11
|
# Retrieves the cache class specified in the configuration.
|
|
10
12
|
#
|
|
11
13
|
# This method resolves the cache class name from the application's
|
|
@@ -20,13 +20,13 @@ module OllamaChat
|
|
|
20
20
|
XDG_CONFIG_HOME = set do
|
|
21
21
|
description 'XDG Configuration directory path'
|
|
22
22
|
default { '~/.config' }
|
|
23
|
-
decode { Pathname.new(_1)
|
|
23
|
+
decode { Pathname.new(_1).join('ollama_chat').expand_path }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
XDG_CACHE_HOME = set do
|
|
27
27
|
description 'XDG Cache directory path'
|
|
28
28
|
default { '~/.cache' }
|
|
29
|
-
decode { Pathname.new(_1)
|
|
29
|
+
decode { Pathname.new(_1).join('ollama_chat').expand_path }
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
PAGER = set do
|
|
@@ -98,20 +98,25 @@ class OllamaChat::FollowChat
|
|
|
98
98
|
|
|
99
99
|
response.message.tool_calls.each do |tool_call|
|
|
100
100
|
name = tool_call.function.name
|
|
101
|
-
unless @chat.
|
|
101
|
+
unless @chat.tool_configured?(name)
|
|
102
102
|
@chat.tool_call_results[name] =
|
|
103
103
|
"Error: Unconfigured tool named %s ignored => Skip.\n" % name
|
|
104
104
|
next
|
|
105
105
|
end
|
|
106
|
-
unless
|
|
106
|
+
unless @chat.tool_registered?(name)
|
|
107
107
|
@chat.tool_call_results[name] =
|
|
108
108
|
"Error: Unregistered tool named %s ignored => Skip.\n" % name
|
|
109
109
|
next
|
|
110
110
|
end
|
|
111
|
+
unless @chat.tool_enabled?(name)
|
|
112
|
+
@chat.tool_call_results[name] =
|
|
113
|
+
"Error: Disabled tool named %s ignored => Skip.\n" % name
|
|
114
|
+
next
|
|
115
|
+
end
|
|
111
116
|
STDOUT.puts
|
|
112
117
|
confirmed = true
|
|
113
118
|
args = JSON.pretty_generate(tool_call.function.arguments)
|
|
114
|
-
if @chat.
|
|
119
|
+
if @chat.tool_function(name).require_confirmation?
|
|
115
120
|
prompt = "I want to execute tool %s\n%s\nConfirm? (y/n) " % [
|
|
116
121
|
bold { name },
|
|
117
122
|
italic { args },
|
data/lib/ollama_chat/history.rb
CHANGED
|
@@ -104,6 +104,7 @@ module OllamaChat::Information
|
|
|
104
104
|
location.show
|
|
105
105
|
voice.show
|
|
106
106
|
@voice.on? and @voices.show
|
|
107
|
+
tools_support.show
|
|
107
108
|
STDOUT.puts "Documents database cache is #{@documents.nil? ? 'n/a' : bold{@documents.cache.class}}"
|
|
108
109
|
STDOUT.puts "Document policy for references in user text: #{bold{document_policy}}"
|
|
109
110
|
STDOUT.puts "Currently selected search engine is #{bold(search_engine)}."
|
|
@@ -152,7 +153,7 @@ module OllamaChat::Information
|
|
|
152
153
|
/revise_last edit the last response in an external editor
|
|
153
154
|
/output filename save last response to filename
|
|
154
155
|
/pipe command write last response to command's stdin
|
|
155
|
-
/tools [enable|disable]
|
|
156
|
+
/tools [enable|disable|on|off] list enabled, enable/disable tools, support on/off
|
|
156
157
|
/vim insert the last message into a vim server
|
|
157
158
|
/quit to quit
|
|
158
159
|
/help to view this help
|
|
@@ -8,6 +8,8 @@ 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
|
+
private
|
|
12
|
+
|
|
11
13
|
# The input method selects and reads content from files matching a pattern.
|
|
12
14
|
#
|
|
13
15
|
# This method prompts the user to select files matching the given glob
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
# @example Ensuring a model is available locally
|
|
17
17
|
# chat.pull_model_unless_present('phi3', {})
|
|
18
18
|
module OllamaChat::ModelHandling
|
|
19
|
+
private
|
|
20
|
+
|
|
19
21
|
# The model_present? method checks if the specified Ollama model is available.
|
|
20
22
|
#
|
|
21
23
|
# @param model [ String ] the name of the Ollama model
|
|
@@ -69,4 +71,49 @@ module OllamaChat::ModelHandling
|
|
|
69
71
|
warn "Caught #{e.class} while pulling model: #{e} => Exiting."
|
|
70
72
|
exit 1
|
|
71
73
|
end
|
|
74
|
+
|
|
75
|
+
# The model_with_size method formats a model's size for display
|
|
76
|
+
# by creating a formatted string that includes the model name and its size
|
|
77
|
+
# in a human-readable format with appropriate units.
|
|
78
|
+
#
|
|
79
|
+
# @param model [ Object ] the model object that has name and size attributes
|
|
80
|
+
#
|
|
81
|
+
# @return [ Object ] a result object with an overridden to_s method
|
|
82
|
+
# that combines the model name and formatted size
|
|
83
|
+
private def model_with_size(model)
|
|
84
|
+
result = model.name
|
|
85
|
+
formatted_size = Term::ANSIColor.bold {
|
|
86
|
+
Tins::Unit.format(model.size, unit: ?B, prefix: 1024, format: '%.1f %U')
|
|
87
|
+
}
|
|
88
|
+
result.singleton_class.class_eval do
|
|
89
|
+
define_method(:to_s) { "%s %s" % [ model.name, formatted_size ] }
|
|
90
|
+
end
|
|
91
|
+
result
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# The choose_model method selects a model from the available list based on
|
|
95
|
+
# CLI input or user interaction.
|
|
96
|
+
# It processes the provided CLI model parameter to determine if a regex
|
|
97
|
+
# selector is used, filters the models accordingly, and prompts the user to
|
|
98
|
+
# choose from the filtered list if needed.
|
|
99
|
+
# The method ensures that a model is selected and displays a connection
|
|
100
|
+
# message with the chosen model and base URL.
|
|
101
|
+
def choose_model(cli_model, current_model)
|
|
102
|
+
selector = if cli_model =~ /\A\?+(.*)\z/
|
|
103
|
+
cli_model = ''
|
|
104
|
+
Regexp.new($1)
|
|
105
|
+
end
|
|
106
|
+
models = ollama.tags.models.sort_by(&:name).map { |m| model_with_size(m) }
|
|
107
|
+
selector and models = models.grep(selector)
|
|
108
|
+
model =
|
|
109
|
+
if models.size == 1
|
|
110
|
+
models.first
|
|
111
|
+
elsif cli_model == ''
|
|
112
|
+
OllamaChat::Utils::Chooser.choose(models) || current_model
|
|
113
|
+
else
|
|
114
|
+
cli_model || current_model
|
|
115
|
+
end
|
|
116
|
+
ensure
|
|
117
|
+
connect_message(model, ollama.base_url)
|
|
118
|
+
end
|
|
72
119
|
end
|