ollama_chat 0.0.145 ā 0.0.147
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 +97 -0
- data/Gemfile +0 -2
- data/Rakefile +6 -4
- data/lib/ollama_chat/chat.rb +2 -2
- data/lib/ollama_chat/commands.rb +23 -22
- data/lib/ollama_chat/compaction.rb +2 -2
- data/lib/ollama_chat/conversation.rb +9 -28
- data/lib/ollama_chat/dialog.rb +16 -13
- data/lib/ollama_chat/favourites_management.rb +35 -51
- data/lib/ollama_chat/input_content.rb +2 -2
- data/lib/ollama_chat/message_list.rb +2 -0
- data/lib/ollama_chat/model_handling.rb +9 -11
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +1 -0
- data/lib/ollama_chat/personae_management.rb +29 -17
- data/lib/ollama_chat/prompt_management.rb +1 -1
- data/lib/ollama_chat/rag_handling.rb +30 -54
- data/lib/ollama_chat/session_management.rb +1 -1
- data/lib/ollama_chat/source_fetching.rb +9 -2
- data/lib/ollama_chat/tool_calling.rb +36 -76
- data/lib/ollama_chat/tools/memorize.rb +1 -1
- data/lib/ollama_chat/tools/search_knowledge.rb +6 -4
- data/lib/ollama_chat/utils/chooser.rb +66 -1
- data/lib/ollama_chat/utils/fetcher.rb +4 -0
- data/lib/ollama_chat/utils/strip_ansi.rb +1 -1
- data/lib/ollama_chat/version.rb +1 -1
- data/lib/ollama_chat/web_searching.rb +16 -24
- data/lib/ollama_chat.rb +1 -0
- data/ollama_chat.gemspec +9 -7
- data/spec/ollama_chat/commands_spec.rb +11 -20
- data/spec/ollama_chat/conversation_spec.rb +7 -17
- data/spec/ollama_chat/favourites_management_spec.rb +19 -60
- data/spec/ollama_chat/input_content_spec.rb +7 -18
- data/spec/ollama_chat/model_handling_spec.rb +3 -3
- data/spec/ollama_chat/prompt_management_spec.rb +3 -3
- data/spec/ollama_chat/rag_handling_spec.rb +14 -18
- data/spec/ollama_chat/system_prompt_management_spec.rb +3 -3
- data/spec/ollama_chat/tool_calling_spec.rb +25 -64
- metadata +39 -17
|
@@ -95,11 +95,9 @@ module OllamaChat::RAGHandling
|
|
|
95
95
|
# Dumps one or more `memory-<persona>` collections to a JSONL file
|
|
96
96
|
# for portable backup or migration.
|
|
97
97
|
#
|
|
98
|
-
# Presents
|
|
99
|
-
#
|
|
100
|
-
# `
|
|
101
|
-
# Each line carries a `collection` field so one file can hold multiple
|
|
102
|
-
# personas.
|
|
98
|
+
# Presents a multi-select chooser of all `memory-*` collections
|
|
99
|
+
# with an `[ALL]` shortcut; Enter commits the write. Each line carries a
|
|
100
|
+
# `collection` field so one file can hold multiple personas.
|
|
103
101
|
#
|
|
104
102
|
# @param filename [String, nil] the output path (must end in .json/.jsonl);
|
|
105
103
|
# prompts interactively if nil
|
|
@@ -109,24 +107,13 @@ module OllamaChat::RAGHandling
|
|
|
109
107
|
.pluck(:name)
|
|
110
108
|
return feedback('No memory-* collections found.', type: :warn) unless collections
|
|
111
109
|
|
|
112
|
-
selected =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
when nil, '[DONE]'
|
|
120
|
-
break
|
|
121
|
-
when '[ALL]'
|
|
122
|
-
selected.merge(remaining)
|
|
123
|
-
break
|
|
124
|
-
else
|
|
125
|
-
selected << choice
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
110
|
+
selected = choose_multi(
|
|
111
|
+
%w[ [ALL] [NONE] ] + collections,
|
|
112
|
+
all: '[ALL]',
|
|
113
|
+
none: '[NONE]',
|
|
114
|
+
prompt: 'Which memory collections to dump? %s ' \
|
|
115
|
+
'[Tab=toggle, Enter=apply, C-c=abort]'
|
|
116
|
+
) or return feedback('Cancelled, no collections selected.', type: :cancel)
|
|
130
117
|
return feedback('Cancelled, no collections selected.', type: :cancel) if selected.empty?
|
|
131
118
|
|
|
132
119
|
filename.present? or filename = ask_for_filename?(action: 'to dump into')
|
|
@@ -137,7 +124,7 @@ module OllamaChat::RAGHandling
|
|
|
137
124
|
filename = Pathname.new(filename).expand_path
|
|
138
125
|
should_overwrite?(filename) or return
|
|
139
126
|
|
|
140
|
-
feedback("Dumping #{selected.size} collection(s): #{selected.sort.
|
|
127
|
+
feedback("Dumping #{selected.size} collection(s): #{selected.sort.joined}")
|
|
141
128
|
|
|
142
129
|
records = []
|
|
143
130
|
selected.sort.each do |col|
|
|
@@ -164,9 +151,8 @@ module OllamaChat::RAGHandling
|
|
|
164
151
|
|
|
165
152
|
# Restores `memory-<persona>` collections from a JSONL dump file.
|
|
166
153
|
#
|
|
167
|
-
# Presents
|
|
168
|
-
#
|
|
169
|
-
# `[ALL]` to grab everything remaining, or `[DONE]` to commit the restore.
|
|
154
|
+
# Presents a multi-select chooser of all collections found in the file
|
|
155
|
+
# with an `[ALL]` shortcut; Enter commits the restore.
|
|
170
156
|
# Records are added with their original tag and source so timestamps
|
|
171
157
|
# and file associations survive.
|
|
172
158
|
#
|
|
@@ -189,29 +175,19 @@ module OllamaChat::RAGHandling
|
|
|
189
175
|
collections = entries.group_by { |e| e['collection'] }.reject { _1.nil? }
|
|
190
176
|
return feedback('No collection field found in entries.', type: :warn) if collections.empty?
|
|
191
177
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
break
|
|
201
|
-
when '[ALL]'
|
|
202
|
-
selected.merge(remaining)
|
|
203
|
-
break
|
|
204
|
-
else
|
|
205
|
-
selected << choice
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
178
|
+
keys = collections.keys
|
|
179
|
+
selected = choose_multi(
|
|
180
|
+
%w[ [ALL] [NONE] ] + keys,
|
|
181
|
+
all: '[ALL]',
|
|
182
|
+
none: '[NONE]',
|
|
183
|
+
prompt: 'Which memory collections to restore? %s ' \
|
|
184
|
+
'[Tab=toggle, Enter=apply, C-c=abort]'
|
|
185
|
+
) or return feedback('Cancelled, no collections selected.', type: :cancel)
|
|
210
186
|
return feedback('Cancelled, no collections selected.', type: :cancel) if selected.empty?
|
|
211
187
|
|
|
212
188
|
selected = selected.sort
|
|
213
189
|
|
|
214
|
-
feedback("Restoring #{selected.size} collection(s): #{selected.
|
|
190
|
+
feedback("Restoring #{selected.size} collection(s): #{selected.joined}")
|
|
215
191
|
|
|
216
192
|
total = 0
|
|
217
193
|
skipped = 0
|
|
@@ -261,8 +237,11 @@ module OllamaChat::RAGHandling
|
|
|
261
237
|
target = collection
|
|
262
238
|
prompt = "š„ This will incinerate every record in #{target.inspect}. " \
|
|
263
239
|
"Type the name to confirm (C-c ā cancel): "
|
|
264
|
-
typed = switch_history(:
|
|
265
|
-
|
|
240
|
+
typed = switch_history(:empty_history) do
|
|
241
|
+
Reline::HISTORY.clear
|
|
242
|
+
ask?(prompt:).full?(:strip)
|
|
243
|
+
ensure
|
|
244
|
+
Reline::HISTORY.clear
|
|
266
245
|
end
|
|
267
246
|
if typed == target
|
|
268
247
|
@documents.clear
|
|
@@ -392,7 +371,7 @@ module OllamaChat::RAGHandling
|
|
|
392
371
|
display_map = {}
|
|
393
372
|
sources.each do |s|
|
|
394
373
|
tags = source_tags[s].map(&:to_s)
|
|
395
|
-
line = tags.any? ? "#{s} [#{tags.
|
|
374
|
+
line = tags.any? ? "#{s} [#{tags.joined}]" : s
|
|
396
375
|
display_map[line] = s
|
|
397
376
|
end
|
|
398
377
|
display = display_map.keys
|
|
@@ -416,7 +395,7 @@ module OllamaChat::RAGHandling
|
|
|
416
395
|
output.puts
|
|
417
396
|
records.each do |record|
|
|
418
397
|
output.puts kramdown_ansi_parse(<<~EOT)
|
|
419
|
-
**[#{record.tags.
|
|
398
|
+
**[#{record.tags.joined}]**
|
|
420
399
|
```
|
|
421
400
|
#{wrap(record.text.sub(/\n+\z/, ''), percentage: 90)}
|
|
422
401
|
```
|
|
@@ -617,10 +596,7 @@ module OllamaChat::RAGHandling
|
|
|
617
596
|
if matched_sources.nil? || matched_sources.member?(source)
|
|
618
597
|
seen.member?(source) and next
|
|
619
598
|
seen << source
|
|
620
|
-
|
|
621
|
-
infobar.puts "Source #{source.to_s.inspect} is unmodified. => Skipping."
|
|
622
|
-
next
|
|
623
|
-
end
|
|
599
|
+
@documents.source_modified?(source) or next
|
|
624
600
|
sources[source] = record.tags_set
|
|
625
601
|
end
|
|
626
602
|
@documents.source_remove(source)
|
|
@@ -303,12 +303,17 @@ module OllamaChat::SourceFetching
|
|
|
303
303
|
# to the tags array to apply to that source
|
|
304
304
|
# @return [Array<String>] results from each successful embed call
|
|
305
305
|
def bulk_embed_sources(sources_tags)
|
|
306
|
+
sources_tags.empty? and return []
|
|
307
|
+
infobar.show = false
|
|
306
308
|
prompt = prompt(:embed)
|
|
307
|
-
|
|
308
|
-
sources_tags.size
|
|
309
|
+
if sources_tags.size <= 1 or config.embedding.concurrency <= 1
|
|
310
|
+
feedback("Collection #{bold{collection}}: Embedding #{sources_tags.size} sourcesā¦", type: :info)
|
|
311
|
+
return sources_tags.map { |s, tags| embed(s, prompt:, tags:) }.compact
|
|
312
|
+
end
|
|
309
313
|
|
|
310
314
|
results = []
|
|
311
315
|
mutex = Mutex.new
|
|
316
|
+
feedback("Collection #{bold{collection}}: Embedding #{sources_tags.size} sources in parallelā¦", type: :info)
|
|
312
317
|
Tins::Limited.new(config.embedding.concurrency, name: 'embed').process do |l|
|
|
313
318
|
sources_tags.each do |s, tags|
|
|
314
319
|
l.execute do
|
|
@@ -319,6 +324,8 @@ module OllamaChat::SourceFetching
|
|
|
319
324
|
l.stop
|
|
320
325
|
end
|
|
321
326
|
results
|
|
327
|
+
ensure
|
|
328
|
+
infobar.show = true
|
|
322
329
|
end
|
|
323
330
|
|
|
324
331
|
private
|
|
@@ -94,88 +94,48 @@ module OllamaChat::ToolCalling
|
|
|
94
94
|
Array(config.tools&.functions&.attribute_names&.map(&:to_s)).sort
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
#
|
|
97
|
+
# The choose_tools method opens an interactive multi-select picker showing
|
|
98
|
+
# all configured tools with their current enabled/disabled state and
|
|
99
|
+
# confirmation requirement. The user toggles tools with Tab and
|
|
100
|
+
# applies changes with Enter.
|
|
99
101
|
#
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
enabled = tool_enabled?(tool) ? 'ā
' : 'ā'
|
|
107
|
-
require_confirmation = tool_function(tool).require_confirmation? ? 'ā' : 'ā'
|
|
108
|
-
|
|
109
|
-
output.printf(
|
|
110
|
-
"%s %s %s\n",
|
|
111
|
-
enabled, require_confirmation, (enabled ? bold { tool } : tool)
|
|
112
|
-
)
|
|
113
|
-
end
|
|
114
|
-
output.puts ?ā * Tins::Terminal.columns
|
|
115
|
-
tools_support.show(output:)
|
|
102
|
+
# @return [nil]
|
|
103
|
+
def choose_tools
|
|
104
|
+
unless tools_support.on?
|
|
105
|
+
return feedback(
|
|
106
|
+
'Tools are globally disabled. Use /tools on first.', type: :warn
|
|
107
|
+
)
|
|
116
108
|
end
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# list of available tools.
|
|
121
|
-
#
|
|
122
|
-
# This method presents a menu of tools that can be enabled, excluding those
|
|
123
|
-
# that are already enabled. It uses the chooser to display the available
|
|
124
|
-
# tools and handles the user's selection by updating the session's default
|
|
125
|
-
# tools configuration in the database.
|
|
126
|
-
def enable_tool
|
|
127
|
-
choose_with_state do
|
|
128
|
-
loop do
|
|
129
|
-
select_tools = configured_tools - enabled_tools
|
|
130
|
-
select_tools = [ '[EXIT]' ] + select_tools
|
|
131
|
-
chosen = choose_entry(
|
|
132
|
-
select_tools,
|
|
133
|
-
prompt: 'Which capabilities should be granted to the model? %s'
|
|
134
|
-
)
|
|
135
|
-
case chosen
|
|
136
|
-
when '[EXIT]', nil
|
|
137
|
-
feedback("Exiting chooser.")
|
|
138
|
-
return
|
|
139
|
-
when *select_tools
|
|
140
|
-
session.tools_default_enabled[chosen] = true
|
|
141
|
-
unless session.save
|
|
142
|
-
feedback("Could not enable tool %s" % bold { chosen }, type: :warn)
|
|
143
|
-
confirm?(prompt: "\nā Press any key to continue (%s). ", timeout: 3)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
109
|
+
entries = configured_tools.map do |tool|
|
|
110
|
+
marker = tool_function(tool).require_confirmation? ? 'ā' : 'ā'
|
|
111
|
+
SearchUI::Wrapper.new(tool, display: "#{marker} #{tool}")
|
|
147
112
|
end
|
|
148
|
-
|
|
113
|
+
picked = entries.select { |e| enabled_tools.include?(e.value) }
|
|
114
|
+
result = choose_multi(
|
|
115
|
+
entries,
|
|
116
|
+
prompt: 'Choose tools: %s [Tab=toggle, Enter=apply, C-c=abort]',
|
|
117
|
+
picked:,
|
|
118
|
+
picked_icon: 'ā
',
|
|
119
|
+
unpicked_icon: 'ā'
|
|
120
|
+
) or return feedback('Aborted.')
|
|
149
121
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
122
|
+
result = result.map(&:value)
|
|
123
|
+
to_enable = result - enabled_tools
|
|
124
|
+
to_disable = enabled_tools - result
|
|
125
|
+
|
|
126
|
+
to_enable.each { |t| session.tools_default_enabled[t] = true }
|
|
127
|
+
to_disable.each { |t| session.tools_default_enabled[t] = false }
|
|
128
|
+
|
|
129
|
+
unless (to_enable + to_disable).empty?
|
|
130
|
+
unless session.save
|
|
131
|
+
feedback('Could not save session.', type: :warn)
|
|
132
|
+
confirm?(prompt: "\n\u23CE Press any key to continue (%s). ", timeout: 3)
|
|
133
|
+
else
|
|
134
|
+
feedback(
|
|
135
|
+
"Enabled: %s | Disabled: %s" %
|
|
136
|
+
[ to_enable.join(', ').inspect, to_disable.join(', ').inspect ]
|
|
165
137
|
)
|
|
166
|
-
case chosen
|
|
167
|
-
when '[EXIT]', nil
|
|
168
|
-
feedback("Exiting chooser.")
|
|
169
|
-
return
|
|
170
|
-
when *select_tools
|
|
171
|
-
session.tools_default_enabled[chosen] = false
|
|
172
|
-
unless session.save
|
|
173
|
-
feedback("Could not disable tool %s" % bold { chosen }, type: :warn)
|
|
174
|
-
confirm?(prompt: "\nā Press any key to continue (%s). ", timeout: 3)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
138
|
end
|
|
178
139
|
end
|
|
179
140
|
end
|
|
180
|
-
|
|
181
141
|
end
|
|
@@ -123,7 +123,7 @@ class OllamaChat::Tools::Memorize
|
|
|
123
123
|
"New entry tagged ##{timestamp}." :
|
|
124
124
|
"Memory stored in collection #{collection.inspect}."
|
|
125
125
|
|
|
126
|
-
result = { success: true, timestamp:, collection:, message: }
|
|
126
|
+
result = { success: true, timestamp:, collection:, message:, text: }
|
|
127
127
|
if update
|
|
128
128
|
result |= {
|
|
129
129
|
replaced_timestamp: update,
|
|
@@ -34,9 +34,10 @@ class OllamaChat::Tools::SearchKnowledge
|
|
|
34
34
|
function: Tool::Function.new(
|
|
35
35
|
name:,
|
|
36
36
|
description: <<~EOT,
|
|
37
|
-
Search the local knowledge collections for text matching the
|
|
38
|
-
|
|
39
|
-
a prompt header and an array of {text, tags}
|
|
37
|
+
Search the local knowledge collections for text matching the supplied
|
|
38
|
+
query formulated as a natural language question. The result is a JSON
|
|
39
|
+
string containing a prompt header and an array of {text, tags}
|
|
40
|
+
objects.
|
|
40
41
|
EOT
|
|
41
42
|
parameters: Tool::Function::Parameters.new(
|
|
42
43
|
type: 'object',
|
|
@@ -44,7 +45,8 @@ class OllamaChat::Tools::SearchKnowledge
|
|
|
44
45
|
query: Tool::Function::Parameters::Property.new(
|
|
45
46
|
type: 'string',
|
|
46
47
|
description: <<~EOT,
|
|
47
|
-
The query or text to search for in the knowledge collections
|
|
48
|
+
The query or text to search for in the knowledge collections as
|
|
49
|
+
a fully formulated question in natural language.
|
|
48
50
|
EOT
|
|
49
51
|
),
|
|
50
52
|
tags: Tool::Function::Parameters::Property.new(
|
|
@@ -55,7 +55,7 @@ module OllamaChat::Utils::Chooser
|
|
|
55
55
|
]
|
|
56
56
|
}.select { |_, s| s < 0 }.sort_by(&:last).map(&:first)
|
|
57
57
|
matches.empty? and matches = entries
|
|
58
|
-
matches
|
|
58
|
+
matches
|
|
59
59
|
},
|
|
60
60
|
query: -> _answer, matches, selector {
|
|
61
61
|
matches.each_with_index.map { |m, i|
|
|
@@ -77,6 +77,71 @@ module OllamaChat::Utils::Chooser
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
+
# The choose_multi method presents a list of entries for multi-selection.
|
|
81
|
+
#
|
|
82
|
+
# Users toggle items with Tab and confirm with Enter, which returns
|
|
83
|
+
# the full set of picked items as an Array. Ctrl-C aborts and returns nil.
|
|
84
|
+
#
|
|
85
|
+
# @param entries [Array] the list of entries to present to the user
|
|
86
|
+
# @param prompt [String] the prompt message (default: 'Search? %s')
|
|
87
|
+
# @param picked [ Array, nil ] items to pre-select (default: nil)
|
|
88
|
+
# @param all [String, nil] sentinel entry that selects all items (default: nil)
|
|
89
|
+
# @param none [String, nil] sentinel entry that clears all items (default: nil)
|
|
90
|
+
# @param picked_icon [String] icon for selected items (default: 'āŖ')
|
|
91
|
+
# @param unpicked_icon [String] icon for unselected items (default: 'ā«')
|
|
92
|
+
# @return [Array, nil] the picked items (excluding sentinels), or nil if aborted
|
|
93
|
+
#
|
|
94
|
+
# @example
|
|
95
|
+
# picked = choose_multi(
|
|
96
|
+
# entries,
|
|
97
|
+
# prompt: 'Toggle: %s [Tab=toggle, Enter=apply, C-c=abort]',
|
|
98
|
+
# picked: current_selection,
|
|
99
|
+
# all: '[ALL]'
|
|
100
|
+
# )
|
|
101
|
+
def choose_multi(entries, prompt: 'Search? %s', picked: nil,
|
|
102
|
+
all: nil, none: nil,
|
|
103
|
+
picked_icon: 'āŖ', unpicked_icon: 'ā«')
|
|
104
|
+
state = current_search_state if dynamic_defined?(:current_search_state)
|
|
105
|
+
search = Search.new(
|
|
106
|
+
state: ,
|
|
107
|
+
prompt: ,
|
|
108
|
+
multi: true,
|
|
109
|
+
picked: ,
|
|
110
|
+
all: ,
|
|
111
|
+
none: ,
|
|
112
|
+
match: -> answer {
|
|
113
|
+
matcher = Amatch::PairDistance.new(answer.downcase)
|
|
114
|
+
matches = entries.map { |n|
|
|
115
|
+
[
|
|
116
|
+
n,
|
|
117
|
+
-matcher.similar(
|
|
118
|
+
n.ask_and_send_or_self(:value).to_s.downcase, /\b/
|
|
119
|
+
)
|
|
120
|
+
]
|
|
121
|
+
}.select { |_, s| s < 0 }.sort_by(&:last).map(&:first)
|
|
122
|
+
matches.empty? and matches = entries
|
|
123
|
+
matches
|
|
124
|
+
},
|
|
125
|
+
query: -> _answer, matches, selector, picked {
|
|
126
|
+
matches.each_with_index.map { |m, i|
|
|
127
|
+
mark = picked[m] ? picked_icon : unpicked_icon
|
|
128
|
+
cursor = i == selector ? " #{blue { ?ā® }}" : ' '
|
|
129
|
+
"#{cursor} #{mark} #{m}"
|
|
130
|
+
} * ?\n
|
|
131
|
+
},
|
|
132
|
+
found: -> _answer, matches, selector { matches[selector] },
|
|
133
|
+
output: STDOUT
|
|
134
|
+
)
|
|
135
|
+
entry = search.start
|
|
136
|
+
self.current_search_state = search.state if dynamic_defined?(:current_search_state)
|
|
137
|
+
if entry
|
|
138
|
+
entry
|
|
139
|
+
else
|
|
140
|
+
print clear_screen, move_home
|
|
141
|
+
nil
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
80
145
|
# Wraps a block of code to provide a fresh search state for sequential
|
|
81
146
|
# interactive selections.
|
|
82
147
|
#
|
|
@@ -170,6 +170,8 @@ class OllamaChat::Utils::Fetcher
|
|
|
170
170
|
result
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
|
+
ensure
|
|
174
|
+
infobar.finish
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
# The normalize_url method processes a URL by converting it to a string,
|
|
@@ -335,6 +337,8 @@ class OllamaChat::Utils::Fetcher
|
|
|
335
337
|
rescue RetryWithoutStreaming
|
|
336
338
|
@streaming = false
|
|
337
339
|
retry
|
|
340
|
+
ensure
|
|
341
|
+
infobar.finish
|
|
338
342
|
end
|
|
339
343
|
|
|
340
344
|
private
|
|
@@ -17,6 +17,6 @@ module OllamaChat::Utils::StripANSI
|
|
|
17
17
|
# @param line [String] the string potentially containing ANSI escapes
|
|
18
18
|
# @return [String] the string with all ANSI escape sequences removed
|
|
19
19
|
def strip_ansi(line)
|
|
20
|
-
line.to_s.gsub(ANSI_RE, '')
|
|
20
|
+
line.to_s.encode('UTF-8', invalid: :replace, undef: :replace).gsub(ANSI_RE, '')
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/ollama_chat/version.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# by hand; it is rewritten on every `rake version` invocation.
|
|
6
6
|
module OllamaChat
|
|
7
7
|
# The current version of the OllamaChat gem as a String.
|
|
8
|
-
VERSION = '0.0.
|
|
8
|
+
VERSION = '0.0.147'
|
|
9
9
|
VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
|
|
10
10
|
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
|
11
11
|
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
|
@@ -109,30 +109,22 @@ module OllamaChat::WebSearching
|
|
|
109
109
|
def manage_links(command)
|
|
110
110
|
case command
|
|
111
111
|
when 'clear'
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
else
|
|
129
|
-
feedback('Denied.', type: :denied)
|
|
130
|
-
confirm?(prompt: "\nā Press any key to continue (%s). ", timeout: 3)
|
|
131
|
-
end
|
|
132
|
-
when /./
|
|
133
|
-
links.delete(link)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
112
|
+
links_list = links.to_a
|
|
113
|
+
return feedback("List is empty.", type: :info) if links_list.empty?
|
|
114
|
+
|
|
115
|
+
picked = choose_multi(
|
|
116
|
+
%w[[ALL] [NONE]] + links_list,
|
|
117
|
+
all: '[ALL]',
|
|
118
|
+
none: '[NONE]',
|
|
119
|
+
prompt: 'Which links shall we sever? %s [Tab=toggle, Enter=apply, C-c=abort]',
|
|
120
|
+
) or return
|
|
121
|
+
return if picked.empty?
|
|
122
|
+
|
|
123
|
+
if confirm?(prompt: "š Sever #{picked.size} link(s)? (y/n) ", yes: /\Ay/i)
|
|
124
|
+
picked.each { links.delete(_1) }
|
|
125
|
+
feedback("Cleared #{picked.size} link(s).", type: :info)
|
|
126
|
+
else
|
|
127
|
+
feedback('Denied.', type: :denied)
|
|
136
128
|
end
|
|
137
129
|
when nil
|
|
138
130
|
if links.empty?
|
data/lib/ollama_chat.rb
CHANGED
data/ollama_chat.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: ollama_chat 0.0.
|
|
2
|
+
# stub: ollama_chat 0.0.147 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "ollama_chat".freeze
|
|
6
|
-
s.version = "0.0.
|
|
6
|
+
s.version = "0.0.147".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]
|
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
|
|
25
25
|
s.specification_version = 4
|
|
26
26
|
|
|
27
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.
|
|
27
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.24.1".freeze])
|
|
28
28
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.12".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])
|
|
@@ -32,9 +32,11 @@ Gem::Specification.new do |s|
|
|
|
32
32
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
|
33
33
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
|
34
34
|
s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
|
|
35
|
+
s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0".freeze])
|
|
36
|
+
s.add_runtime_dependency(%q<json-generic_object>.freeze, [">= 0.2.0".freeze])
|
|
35
37
|
s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
|
|
36
|
-
s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.
|
|
37
|
-
s.add_runtime_dependency(%q<documentrix>.freeze, [">= 0.8.
|
|
38
|
+
s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.27".freeze])
|
|
39
|
+
s.add_runtime_dependency(%q<documentrix>.freeze, [">= 0.8.1".freeze])
|
|
38
40
|
s.add_runtime_dependency(%q<unix_socks>.freeze, [">= 0.4".freeze])
|
|
39
41
|
s.add_runtime_dependency(%q<rss>.freeze, ["~> 0.3".freeze])
|
|
40
42
|
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
|
|
@@ -44,14 +46,14 @@ Gem::Specification.new do |s|
|
|
|
44
46
|
s.add_runtime_dependency(%q<kramdown-ansi>.freeze, ["~> 0.9".freeze])
|
|
45
47
|
s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze, ">= 0.22.2".freeze])
|
|
46
48
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.62".freeze])
|
|
47
|
-
s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0.
|
|
49
|
+
s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0.4".freeze])
|
|
48
50
|
s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.4".freeze])
|
|
49
51
|
s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
|
|
50
52
|
s.add_runtime_dependency(%q<bigdecimal>.freeze, ["~> 3.1".freeze])
|
|
51
53
|
s.add_runtime_dependency(%q<csv>.freeze, ["~> 3.0".freeze])
|
|
52
54
|
s.add_runtime_dependency(%q<const_conf>.freeze, ["~> 0.9".freeze])
|
|
53
55
|
s.add_runtime_dependency(%q<context_spook>.freeze, ["~> 1.7".freeze])
|
|
54
|
-
s.add_runtime_dependency(%q<infobar>.freeze, [">= 0.
|
|
56
|
+
s.add_runtime_dependency(%q<infobar>.freeze, [">= 0.16.0".freeze])
|
|
55
57
|
s.add_runtime_dependency(%q<rubyzip>.freeze, ["~> 3.0".freeze])
|
|
56
58
|
s.add_runtime_dependency(%q<sequel>.freeze, ["~> 5.0".freeze])
|
|
57
59
|
s.add_runtime_dependency(%q<file-tail>.freeze, ["~> 1.4".freeze])
|
|
@@ -870,19 +870,10 @@ describe OllamaChat::Commands, protect_env: true do
|
|
|
870
870
|
|
|
871
871
|
describe '/tools' do
|
|
872
872
|
it 'returns :next when input is "/tools"' do
|
|
873
|
-
expect(chat).to receive(:
|
|
873
|
+
expect(chat).to receive(:choose_tools)
|
|
874
874
|
expect(chat.handle_input("/tools")).to eq :next
|
|
875
875
|
end
|
|
876
876
|
|
|
877
|
-
it 'returns :next when input is "/tools enable"' do
|
|
878
|
-
expect(chat).to receive(:enable_tool)
|
|
879
|
-
expect(chat.handle_input("/tools enable")).to eq :next
|
|
880
|
-
end
|
|
881
|
-
|
|
882
|
-
it 'returns :next when input is "/tools disable"' do
|
|
883
|
-
expect(chat).to receive(:disable_tool)
|
|
884
|
-
expect(chat.handle_input("/tools disable")).to eq :next
|
|
885
|
-
end
|
|
886
877
|
it 'returns :next when input is "/tools on"' do
|
|
887
878
|
expect(chat.tools_support).to receive(:set).with(true, show: true)
|
|
888
879
|
expect(chat.handle_input("/tools on")).to eq :next
|
|
@@ -977,17 +968,10 @@ describe OllamaChat::Commands, protect_env: true do
|
|
|
977
968
|
end
|
|
978
969
|
|
|
979
970
|
describe '/favourite' do
|
|
980
|
-
it '
|
|
971
|
+
it 'opens the multi-select picker for each type' do
|
|
981
972
|
%w[model prompt system persona suggest].each do |type|
|
|
982
|
-
expect(chat).to receive(:
|
|
983
|
-
expect(chat.handle_input("/favourite
|
|
984
|
-
end
|
|
985
|
-
end
|
|
986
|
-
|
|
987
|
-
it 'deletes a favourite for each type' do
|
|
988
|
-
%w[model prompt system persona suggest].each do |type|
|
|
989
|
-
expect(chat).to receive(:delete_favourite).with(type)
|
|
990
|
-
expect(chat.handle_input("/favourite delete #{type}")).to eq :next
|
|
973
|
+
expect(chat).to receive(:choose_favourite).with(type)
|
|
974
|
+
expect(chat.handle_input("/favourite #{type}")).to eq :next
|
|
991
975
|
end
|
|
992
976
|
end
|
|
993
977
|
end
|
|
@@ -1151,6 +1135,13 @@ describe OllamaChat::Commands, protect_env: true do
|
|
|
1151
1135
|
end
|
|
1152
1136
|
end
|
|
1153
1137
|
|
|
1138
|
+
describe '/restart' do
|
|
1139
|
+
it 'returns :next when input is "/restart"' do
|
|
1140
|
+
expect(chat).to receive(:reload_config)
|
|
1141
|
+
expect(chat.handle_input("/restart")).to eq :next
|
|
1142
|
+
end
|
|
1143
|
+
end
|
|
1144
|
+
|
|
1154
1145
|
describe '/nixda' do
|
|
1155
1146
|
it 'returns :next when input is "/nixda"' do
|
|
1156
1147
|
expect(chat).to receive(:display_chat_help)
|