ollama_chat 0.0.30 → 0.0.31
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 +30 -0
- data/lib/ollama_chat/parsing.rb +31 -14
- data/lib/ollama_chat/source_fetching.rb +31 -8
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +4 -4
- data/spec/assets/example_with_quote.html +10 -0
- data/spec/ollama_chat/clipboard_spec.rb +1 -0
- data/spec/ollama_chat/parsing_spec.rb +38 -4
- data/spec/ollama_chat/source_fetching_spec.rb +62 -0
- data/spec/spec_helper.rb +8 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '025319afc822ea46074061e5976aed1aa34f6ebe45e305bc570d58bc7883a30e'
|
4
|
+
data.tar.gz: eeed845da1c216ab6c38052655db1249c7f15bed25d10df2c8bb7a8578984325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79d81e5087a74486ec98dbad3ddc91099b6fda1a4a3c26365f7ff5a7e0c14934d806741ae26ecf5534002d4e47a46cd70abbbda681cff95d58925c882ff7cef
|
7
|
+
data.tar.gz: 696a4e5089a5b4d43729b2c0552721528dbc8647d66e538166e274ab422f422239d449f992d63679a440e54e88ae544b1672d484902f6ca55d2e91f1299caa25
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2025-09-15 v0.0.31
|
4
|
+
|
5
|
+
- Added new test asset file `"spec/assets/example with \".html"` as
|
6
|
+
`spec/assets/example_with_quote.html`
|
7
|
+
- Enhanced parsing tests in `spec/ollama_chat/parsing_spec.rb` to support file
|
8
|
+
URLs with spaces and quotes
|
9
|
+
- Added cleanup code using `FileUtils.rm_f` in test cases to remove temporary
|
10
|
+
files
|
11
|
+
- Modified test method names to reflect support for spaces and quotes in file
|
12
|
+
paths
|
13
|
+
- Added `ghostscript` package to the Dockerfile dependencies
|
14
|
+
- Added `fail_fast: true` to the script configuration
|
15
|
+
- Added a check for `pbcopy` command in clipboard spec
|
16
|
+
- Wrapped SimpleCov require in begin/rescue block to handle LoadError
|
17
|
+
- Set default `OLLAMA_HOST` environment variable to 'localhost:11434' in spec
|
18
|
+
helper
|
19
|
+
- Added `CONTENT_REGEXP` for unified parsing of URLs, tags, and file references
|
20
|
+
- Updated `parse_content` method to use new regex and support quoted file paths
|
21
|
+
- Introduced `check_exist:` option in `fetch_source` to validate file existence
|
22
|
+
- Extracted file reading logic into new helper method
|
23
|
+
`fetch_source_as_filename`
|
24
|
+
- Enhanced handling of file URLs with spaces and special characters
|
25
|
+
- Added comprehensive tests for parsing file paths with spaces, quotes, and
|
26
|
+
encoding
|
27
|
+
- Supported `file://` URI decoding using `URI.decode_www_form_component`
|
28
|
+
- Refactored `fetch_source` to better handle relative, absolute, and tilde
|
29
|
+
paths
|
30
|
+
- Updated spec files to use `Pathname` and improved assertions for file content
|
31
|
+
- Updated `gem_hadar` development dependency version from **2.3** to **2.6**
|
32
|
+
|
3
33
|
## 2025-09-11 v0.0.30
|
4
34
|
|
5
35
|
- Changed `config.prompts.web_import` to `config.prompts.web_summarize` in default branch
|
data/lib/ollama_chat/parsing.rb
CHANGED
@@ -189,6 +189,21 @@ module OllamaChat::Parsing
|
|
189
189
|
)
|
190
190
|
end
|
191
191
|
|
192
|
+
CONTENT_REGEXP = %r{
|
193
|
+
(https?://\S+) # Match HTTP/HTTPS URLs
|
194
|
+
| # OR
|
195
|
+
(?<![a-zA-Z\d]) # Negative lookbehind: not part of a larger word
|
196
|
+
\# # Literal # character (starts a tag)
|
197
|
+
([\w\]\[]+) # Tag content: alphanumeric, brackets, underscores
|
198
|
+
| # OR
|
199
|
+
(file://(?:[^\s#]+)) # Match file:// URLs
|
200
|
+
| # OR
|
201
|
+
"((?:\.\.|[~.]?)/(?:\\"|\\|[^"\\]+)+)" # Quoted file path with escaped " quotes
|
202
|
+
| # OR
|
203
|
+
(\S*\/\S+) # File path with at least one forward slash
|
204
|
+
}x
|
205
|
+
private_constant :CONTENT_REGEXP
|
206
|
+
|
192
207
|
# Parses content and processes embedded resources based on document policy
|
193
208
|
#
|
194
209
|
# This method analyzes input content for URLs, tags, and file references,
|
@@ -203,28 +218,30 @@ module OllamaChat::Parsing
|
|
203
218
|
def parse_content(content, images)
|
204
219
|
images.clear
|
205
220
|
tags = Documentrix::Utils::Tags.new valid_tag: /\A#*([\w\]\[]+)/
|
206
|
-
|
207
221
|
contents = [ content ]
|
208
|
-
content.scan(
|
222
|
+
content.scan(CONTENT_REGEXP).each { |url, tag, file_url, quoted_file, file|
|
223
|
+
check_exist = false
|
209
224
|
case
|
210
225
|
when tag
|
211
226
|
tags.add(tag)
|
212
227
|
next
|
213
|
-
when file
|
214
|
-
file = file.sub(/#.*/, '')
|
215
|
-
file =~ %r(\A[~./]) or file.prepend('./')
|
216
|
-
file = begin
|
217
|
-
File.expand_path(file)
|
218
|
-
rescue ArgumentError
|
219
|
-
next
|
220
|
-
end
|
221
|
-
File.exist?(file) or next
|
222
|
-
source = file
|
223
228
|
when url
|
224
229
|
links.add(url.to_s)
|
225
230
|
source = url
|
231
|
+
when file_url
|
232
|
+
check_exist = true
|
233
|
+
source = file_url
|
234
|
+
when quoted_file
|
235
|
+
file = quoted_file.gsub('\"', ?")
|
236
|
+
file =~ %r(\A[~./]) or file.prepend('./')
|
237
|
+
check_exist = true
|
238
|
+
source = file
|
239
|
+
when file
|
240
|
+
file =~ %r(\A[~./]) or file.prepend('./')
|
241
|
+
check_exist = true
|
242
|
+
source = file
|
226
243
|
end
|
227
|
-
fetch_source(source) do |source_io|
|
244
|
+
fetch_source(source, check_exist:) do |source_io|
|
228
245
|
case source_io&.content_type&.media_type
|
229
246
|
when 'image'
|
230
247
|
add_image(images, source_io, source)
|
@@ -246,7 +263,7 @@ module OllamaChat::Parsing
|
|
246
263
|
)
|
247
264
|
end
|
248
265
|
end
|
249
|
-
|
266
|
+
}
|
250
267
|
new_content = contents.select { _1.present? rescue nil }.compact * "\n\n"
|
251
268
|
return new_content, (tags unless tags.empty?)
|
252
269
|
end
|
@@ -52,14 +52,14 @@ module OllamaChat::SourceFetching
|
|
52
52
|
# @param source [ String ] the source identifier which can be a command, URL, or file path
|
53
53
|
#
|
54
54
|
# @yield [ tmp ]
|
55
|
-
def fetch_source(source, &block)
|
55
|
+
def fetch_source(source, check_exist: false, &block)
|
56
56
|
case source
|
57
|
-
when %r
|
57
|
+
when %r{\A!(.*)}
|
58
58
|
command = $1
|
59
59
|
OllamaChat::Utils::Fetcher.execute(command) do |tmp|
|
60
60
|
block.(tmp)
|
61
61
|
end
|
62
|
-
when %r
|
62
|
+
when %r{\Ahttps?://\S+}
|
63
63
|
links.add(source.to_s)
|
64
64
|
OllamaChat::Utils::Fetcher.get(
|
65
65
|
source,
|
@@ -70,12 +70,20 @@ module OllamaChat::SourceFetching
|
|
70
70
|
) do |tmp|
|
71
71
|
block.(tmp)
|
72
72
|
end
|
73
|
-
when %r
|
74
|
-
filename =
|
73
|
+
when %r{\Afile://([^\s#]+)}
|
74
|
+
filename = URI.decode_www_form_component($1)
|
75
75
|
filename = File.expand_path(filename)
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
check_exist && !File.exist?(filename) and return
|
77
|
+
fetch_source_as_filename(filename, &block)
|
78
|
+
when %r{\A((?:\.\.|[~.]?)/(?:\ |\S+)*)}
|
79
|
+
filename = File.expand_path($1)
|
80
|
+
check_exist && !File.exist?(filename) and return
|
81
|
+
fetch_source_as_filename(filename, &block)
|
82
|
+
when %r{\A"((?:\.\.|[~.]?)/(?:\\"|\\|[^"\\]+)+)"}
|
83
|
+
filename = $1.gsub('\"', ?")
|
84
|
+
filename = File.expand_path(filename)
|
85
|
+
check_exist && !File.exist?(filename) and return
|
86
|
+
fetch_source_as_filename(filename, &block)
|
79
87
|
else
|
80
88
|
raise "invalid source #{source.inspect}"
|
81
89
|
end
|
@@ -83,6 +91,21 @@ module OllamaChat::SourceFetching
|
|
83
91
|
STDERR.puts "Cannot fetch source #{source.to_s.inspect}: #{e.class} #{e}\n#{e.backtrace * ?\n}"
|
84
92
|
end
|
85
93
|
|
94
|
+
# Reads a file and extends it with header extension metadata. It then yields
|
95
|
+
# the file to the provided block for processing. If the file does not exist,
|
96
|
+
# it outputs an error message to standard error.
|
97
|
+
#
|
98
|
+
# @param filename [ String ] the path to the file to be read
|
99
|
+
#
|
100
|
+
# @yield [ file ] yields the opened file with header extension
|
101
|
+
#
|
102
|
+
# @return [ nil ] returns nil if the file does not exist
|
103
|
+
# @return [ Object ] returns the result of the block execution if the file exists
|
104
|
+
private def fetch_source_as_filename(filename, &block)
|
105
|
+
OllamaChat::Utils::Fetcher.read(filename) do |tmp|
|
106
|
+
block.(tmp)
|
107
|
+
end
|
108
|
+
end
|
86
109
|
|
87
110
|
# Adds an image to the images collection from the given source IO and source
|
88
111
|
# identifier.
|
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.31 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.31".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]
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["ollama_chat".freeze, "ollama_chat_send".freeze]
|
15
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]
|
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/example_with_quote.html".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]
|
@@ -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.6".freeze])
|
28
28
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".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])
|
@@ -8,6 +8,7 @@ describe OllamaChat::Clipboard do
|
|
8
8
|
connect_to_ollama_server
|
9
9
|
|
10
10
|
it 'can copy to clipboard' do
|
11
|
+
`which pbcopy`.full? or skip 'pbcopy not in path'
|
11
12
|
expect(STDERR).to receive(:puts).with(/No response available to copy to the system clipboard/)
|
12
13
|
expect(chat.copy_to_clipboard).to be_nil
|
13
14
|
chat.instance_variable_get(:@messages).load_conversation(asset('conversation.json'))
|
@@ -167,9 +167,10 @@ EOT
|
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'can parse file URLs' do
|
170
|
-
|
170
|
+
source_path= Pathname.pwd.join('spec/assets/example.html')
|
171
|
+
content, = chat.parse_content("see file://#{source_path}", [])
|
171
172
|
expect(content).to include(<<~EOT)
|
172
|
-
Imported "
|
173
|
+
Imported "file://#{source_path}":
|
173
174
|
|
174
175
|
# My First Heading
|
175
176
|
|
@@ -177,15 +178,48 @@ EOT
|
|
177
178
|
EOT
|
178
179
|
end
|
179
180
|
|
181
|
+
it 'can parse file URLs with spaces and quotes' do
|
182
|
+
file_path = Pathname.pwd.join('spec/assets/example with ".html')
|
183
|
+
FileUtils.cp 'spec/assets/example_with_quote.html', file_path
|
184
|
+
file_url = "file://#{file_path.to_s.gsub(' ', '%20').gsub('"', '%22')}"
|
185
|
+
content, = chat.parse_content("see #{file_url}", [])
|
186
|
+
expect(content).to include(<<~EOT)
|
187
|
+
Imported "#{file_url}":
|
188
|
+
|
189
|
+
# My First Heading
|
190
|
+
|
191
|
+
My first paragraph.
|
192
|
+
EOT
|
193
|
+
ensure
|
194
|
+
FileUtils.rm_f file_path
|
195
|
+
end
|
196
|
+
|
180
197
|
it 'can parse file paths' do
|
181
|
-
|
198
|
+
file_path = Pathname.pwd.join('spec/assets/example.html')
|
199
|
+
content, = chat.parse_content("see #{file_path}", [])
|
200
|
+
expect(content).to include(<<~EOT)
|
201
|
+
Imported "#{file_path}":
|
202
|
+
|
203
|
+
# My First Heading
|
204
|
+
|
205
|
+
My first paragraph.
|
206
|
+
EOT
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'can parse quoted file paths' do
|
210
|
+
file_path = Pathname.pwd.join('spec/assets/example with ".html')
|
211
|
+
FileUtils.cp 'spec/assets/example_with_quote.html', file_path
|
212
|
+
quoted_file_path = file_path.to_s.gsub('"', '\"')
|
213
|
+
content, = chat.parse_content(%{see "#{quoted_file_path}"}, [])
|
182
214
|
expect(content).to include(<<~EOT)
|
183
|
-
Imported "#{
|
215
|
+
Imported "#{quoted_file_path}":
|
184
216
|
|
185
217
|
# My First Heading
|
186
218
|
|
187
219
|
My first paragraph.
|
188
220
|
EOT
|
221
|
+
ensure
|
222
|
+
FileUtils.rm_f file_path
|
189
223
|
end
|
190
224
|
|
191
225
|
it 'can add images' do
|
@@ -36,4 +36,66 @@ describe OllamaChat::SourceFetching do
|
|
36
36
|
'This source was now embedded: ./spec/assets/example.html'
|
37
37
|
)
|
38
38
|
end
|
39
|
+
|
40
|
+
describe '#fetch_source' do
|
41
|
+
context 'with filename' do
|
42
|
+
it 'can handle files without spaces' do
|
43
|
+
source = './spec/assets/example.html'
|
44
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
45
|
+
with(File.expand_path(source))
|
46
|
+
chat.fetch_source(source)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can handle files with \\ escaped spaces' do
|
50
|
+
source = './spec/assets/file\ with\ spaces.html'
|
51
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
52
|
+
with(File.expand_path(source))
|
53
|
+
chat.fetch_source(source)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can handle files with spaces in " quotes' do
|
57
|
+
source = '"./spec/assets/file with spaces.html"'
|
58
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
59
|
+
with(File.expand_path(source[1..-2]))
|
60
|
+
chat.fetch_source(source)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'can handle files with spaces and " in " quotes' do
|
64
|
+
source = '"./spec/assets/file with \" and spaces.html"'
|
65
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
66
|
+
with(File.expand_path('./spec/assets/file with " and spaces.html'))
|
67
|
+
chat.fetch_source(source)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'handles relative paths correctly' do
|
71
|
+
source = '../spec/assets/example.html'
|
72
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
73
|
+
with(File.expand_path(source))
|
74
|
+
chat.fetch_source(source)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'handles tilde expansion in filename' do
|
78
|
+
source = '~/test.txt'
|
79
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
80
|
+
with(File.expand_path(source))
|
81
|
+
chat.fetch_source(source)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'handles absolute paths in filename' do
|
85
|
+
source = '/tmp/test.txt'
|
86
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
87
|
+
with(File.expand_path(source))
|
88
|
+
chat.fetch_source(source)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with file:// URI' do
|
93
|
+
it 'fetches content from file URI with encoded paths' do
|
94
|
+
source = 'file:///path/with%20spaces/file.txt'
|
95
|
+
expect(chat).to receive(:fetch_source_as_filename).
|
96
|
+
with('/path/with spaces/file.txt')
|
97
|
+
chat.fetch_source(source)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
39
101
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
begin
|
2
|
+
require 'gem_hadar/simplecov'
|
3
|
+
GemHadar::SimpleCov.start
|
4
|
+
rescue LoadError
|
5
|
+
end
|
3
6
|
require 'rspec'
|
4
7
|
require 'tins/xt/expose'
|
5
8
|
begin
|
@@ -143,6 +146,9 @@ RSpec.configure do |config|
|
|
143
146
|
config.extend StubOllamaServer
|
144
147
|
|
145
148
|
config.around(&ProtectEnvVars.apply)
|
149
|
+
config.before(:each) do
|
150
|
+
ENV['OLLAMA_HOST'] = 'localhost:11434'
|
151
|
+
end
|
146
152
|
|
147
153
|
config.before(:suite) do
|
148
154
|
infobar.show = nil
|
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.
|
4
|
+
version: 0.0.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '2.
|
18
|
+
version: '2.6'
|
19
19
|
type: :development
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: '2.
|
25
|
+
version: '2.6'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: all_images
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -466,6 +466,7 @@ files:
|
|
466
466
|
- spec/assets/example.rb
|
467
467
|
- spec/assets/example.rss
|
468
468
|
- spec/assets/example.xml
|
469
|
+
- spec/assets/example_with_quote.html
|
469
470
|
- spec/assets/kitten.jpg
|
470
471
|
- spec/assets/prompt.txt
|
471
472
|
- spec/assets/searxng.json
|