ollama_chat 0.0.87 → 0.0.88
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 +33 -0
- data/lib/ollama_chat/chat.rb +5 -4
- data/lib/ollama_chat/input_content.rb +7 -2
- data/lib/ollama_chat/message_list.rb +1 -1
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +1 -1
- data/lib/ollama_chat/source_fetching.rb +15 -21
- data/lib/ollama_chat/switches.rb +62 -5
- data/lib/ollama_chat/tools/directory_structure.rb +2 -1
- data/lib/ollama_chat/utils/analyze_directory.rb +2 -2
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +2 -2
- data/spec/ollama_chat/chat_spec.rb +0 -1
- data/spec/ollama_chat/message_list_spec.rb +3 -0
- data/spec/ollama_chat/source_fetching_spec.rb +1 -1
- data/spec/ollama_chat/switches_spec.rb +81 -4
- data/spec/ollama_chat/utils/analyze_directory_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f324fb61e2ee223925e1b539c1b553fa43d9ab03e94a8ef3531d16ff5937f900
|
|
4
|
+
data.tar.gz: 70955ecf696dad97193c20d14c7e2dbeaef5ce8cb9f38e121fc6c4b0672fdbce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ef76c2f4b15f9d4ffbf0361a5d70b8aad0fc4207520c4984cc19b6efb98763dd18be5cc830cfaa5bfa0a0cc8c2ba91738485652f717b423e7a0bebd23756123
|
|
7
|
+
data.tar.gz: c0c924035d0d17bc1dde13c41ad2ea73d1b7868336754f2bc1085038b550dca5770c8dba1bd401e4b9e76c3104e864d54ba14a8b6a555ad076ec7302e7cf2f3d
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-06-03 v0.0.88
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Implemented a transition callback system for switches via the
|
|
8
|
+
`PerformCallbacks` module, allowing `OllamaChat::Switches::Switch` and
|
|
9
|
+
`OllamaChat::Switches::DatabaseSwitch` to trigger procs on state changes.
|
|
10
|
+
- Added conditional inclusion of `runtime_info` in the system prompt based on
|
|
11
|
+
the state of `@chat.runtime_info.on?`.
|
|
12
|
+
- Automated system prompt resets when toggling runtime information by adding
|
|
13
|
+
callbacks to the `@runtime_info` switch that trigger `reset_system_prompt`.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Updated `lib/ollama_chat/chat.rb` to utilize `@messages.system_name` instead
|
|
18
|
+
of `@system` within the `change_system_prompt` method.
|
|
19
|
+
- Refactored file handling in `lib/ollama_chat/input_content.rb` by adding a
|
|
20
|
+
`skip_blank` parameter to `provide_file_set_content`, and updated
|
|
21
|
+
`summarize`, `embed`, and `import` commands to use `skip_blank: true`.
|
|
22
|
+
- Simplified directory exclusion logic in `analyze_directory.rb` by using
|
|
23
|
+
strings and `child.basename.fnmatch?` for pattern matching instead of
|
|
24
|
+
expanded `Pathname` objects.
|
|
25
|
+
- Refactored `embed` and `embed_source` in `lib/ollama_chat/source_fetching.rb`
|
|
26
|
+
using guard clauses and updated the corresponding prompt in
|
|
27
|
+
`default_config.yml`. You might need to reset the prompt for it to continue
|
|
28
|
+
working.
|
|
29
|
+
- Clarified documentation for the `suffix` parameter in the
|
|
30
|
+
`directory_structure` tool, including notes on filtering by file extensions.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- Corrected control flow within the summary writing loop.
|
|
35
|
+
|
|
3
36
|
## 2026-05-28 v0.0.87
|
|
4
37
|
|
|
5
38
|
### Features
|
data/lib/ollama_chat/chat.rb
CHANGED
|
@@ -424,7 +424,7 @@ class OllamaChat::Chat
|
|
|
424
424
|
when 'list'
|
|
425
425
|
list_system_prompts
|
|
426
426
|
when 'change'
|
|
427
|
-
change_system_prompt(@
|
|
427
|
+
change_system_prompt(@messages.system_name)
|
|
428
428
|
@messages.show_system_prompt
|
|
429
429
|
when 'duplicate'
|
|
430
430
|
duplicate_system_prompt
|
|
@@ -534,6 +534,7 @@ class OllamaChat::Chat
|
|
|
534
534
|
if summary.full?
|
|
535
535
|
filename.write(summary)
|
|
536
536
|
STDOUT.puts "File successfully written."
|
|
537
|
+
next :next
|
|
537
538
|
else
|
|
538
539
|
STDERR.puts "Nothing to summarize!"
|
|
539
540
|
next :next
|
|
@@ -907,7 +908,7 @@ class OllamaChat::Chat
|
|
|
907
908
|
words = opts.fetch(?w, 100)
|
|
908
909
|
all = opts.fetch(?a, false)
|
|
909
910
|
arg and patterns = arg.scan(/(\S+)/).flatten
|
|
910
|
-
next provide_file_set_content(patterns, all:) { summarize(_1, words:) } || :next
|
|
911
|
+
next provide_file_set_content(patterns, all:, skip_blank: true) { summarize(_1, words:) } || :next
|
|
911
912
|
elsif arg
|
|
912
913
|
words = opts.fetch(?w, 100)
|
|
913
914
|
source = arg
|
|
@@ -942,7 +943,7 @@ class OllamaChat::Chat
|
|
|
942
943
|
if opts[?p]
|
|
943
944
|
all = opts.fetch(?a, false)
|
|
944
945
|
arg and patterns = arg.scan(/(\S+)/).flatten
|
|
945
|
-
next provide_file_set_content(patterns, all:) { embed(_1, tags:) } || :next
|
|
946
|
+
next provide_file_set_content(patterns, all:, skip_blank: true) { embed(_1, tags:) } || :next
|
|
946
947
|
elsif arg
|
|
947
948
|
next embed(arg, tags:) || :next
|
|
948
949
|
else
|
|
@@ -972,7 +973,7 @@ class OllamaChat::Chat
|
|
|
972
973
|
if opts[?p]
|
|
973
974
|
all = opts.fetch(?a, false)
|
|
974
975
|
arg and patterns = arg.scan(/(\S+)/).flatten
|
|
975
|
-
next provide_file_set_content(patterns, all:) { import(_1) } || :next
|
|
976
|
+
next provide_file_set_content(patterns, all:, skip_blank: true) { import(_1) } || :next
|
|
976
977
|
elsif arg
|
|
977
978
|
source = arg
|
|
978
979
|
next import(source) || :next
|
|
@@ -140,10 +140,12 @@ module OllamaChat::InputContent
|
|
|
140
140
|
# @param patterns [Array<String>] # the glob patterns used to find files
|
|
141
141
|
# @param all [TrueClass, FalseClass] whether to process all matching files
|
|
142
142
|
# or let the caller choose a subset
|
|
143
|
+
# @param skip_blank [TrueClass, FalseClass] whether to skip appending
|
|
144
|
+
# to the result if the block returns a blank result
|
|
143
145
|
#
|
|
144
146
|
# @yield [filename] the block that processes each filename
|
|
145
147
|
# @return [String] the concatenated result of the block applied to each file
|
|
146
|
-
def provide_file_set_content(patterns, all: false, &block)
|
|
148
|
+
def provide_file_set_content(patterns, all: false, skip_blank: false, &block)
|
|
147
149
|
total = 0
|
|
148
150
|
all and file_set_each(patterns, all:) { total += 1 }
|
|
149
151
|
count = 0
|
|
@@ -154,7 +156,10 @@ module OllamaChat::InputContent
|
|
|
154
156
|
else
|
|
155
157
|
STDOUT.puts "Handling File (#{bold{count}}):"
|
|
156
158
|
end
|
|
157
|
-
|
|
159
|
+
block_result = block.(filename)
|
|
160
|
+
if !skip_blank || block_result.present?
|
|
161
|
+
result << ("%s:\n\n%s\n\n" % [ filename, block_result ])
|
|
162
|
+
end
|
|
158
163
|
end.full?
|
|
159
164
|
end
|
|
160
165
|
end
|
|
@@ -348,7 +348,7 @@ class OllamaChat::MessageList
|
|
|
348
348
|
@messages.reject! { |msg| msg.role == 'system' }
|
|
349
349
|
templates_values = {
|
|
350
350
|
persona: @chat.default_persona_profile,
|
|
351
|
-
runtime_info: @chat.static_runtime_information,
|
|
351
|
+
runtime_info: (@chat.static_runtime_information if @chat.runtime_info.on?),
|
|
352
352
|
}
|
|
353
353
|
if new_system_prompt = system.full? { _1.to_s % templates_values }
|
|
354
354
|
@system = new_system_prompt
|
|
@@ -24,7 +24,7 @@ infobar:
|
|
|
24
24
|
:frames: :braille181
|
|
25
25
|
:message: ✓
|
|
26
26
|
prompts:
|
|
27
|
-
embed: "This source has been added to or updated in collection %{collection}
|
|
27
|
+
embed: "This source has been added to or updated in collection \"%{collection}\"."
|
|
28
28
|
summarize: |
|
|
29
29
|
Generate an abstract summary of the content in this document using
|
|
30
30
|
%{words} words:
|
|
@@ -174,13 +174,6 @@ module OllamaChat::SourceFetching
|
|
|
174
174
|
# nil if embedding is disabled or fails
|
|
175
175
|
def embed_source(source_io, source, tags: [], count: nil)
|
|
176
176
|
@embedding.on? or return parse_source(source_io)
|
|
177
|
-
m = "Embedding #{italic { source_io&.content_type }} document "\
|
|
178
|
-
"#{source.to_s.inspect} in collection #{collection.to_s.inspect}."
|
|
179
|
-
if count
|
|
180
|
-
STDOUT.puts '%u. %s' % [ count, m ]
|
|
181
|
-
else
|
|
182
|
-
STDOUT.puts m
|
|
183
|
-
end
|
|
184
177
|
unless @documents.source_modified?(source)
|
|
185
178
|
STDOUT.puts "Source #{source.to_s.inspect} already up-to-date. => Skipping."
|
|
186
179
|
return
|
|
@@ -212,6 +205,13 @@ module OllamaChat::SourceFetching
|
|
|
212
205
|
)
|
|
213
206
|
end
|
|
214
207
|
inputs or return
|
|
208
|
+
m = "Embedded #{italic { source_io&.content_type }} document "\
|
|
209
|
+
"#{source.to_s.inspect} in collection #{collection.to_s.inspect}."
|
|
210
|
+
if count
|
|
211
|
+
STDOUT.puts '%u. %s' % [ count, m ]
|
|
212
|
+
else
|
|
213
|
+
STDOUT.puts m
|
|
214
|
+
end
|
|
215
215
|
source = source.to_s
|
|
216
216
|
command = false
|
|
217
217
|
if source.start_with?(?!)
|
|
@@ -231,8 +231,7 @@ module OllamaChat::SourceFetching
|
|
|
231
231
|
# Embeds content from the specified source.
|
|
232
232
|
#
|
|
233
233
|
# This method fetches content from a given source (command, URL, or file) and
|
|
234
|
-
# processes it for embedding using the embed_source method.
|
|
235
|
-
# disabled, it falls back to generating a summary instead.
|
|
234
|
+
# processes it for embedding using the embed_source method.
|
|
236
235
|
#
|
|
237
236
|
# @param source [String] The source identifier which can be a command, URL,
|
|
238
237
|
# or file path
|
|
@@ -240,19 +239,14 @@ module OllamaChat::SourceFetching
|
|
|
240
239
|
# @return [String, nil] The formatted embedding result or summary message, or
|
|
241
240
|
# nil if the operation fails
|
|
242
241
|
def embed(source, tags: [])
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
embed_source(source_io, source, tags:)
|
|
250
|
-
end
|
|
251
|
-
prompt(:embed).to_s % { source:, collection: collection }
|
|
252
|
-
else
|
|
253
|
-
STDOUT.puts "Embedding is off, so I will just give a small summary of this source."
|
|
254
|
-
summarize(source)
|
|
242
|
+
@embedding.on? or return
|
|
243
|
+
fetch_source(source) do |source_io|
|
|
244
|
+
content = parse_source(source_io)
|
|
245
|
+
content.present? or return
|
|
246
|
+
source_io.rewind
|
|
247
|
+
embed_source(source_io, source, tags:) or return
|
|
255
248
|
end
|
|
249
|
+
prompt(:embed).to_s % { collection: collection }
|
|
256
250
|
end
|
|
257
251
|
|
|
258
252
|
private
|
data/lib/ollama_chat/switches.rb
CHANGED
|
@@ -45,6 +45,47 @@ module OllamaChat::Switches
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# A module that intercepts switch state changes to execute registered callbacks.
|
|
49
|
+
#
|
|
50
|
+
# This module is designed to be prepended into switch classes. It captures
|
|
51
|
+
# the value before and after a change occurs, then triggers any proc
|
|
52
|
+
# associated with that specific transition in the `@callbacks` hash.
|
|
53
|
+
module PerformCallbacks
|
|
54
|
+
# Intercepts the set operation to trigger state-transition callbacks.
|
|
55
|
+
#
|
|
56
|
+
# @param a [Array] positional arguments passed to the original set method
|
|
57
|
+
# @param kw [Hash] keyword arguments passed to the original set method
|
|
58
|
+
# @return [Object] the result of the original set method
|
|
59
|
+
def set(*a, **kw)
|
|
60
|
+
before_value = value
|
|
61
|
+
result = super
|
|
62
|
+
perform_callbacks(before_value)
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Intercepts the toggle operation to trigger state-transition callbacks.
|
|
67
|
+
#
|
|
68
|
+
# @param kw [Hash] keyword arguments passed to the original toggle method
|
|
69
|
+
# @return [Object] the result of the original toggle method
|
|
70
|
+
def toggle(**kw)
|
|
71
|
+
before_value = value
|
|
72
|
+
result = super
|
|
73
|
+
perform_callbacks(before_value)
|
|
74
|
+
result
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
# Executes the callback proc associated with the current state transition.
|
|
80
|
+
#
|
|
81
|
+
# @param before_value [Boolean] the state of the switch before the change
|
|
82
|
+
# @return [self] the current instance
|
|
83
|
+
def perform_callbacks(before_value)
|
|
84
|
+
@callbacks[[ before_value, value ]]&.(before_value, value)
|
|
85
|
+
self
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
48
89
|
# A switch class that manages boolean state with toggle and set functionality.
|
|
49
90
|
#
|
|
50
91
|
# The Switch class provides a simple way to manage boolean configuration
|
|
@@ -62,9 +103,12 @@ module OllamaChat::Switches
|
|
|
62
103
|
#
|
|
63
104
|
# @param msg [Hash{Boolean => String}] a hash containing true and false messages
|
|
64
105
|
# @param value [Object] the initial state of the switch (coerced to boolean)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
106
|
+
# @param callbacks [Hash{[Boolean, Boolean] => Proc}] optional mapping of
|
|
107
|
+
# state transitions to callback procs. Keys are `[old_value, new_value]`.
|
|
108
|
+
def initialize(msg:, value:, callbacks: {})
|
|
109
|
+
@value = !!value
|
|
110
|
+
@msg = msg
|
|
111
|
+
@callbacks = callbacks.to_h
|
|
68
112
|
end
|
|
69
113
|
|
|
70
114
|
# @!attribute [r] value
|
|
@@ -92,6 +136,7 @@ module OllamaChat::Switches
|
|
|
92
136
|
end
|
|
93
137
|
|
|
94
138
|
include CheckSwitch
|
|
139
|
+
prepend PerformCallbacks
|
|
95
140
|
end
|
|
96
141
|
|
|
97
142
|
# Manages boolean configuration states that are persisted in the database.
|
|
@@ -105,10 +150,13 @@ module OllamaChat::Switches
|
|
|
105
150
|
# @param chat [OllamaChat::Chat] the chat instance providing session access
|
|
106
151
|
# @param msg [Hash{Boolean => String}] the message hash containing display messages
|
|
107
152
|
# @param attribute [Symbol] the database attribute name to manage
|
|
108
|
-
|
|
153
|
+
# @param callbacks [Hash{[Boolean, Boolean] => Proc}] optional mapping of
|
|
154
|
+
# state transitions to callback procs. Keys are `[old_value, new_value]`.
|
|
155
|
+
def initialize(chat:, msg:, attribute:, callbacks: {})
|
|
109
156
|
@chat = chat
|
|
110
157
|
@attribute = attribute
|
|
111
|
-
@msg
|
|
158
|
+
@msg = msg
|
|
159
|
+
@callbacks = callbacks.to_h
|
|
112
160
|
end
|
|
113
161
|
|
|
114
162
|
# Returns the current value of the attribute from the session.
|
|
@@ -143,6 +191,7 @@ module OllamaChat::Switches
|
|
|
143
191
|
end
|
|
144
192
|
|
|
145
193
|
include CheckSwitch
|
|
194
|
+
prepend PerformCallbacks
|
|
146
195
|
end
|
|
147
196
|
|
|
148
197
|
# Manages a boolean state based on a dynamic proc evaluation.
|
|
@@ -315,12 +364,20 @@ module OllamaChat::Switches
|
|
|
315
364
|
}
|
|
316
365
|
)
|
|
317
366
|
|
|
367
|
+
reset_system_prompt = -> * {
|
|
368
|
+
messages.set_system_prompt(messages.system_name)
|
|
369
|
+
}
|
|
370
|
+
|
|
318
371
|
@runtime_info = DatabaseSwitch.new(
|
|
319
372
|
chat: self,
|
|
320
373
|
attribute: :runtime_info_enabled,
|
|
321
374
|
msg: {
|
|
322
375
|
true => "Runtime Information enabled.",
|
|
323
376
|
false => "Runtime Information disabled.",
|
|
377
|
+
},
|
|
378
|
+
callbacks: {
|
|
379
|
+
[ false, true ] => reset_system_prompt,
|
|
380
|
+
[ true, false ] => reset_system_prompt,
|
|
324
381
|
}
|
|
325
382
|
)
|
|
326
383
|
|
|
@@ -27,7 +27,8 @@ class OllamaChat::Tools::DirectoryStructure
|
|
|
27
27
|
name:,
|
|
28
28
|
description: <<~EOT,
|
|
29
29
|
Tree viewer – Returns JSON describing files/folders under path up to
|
|
30
|
-
max_depth (<= height of the tree)
|
|
30
|
+
max_depth (<= height of the tree), optionally only files ending with
|
|
31
|
+
suffix, e. g. rb for ruby files. Handy for locating resources or
|
|
31
32
|
presenting a project layout.
|
|
32
33
|
EOT
|
|
33
34
|
parameters: Tool::Function::Parameters.new(
|
|
@@ -95,7 +95,7 @@ module OllamaChat::Utils::AnalyzeDirectory
|
|
|
95
95
|
#
|
|
96
96
|
# @api private
|
|
97
97
|
def recurse_generate_structure(path = '.', exclude: [], suffix: nil, depth: 0)
|
|
98
|
-
exclude = Array(exclude).map
|
|
98
|
+
exclude = Array(exclude).map(&:to_s)
|
|
99
99
|
extname = suffix&.sub(/\A(?<!.)/, ?.)
|
|
100
100
|
path = Pathname.new(path).expand_path
|
|
101
101
|
entries = []
|
|
@@ -106,7 +106,7 @@ module OllamaChat::Utils::AnalyzeDirectory
|
|
|
106
106
|
# Skip symlinks
|
|
107
107
|
next if child.symlink?
|
|
108
108
|
# Skip user‑excluded paths
|
|
109
|
-
next if exclude.any? { |e| child.fnmatch?(e.to_s, File::FNM_PATHNAME) }
|
|
109
|
+
next if exclude.any? { |e| child.basename.fnmatch?(e.to_s, File::FNM_PATHNAME) }
|
|
110
110
|
|
|
111
111
|
if child.directory?
|
|
112
112
|
entries << {
|
data/lib/ollama_chat/version.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.88 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.88".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]
|
|
@@ -82,7 +82,6 @@ describe OllamaChat::Chat, protect_env: true do
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it 'returns :next when input is "/toggle nixda"' do
|
|
85
|
-
expect_any_instance_of(OllamaChat::Switches::Switch).not_to receive(:toggle)
|
|
86
85
|
expect(chat).to receive(:display_chat_help)
|
|
87
86
|
expect(chat.handle_input("/toggle nixda")).to eq :next
|
|
88
87
|
end
|
|
@@ -202,6 +202,7 @@ describe OllamaChat::MessageList do
|
|
|
202
202
|
|
|
203
203
|
it 'can list conversations with thinking' do
|
|
204
204
|
expect(chat).to receive(:system_prompt)
|
|
205
|
+
expect(chat).to receive(:runtime_info).and_return(double(on?: true))
|
|
205
206
|
expect(chat).to receive(:static_runtime_information)
|
|
206
207
|
expect(chat).to receive(:default_persona_profile)
|
|
207
208
|
expect(chat).to receive(:markdown).
|
|
@@ -249,6 +250,7 @@ describe OllamaChat::MessageList do
|
|
|
249
250
|
expect(list.messages.count { _1.role == 'system' }).to eq 0
|
|
250
251
|
expect(chat).to receive(:default_persona_profile).and_return(nil)
|
|
251
252
|
expect(chat).to receive(:system_prompt).and_return('test prompt')
|
|
253
|
+
expect(chat).to receive(:runtime_info).and_return(double(on?: true))
|
|
252
254
|
expect(chat).to receive(:static_runtime_information)
|
|
253
255
|
expect {
|
|
254
256
|
expect(list.set_system_prompt('test_prompt')).to eq list
|
|
@@ -260,6 +262,7 @@ describe OllamaChat::MessageList do
|
|
|
260
262
|
expect(chat).to receive(:default_persona_profile).and_return(nil).at_least(1)
|
|
261
263
|
list.messages.clear
|
|
262
264
|
expect(chat).to receive(:system_prompt).and_return('first prompt')
|
|
265
|
+
expect(chat).to receive(:runtime_info).and_return(double(on?: true)).at_least(1)
|
|
263
266
|
expect(chat).to receive(:static_runtime_information).at_least(1)
|
|
264
267
|
expect(list.messages.count { _1.role == 'system' }).to eq 0
|
|
265
268
|
list.set_system_prompt('first_prompt')
|
|
@@ -31,7 +31,7 @@ describe OllamaChat::SourceFetching do
|
|
|
31
31
|
'./spec/assets/example.html'
|
|
32
32
|
)
|
|
33
33
|
expect(chat.embed('./spec/assets/example.html')).to eq(
|
|
34
|
-
'This source has been added to or updated in collection default
|
|
34
|
+
'This source has been added to or updated in collection "default".'
|
|
35
35
|
)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -10,6 +10,46 @@ describe OllamaChat::Switches do
|
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
context 'callbacks' do
|
|
14
|
+
let(:callback_on) { double('callback_on') }
|
|
15
|
+
let(:callback_off) { double('callback_off') }
|
|
16
|
+
let :switch do
|
|
17
|
+
described_class.new(
|
|
18
|
+
value: false,
|
|
19
|
+
msg: { true => "On", false => "Off" },
|
|
20
|
+
callbacks: {
|
|
21
|
+
[false, true] => callback_on,
|
|
22
|
+
[true, false] => callback_off
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'triggers the on-callback when switching from false to true' do
|
|
28
|
+
expect(callback_on).to receive(:call).with(false, true)
|
|
29
|
+
expect(callback_off).not_to receive(:call)
|
|
30
|
+
switch.set(true)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'triggers the off-callback when switching from true to false' do
|
|
34
|
+
expect(callback_on).to receive(:call).with(false, true)
|
|
35
|
+
switch.set(true) # Setup state to true
|
|
36
|
+
expect(callback_off).to receive(:call).with(true, false)
|
|
37
|
+
expect(callback_on).not_to receive(:call)
|
|
38
|
+
switch.set(false)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'does not trigger any callback when value remains the same' do
|
|
42
|
+
expect(callback_on).not_to receive(:call)
|
|
43
|
+
expect(callback_off).not_to receive(:call)
|
|
44
|
+
switch.set(false)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'triggers callbacks via toggle' do
|
|
48
|
+
expect(callback_on).to receive(:call).with(false, true)
|
|
49
|
+
switch.toggle
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
13
53
|
context 'default to false' do
|
|
14
54
|
let :config do
|
|
15
55
|
double(test: false)
|
|
@@ -77,9 +117,46 @@ describe OllamaChat::Switches do
|
|
|
77
117
|
)
|
|
78
118
|
end
|
|
79
119
|
|
|
120
|
+
context 'callbacks' do
|
|
121
|
+
let(:callback_on) { double('callback_on') }
|
|
122
|
+
let(:callback_off) { double('callback_off') }
|
|
123
|
+
let :switch do
|
|
124
|
+
described_class.new(
|
|
125
|
+
chat: chat,
|
|
126
|
+
attribute: :test,
|
|
127
|
+
msg: { true => "On", false => "Off" },
|
|
128
|
+
callbacks: {
|
|
129
|
+
[false, true] => callback_on,
|
|
130
|
+
[true, false] => callback_off
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'triggers the on-callback when switching from false to true' do
|
|
136
|
+
expect(session).to receive(:send).with(:test).and_return false, true, true
|
|
137
|
+
expect(session).to receive(:update).with("test": true)
|
|
138
|
+
expect(callback_on).to receive(:call).with(false, true)
|
|
139
|
+
switch.set(true)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'triggers the off-callback when switching from true to false' do
|
|
143
|
+
expect(session).to receive(:send).with(:test).and_return true, false, false
|
|
144
|
+
expect(session).to receive(:update).with("test": false)
|
|
145
|
+
expect(callback_off).to receive(:call).with(true, false)
|
|
146
|
+
switch.set(false)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'does not trigger callbacks when value remains the same' do
|
|
150
|
+
expect(session).to receive(:send).with(:test).and_return false, false
|
|
151
|
+
expect(session).to receive(:update).with("test": false)
|
|
152
|
+
expect(callback_on).not_to receive(:call)
|
|
153
|
+
switch.set(false)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
80
157
|
context 'default to false' do
|
|
81
158
|
it 'can be switched on' do
|
|
82
|
-
expect(session).to receive(:send).with(:test).and_return false, true
|
|
159
|
+
expect(session).to receive(:send).with(:test).and_return false, false, true, true
|
|
83
160
|
expect(session).to receive(:update).with("test": true)
|
|
84
161
|
expect {
|
|
85
162
|
switch.set(true)
|
|
@@ -89,7 +166,7 @@ describe OllamaChat::Switches do
|
|
|
89
166
|
end
|
|
90
167
|
|
|
91
168
|
it 'can be toggled on' do
|
|
92
|
-
expect(session).to receive(:send).with(:test).and_return false, false, true, true
|
|
169
|
+
expect(session).to receive(:send).with(:test).and_return false, false, false, true, true, true
|
|
93
170
|
expect(session).to receive(:update).with("test": true)
|
|
94
171
|
expect(STDOUT).to receive(:puts).with('Enabled.')
|
|
95
172
|
expect {
|
|
@@ -102,7 +179,7 @@ describe OllamaChat::Switches do
|
|
|
102
179
|
|
|
103
180
|
context 'default to true' do
|
|
104
181
|
it 'can be switched on' do
|
|
105
|
-
expect(session).to receive(:send).with(:test).and_return true, false
|
|
182
|
+
expect(session).to receive(:send).with(:test).and_return true, true, false, false
|
|
106
183
|
expect(session).to receive(:update).with("test": false)
|
|
107
184
|
expect {
|
|
108
185
|
switch.set(false)
|
|
@@ -112,7 +189,7 @@ describe OllamaChat::Switches do
|
|
|
112
189
|
end
|
|
113
190
|
|
|
114
191
|
it 'can be toggled off' do
|
|
115
|
-
expect(session).to receive(:send).with(:test).and_return true, true, false, false
|
|
192
|
+
expect(session).to receive(:send).with(:test).and_return true, true, true, false, false, false
|
|
116
193
|
expect(session).to receive(:update).with("test": false)
|
|
117
194
|
expect(STDOUT).to receive(:puts).with('Disabled.')
|
|
118
195
|
expect {
|
|
@@ -92,7 +92,7 @@ describe OllamaChat::Utils::AnalyzeDirectory do
|
|
|
92
92
|
after { FileUtils.remove_entry(@tmp_dir) }
|
|
93
93
|
|
|
94
94
|
it 'skips directories listed in the exclude list' do
|
|
95
|
-
result = generate.call(@tmp_dir, exclude: [
|
|
95
|
+
result = generate.call(@tmp_dir, exclude: %w[ exclude_me ])
|
|
96
96
|
names = result.map { |e| e[:name] }
|
|
97
97
|
|
|
98
98
|
expect(names).not_to include('exclude_me')
|