ollama_chat 0.0.24 → 0.0.26
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/.contexts/code_comment.rb +25 -0
- data/.contexts/full.rb +31 -0
- data/.contexts/info.rb +17 -0
- data/.contexts/lib.rb +25 -0
- data/.contexts/yard.md +94 -0
- data/.gitignore +1 -0
- data/CHANGES.md +39 -0
- data/README.md +10 -1
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/bin/ollama_chat_send +9 -2
- data/lib/ollama_chat/chat.rb +42 -18
- data/lib/ollama_chat/clipboard.rb +12 -0
- data/lib/ollama_chat/dialog.rb +17 -0
- data/lib/ollama_chat/document_cache.rb +28 -10
- data/lib/ollama_chat/follow_chat.rb +26 -7
- data/lib/ollama_chat/history.rb +55 -7
- data/lib/ollama_chat/information.rb +32 -1
- data/lib/ollama_chat/kramdown_ansi.rb +15 -1
- data/lib/ollama_chat/message_format.rb +16 -0
- data/lib/ollama_chat/message_list.rb +52 -5
- data/lib/ollama_chat/message_output.rb +12 -0
- data/lib/ollama_chat/model_handling.rb +17 -0
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +4 -2
- data/lib/ollama_chat/ollama_chat_config.rb +19 -0
- data/lib/ollama_chat/parsing.rb +13 -0
- data/lib/ollama_chat/server_socket.rb +34 -3
- data/lib/ollama_chat/source_fetching.rb +25 -2
- data/lib/ollama_chat/switches.rb +49 -0
- data/lib/ollama_chat/utils/cache_fetcher.rb +15 -0
- data/lib/ollama_chat/utils/chooser.rb +16 -0
- data/lib/ollama_chat/utils/fetcher.rb +41 -1
- data/lib/ollama_chat/utils/file_argument.rb +19 -0
- data/lib/ollama_chat/utils.rb +8 -0
- data/lib/ollama_chat/version.rb +1 -1
- data/lib/ollama_chat/vim.rb +6 -0
- data/lib/ollama_chat/web_searching.rb +11 -0
- data/lib/ollama_chat.rb +9 -0
- data/ollama_chat.gemspec +8 -7
- data/spec/ollama_chat/chat_spec.rb +11 -1
- data/spec/ollama_chat/kramdown_ansi_spec.rb +45 -0
- data/spec/ollama_chat/message_list_spec.rb +70 -9
- data/spec/ollama_chat/server_socket_spec.rb +68 -47
- data/spec/spec_helper.rb +120 -26
- metadata +28 -7
data/spec/spec_helper.rb
CHANGED
@@ -12,44 +12,138 @@ require 'ollama_chat'
|
|
12
12
|
|
13
13
|
ComplexConfig::Provider.deep_freeze = false
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# A module that provides helper methods for asset management within the
|
16
|
+
# application.
|
17
|
+
#
|
18
|
+
# The AssetHelpers module encapsulates functionality related to handling and
|
19
|
+
# processing application assets, such as CSS, JavaScript, and image files. It
|
20
|
+
# offers utilities for managing asset paths, generating URLs, and performing
|
21
|
+
# operations on assets during the application's runtime.
|
22
|
+
module AssetHelpers
|
23
|
+
# The asset method constructs and returns the full path to an asset file.
|
24
|
+
#
|
25
|
+
# This method takes a filename argument and combines it with the assets directory
|
26
|
+
# located within the same directory as the calling file, returning the
|
27
|
+
# complete path to that asset.
|
28
|
+
#
|
29
|
+
# @param name [String] the name of the asset file
|
30
|
+
#
|
31
|
+
# @return [String] the full path to the asset file
|
32
|
+
def asset(name)
|
33
|
+
File.join(__dir__, 'assets', name)
|
34
|
+
end
|
18
35
|
|
19
|
-
|
20
|
-
|
21
|
-
|
36
|
+
# Reads and returns the content of an asset file from the assets directory.
|
37
|
+
#
|
38
|
+
# @param name [String] the name of the asset file to read
|
39
|
+
#
|
40
|
+
# @return [String] the content of the asset file as a string
|
41
|
+
def asset_content(name)
|
42
|
+
File.read(File.join(__dir__, 'assets', name))
|
43
|
+
end
|
22
44
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
45
|
+
# The asset_io method retrieves an IO object for a specified asset file.
|
46
|
+
#
|
47
|
+
# This method constructs the path to an asset file within the assets directory
|
48
|
+
# and returns an IO object representing that file. If a block is provided, it
|
49
|
+
# yields the IO object to the block and ensures the file is properly closed
|
50
|
+
# after the block executes.
|
51
|
+
#
|
52
|
+
# @param name [ String ] the name of the asset file to retrieve
|
53
|
+
#
|
54
|
+
# @yield [ io ] yields the IO object for the asset file to the provided block
|
55
|
+
#
|
56
|
+
# @return [ File, nil ] returns the IO object for the asset file, or nil if a
|
57
|
+
# block is provided and the block does not return a value
|
58
|
+
def asset_io(name, &block)
|
59
|
+
io = File.new(File.join(__dir__, 'assets', name))
|
60
|
+
if block
|
61
|
+
begin
|
62
|
+
block.call(io)
|
63
|
+
ensure
|
64
|
+
io.close
|
65
|
+
end
|
66
|
+
else
|
67
|
+
io
|
30
68
|
end
|
31
|
-
|
32
|
-
|
69
|
+
end
|
70
|
+
|
71
|
+
# The asset_json method reads and parses a JSON asset file.
|
72
|
+
#
|
73
|
+
# This method retrieves an asset by name, reads its contents from the
|
74
|
+
# filesystem, and then parses the resulting string as JSON, returning the
|
75
|
+
# parsed data structure.
|
76
|
+
#
|
77
|
+
# @param name [String] the name of the asset to retrieve and parse
|
78
|
+
#
|
79
|
+
# @return [Object] the parsed JSON data structure, typically a Hash or Array
|
80
|
+
def asset_json(name)
|
81
|
+
JSON(JSON(File.read(asset(name))))
|
33
82
|
end
|
34
83
|
end
|
35
84
|
|
36
|
-
|
37
|
-
|
85
|
+
# A module that provides functionality for stubbing Ollama server responses.
|
86
|
+
#
|
87
|
+
# The StubOllamaServer module enables developers to simulate Ollama API
|
88
|
+
# interactions in test environments by intercepting requests and returning
|
89
|
+
# predefined responses. This allows for faster, more reliable testing without
|
90
|
+
# requiring external service calls.
|
91
|
+
module StubOllamaServer
|
92
|
+
# The connect_to_ollama_server method establishes a connection to an Ollama
|
93
|
+
# server.
|
94
|
+
#
|
95
|
+
# This method sets up stubbed HTTP requests to simulate responses from an
|
96
|
+
# Ollama server, including API tags, show, and version endpoints. It can
|
97
|
+
# optionally instantiate a chat session after setting up the stubs.
|
98
|
+
#
|
99
|
+
# @param instantiate [Boolean] whether to instantiate a chat session after setting up stubs
|
100
|
+
def connect_to_ollama_server(instantiate: true)
|
101
|
+
before do
|
102
|
+
stub_request(:get, %r(/api/tags\z)).
|
103
|
+
to_return(status: 200, body: asset_json('api_tags.json'))
|
104
|
+
stub_request(:post, %r(/api/show\z)).
|
105
|
+
to_return(status: 200, body: asset_json('api_show.json'))
|
106
|
+
stub_request(:get, %r(/api/version\z)).
|
107
|
+
to_return(status: 200, body: asset_json('api_version.json'))
|
108
|
+
instantiate and chat
|
109
|
+
end
|
110
|
+
end
|
38
111
|
end
|
39
112
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
113
|
+
# A module that provides functionality for protecting environment variables during tests.
|
114
|
+
#
|
115
|
+
# This module ensures that environment variable changes made during test execution
|
116
|
+
# are automatically restored to their original values after the test completes.
|
117
|
+
# It is designed to prevent side effects between tests that modify environment
|
118
|
+
# variables, maintaining a clean testing environment.
|
119
|
+
module ProtectEnvVars
|
120
|
+
# The apply method creates a lambda that protects environment variables
|
121
|
+
# during test execution.
|
122
|
+
#
|
123
|
+
# @return [Proc] a lambda that wraps test execution with environment variable
|
124
|
+
# preservation
|
125
|
+
def self.apply
|
126
|
+
-> example do
|
127
|
+
if example.metadata[:protect_env]
|
128
|
+
begin
|
129
|
+
stored_env = ENV.to_h
|
130
|
+
example.run
|
131
|
+
ensure
|
132
|
+
ENV.replace(stored_env)
|
133
|
+
end
|
134
|
+
else
|
135
|
+
example.run
|
136
|
+
end
|
137
|
+
end
|
49
138
|
end
|
50
139
|
end
|
51
140
|
|
52
141
|
RSpec.configure do |config|
|
142
|
+
config.include AssetHelpers
|
143
|
+
config.extend StubOllamaServer
|
144
|
+
|
145
|
+
config.around(&ProtectEnvVars.apply)
|
146
|
+
|
53
147
|
config.before(:suite) do
|
54
148
|
infobar.show = nil
|
55
149
|
end
|
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.26
|
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.1'
|
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.1'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: all_images
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +107,20 @@ dependencies:
|
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: context_spook
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
110
124
|
- !ruby/object:Gem::Dependency
|
111
125
|
name: excon
|
112
126
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,14 +141,14 @@ dependencies:
|
|
127
141
|
requirements:
|
128
142
|
- - "~>"
|
129
143
|
- !ruby/object:Gem::Version
|
130
|
-
version: '1.
|
144
|
+
version: '1.6'
|
131
145
|
type: :runtime
|
132
146
|
prerelease: false
|
133
147
|
version_requirements: !ruby/object:Gem::Requirement
|
134
148
|
requirements:
|
135
149
|
- - "~>"
|
136
150
|
- !ruby/object:Gem::Version
|
137
|
-
version: '1.
|
151
|
+
version: '1.6'
|
138
152
|
- !ruby/object:Gem::Dependency
|
139
153
|
name: documentrix
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,14 +307,14 @@ dependencies:
|
|
293
307
|
requirements:
|
294
308
|
- - "~>"
|
295
309
|
- !ruby/object:Gem::Version
|
296
|
-
version: '1.
|
310
|
+
version: '1.41'
|
297
311
|
type: :runtime
|
298
312
|
prerelease: false
|
299
313
|
version_requirements: !ruby/object:Gem::Requirement
|
300
314
|
requirements:
|
301
315
|
- - "~>"
|
302
316
|
- !ruby/object:Gem::Version
|
303
|
-
version: '1.
|
317
|
+
version: '1.41'
|
304
318
|
- !ruby/object:Gem::Dependency
|
305
319
|
name: search_ui
|
306
320
|
requirement: !ruby/object:Gem::Requirement
|
@@ -400,6 +414,11 @@ extra_rdoc_files:
|
|
400
414
|
- lib/ollama_chat/web_searching.rb
|
401
415
|
files:
|
402
416
|
- ".all_images.yml"
|
417
|
+
- ".contexts/code_comment.rb"
|
418
|
+
- ".contexts/full.rb"
|
419
|
+
- ".contexts/info.rb"
|
420
|
+
- ".contexts/lib.rb"
|
421
|
+
- ".contexts/yard.md"
|
403
422
|
- ".envrc"
|
404
423
|
- ".gitignore"
|
405
424
|
- CHANGES.md
|
@@ -460,6 +479,7 @@ files:
|
|
460
479
|
- spec/ollama_chat/clipboard_spec.rb
|
461
480
|
- spec/ollama_chat/follow_chat_spec.rb
|
462
481
|
- spec/ollama_chat/information_spec.rb
|
482
|
+
- spec/ollama_chat/kramdown_ansi_spec.rb
|
463
483
|
- spec/ollama_chat/message_list_spec.rb
|
464
484
|
- spec/ollama_chat/message_output_spec.rb
|
465
485
|
- spec/ollama_chat/model_handling_spec.rb
|
@@ -504,6 +524,7 @@ test_files:
|
|
504
524
|
- spec/ollama_chat/clipboard_spec.rb
|
505
525
|
- spec/ollama_chat/follow_chat_spec.rb
|
506
526
|
- spec/ollama_chat/information_spec.rb
|
527
|
+
- spec/ollama_chat/kramdown_ansi_spec.rb
|
507
528
|
- spec/ollama_chat/message_list_spec.rb
|
508
529
|
- spec/ollama_chat/message_output_spec.rb
|
509
530
|
- spec/ollama_chat/model_handling_spec.rb
|