ollama_chat 0.0.25 → 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 +6 -0
- data/.contexts/lib.rb +2 -0
- data/.contexts/yard.md +94 -0
- data/.gitignore +1 -0
- data/CHANGES.md +15 -0
- data/README.md +2 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/ollama_chat/chat.rb +19 -6
- 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 +12 -0
- 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.rb +19 -0
- data/lib/ollama_chat/parsing.rb +13 -0
- data/lib/ollama_chat/server_socket.rb +27 -0
- data/lib/ollama_chat/source_fetching.rb +25 -0
- data/lib/ollama_chat/switches.rb +49 -0
- data/lib/ollama_chat/utils/cache_fetcher.rb +15 -0
- data/lib/ollama_chat/utils/fetcher.rb +41 -1
- 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 +4 -4
- data/spec/ollama_chat/chat_spec.rb +11 -1
- data/spec/ollama_chat/kramdown_ansi_spec.rb +5 -5
- data/spec/ollama_chat/message_list_spec.rb +47 -12
- data/spec/spec_helper.rb +120 -26
- metadata +5 -3
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
|
@@ -414,9 +414,11 @@ extra_rdoc_files:
|
|
414
414
|
- lib/ollama_chat/web_searching.rb
|
415
415
|
files:
|
416
416
|
- ".all_images.yml"
|
417
|
+
- ".contexts/code_comment.rb"
|
417
418
|
- ".contexts/full.rb"
|
418
419
|
- ".contexts/info.rb"
|
419
420
|
- ".contexts/lib.rb"
|
421
|
+
- ".contexts/yard.md"
|
420
422
|
- ".envrc"
|
421
423
|
- ".gitignore"
|
422
424
|
- CHANGES.md
|