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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12c83374034666d30f5b8fdbe2e6b4f4b652ff9b418affee5117bc0d6e67fcc
|
4
|
+
data.tar.gz: f1ce7fca104f94ee159b1d6add90fcff3792d9e2a741d7d1f6f3cf3741646fd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b6ec1e765aa5bf46200b5f308eea5b690674ebc296afcf240689385cabc91009da8145ee04b568296a7cff65d57c03e5c0c49fd38393a90abc9e659d6d4e9b2
|
7
|
+
data.tar.gz: c9a3db643d6efad021153f9c6cfad22f57696607354e21ca6a48dc5d3f454cf372327f31598542a1d70ad6e3fcdc4ca81b3a69c17e6c3b95dfc558a30aefc5d7
|
@@ -0,0 +1,25 @@
|
|
1
|
+
context do
|
2
|
+
namespace "lib" do
|
3
|
+
Dir['lib/**/*.rb'].each do |filename|
|
4
|
+
file filename, tags: 'lib'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace "spec" do
|
9
|
+
Dir['spec/**/*.rb'].each do |filename|
|
10
|
+
file filename, tags: 'spec'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
file 'README.md', tags: 'documentation'
|
15
|
+
|
16
|
+
file '.contexts/yard.md', tags: [ 'yard', 'cheatsheet' ]
|
17
|
+
|
18
|
+
meta guidelins: <<~EOT
|
19
|
+
# Guidelines for creating YARD documentation
|
20
|
+
|
21
|
+
- Look into the file, with tags yard and cheatsheet for how comment ruby
|
22
|
+
constructs.
|
23
|
+
- In comments above initialize methods never omit @return
|
24
|
+
EOT
|
25
|
+
end
|
data/.contexts/full.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
context do
|
2
|
+
variable project_name: Pathname.pwd.basename
|
3
|
+
|
4
|
+
variable project_version: File.read('VERSION').chomp
|
5
|
+
|
6
|
+
variable branch: `git rev-parse --abbrev-ref HEAD`.chomp
|
7
|
+
|
8
|
+
namespace "structure" do
|
9
|
+
command "tree lib", tags: %w[ project_structure ]
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace "lib" do
|
13
|
+
Dir['lib/**/*.rb'].each do |filename|
|
14
|
+
file filename, tags: 'lib'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace "spec" do
|
19
|
+
Dir['spec/**/*.rb'].each do |filename|
|
20
|
+
file filename, tags: 'spec'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
file 'Rakefile', tags: 'gem_hadar'
|
25
|
+
|
26
|
+
file 'README.md', tags: 'documentation'
|
27
|
+
|
28
|
+
meta ruby: RUBY_DESCRIPTION
|
29
|
+
|
30
|
+
meta code_coverage: json('coverage/coverage_context.json')
|
31
|
+
end
|
data/.contexts/info.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
context do
|
2
|
+
variable project_name: Pathname.pwd.basename
|
3
|
+
|
4
|
+
variable project_version: File.read('VERSION').chomp
|
5
|
+
|
6
|
+
variable branch: `git rev-parse --abbrev-ref HEAD`.chomp
|
7
|
+
|
8
|
+
namespace "structure" do
|
9
|
+
command "tree lib", tags: %w[ project_structure ]
|
10
|
+
end
|
11
|
+
|
12
|
+
file 'Rakefile', tags: 'gem_hadar'
|
13
|
+
|
14
|
+
file 'README.md', tags: 'documentation'
|
15
|
+
|
16
|
+
meta ruby: RUBY_DESCRIPTION
|
17
|
+
end
|
data/.contexts/lib.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
context do
|
2
|
+
variable project_name: Pathname.pwd.basename
|
3
|
+
|
4
|
+
variable project_version: File.read('VERSION').chomp
|
5
|
+
|
6
|
+
variable branch: `git rev-parse --abbrev-ref HEAD`.chomp
|
7
|
+
|
8
|
+
namespace "structure" do
|
9
|
+
command "tree lib", tags: %w[ project_structure ]
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace "lib" do
|
13
|
+
Dir['lib/**/*.rb'].each do |filename|
|
14
|
+
file filename, tags: 'lib'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
file 'Rakefile', tags: 'gem_hadar'
|
19
|
+
|
20
|
+
file 'README.md', tags: 'documentation'
|
21
|
+
|
22
|
+
meta ruby: RUBY_DESCRIPTION
|
23
|
+
|
24
|
+
meta code_coverage: json('coverage/coverage_context.json')
|
25
|
+
end
|
data/.contexts/yard.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
|
2
|
+
# YARD Documentation Example
|
3
|
+
|
4
|
+
**You**, as an AI assistant, are tasked with generating only YARD documentation
|
5
|
+
comments for Ruby code, not executable code itself.
|
6
|
+
|
7
|
+
## Your Documentation Responsibilities
|
8
|
+
|
9
|
+
When generating Ruby documentation, you must:
|
10
|
+
|
11
|
+
### 1. **Generate Only Documentation Comments**
|
12
|
+
- Provide `#` prefixed comment blocks only
|
13
|
+
- Do not generate actual method bodies or class implementations
|
14
|
+
- Do not include executable code like `def`, `class`, `attr_reader`, etc.
|
15
|
+
- Focus solely on the documentation portions
|
16
|
+
|
17
|
+
### 2. **Follow the Exact Structure from Example**
|
18
|
+
Here are the documentation comments from the Document class:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# Represents a generic document in a document management system.
|
22
|
+
# @example How to create a document
|
23
|
+
# document = Document.new('Hello World')
|
24
|
+
class Document
|
25
|
+
# @!attribute [r] title
|
26
|
+
# @return [String]
|
27
|
+
attr_reader :title
|
28
|
+
|
29
|
+
# @!attribute [w] description
|
30
|
+
# @return [String]
|
31
|
+
attr_writer :description
|
32
|
+
|
33
|
+
# @!attribute [rw] sections
|
34
|
+
# @api private
|
35
|
+
# @return [Array<Section>]
|
36
|
+
attr_accessor :sections
|
37
|
+
|
38
|
+
# Initializes a new Document instance.
|
39
|
+
# @note This method should be called with care.
|
40
|
+
#
|
41
|
+
# @param title [String] the title of the document
|
42
|
+
# @param description [String] the description of the document
|
43
|
+
# @param options [Hash] additional configuration options
|
44
|
+
# @option options [Boolean] :editable whether the document can be edited
|
45
|
+
# @yieldparam [String] content The content of the document.
|
46
|
+
# @yieldreturn [String] Returns a modified content.
|
47
|
+
#
|
48
|
+
# @raise [ArgumentError] if the title is nil
|
49
|
+
#
|
50
|
+
# @return [Document] a new Document instance
|
51
|
+
def initialize(title, description, options = {})
|
52
|
+
# Do NOT generate executable code
|
53
|
+
end
|
54
|
+
|
55
|
+
# Edits the document content.
|
56
|
+
#
|
57
|
+
# @overload edit(new_content)
|
58
|
+
# @param new_content [String] the new content for the document
|
59
|
+
# @return [Boolean] true if editing was successful, false otherwise
|
60
|
+
#
|
61
|
+
# @overload edit
|
62
|
+
# @yield Gives a block to process the current content.
|
63
|
+
# @yieldreturn [String] Returns the new content after processing.
|
64
|
+
# @return [Boolean] true if editing was successful, false otherwise
|
65
|
+
#
|
66
|
+
# @deprecated Use `modify` method instead.
|
67
|
+
def edit(new_content = nil)
|
68
|
+
# Do NOT generate executable code
|
69
|
+
end
|
70
|
+
|
71
|
+
# @todo Implement a proper save mechanism
|
72
|
+
def save
|
73
|
+
# Do NOT generate executable code
|
74
|
+
end
|
75
|
+
|
76
|
+
# Views the document
|
77
|
+
#
|
78
|
+
# @example Viewing the document title
|
79
|
+
# document.view_title #=> "Sample Document"
|
80
|
+
#
|
81
|
+
# @see #edit
|
82
|
+
# @return [String] the title of the document
|
83
|
+
def view_title
|
84
|
+
# Do NOT generate executable code
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
## Key Rule
|
90
|
+
|
91
|
+
**DO NOT GENERATE ANY EXECUTABLE CODE** - only documentation comments that
|
92
|
+
would be placed above actual Ruby methods and classes. The example shows what
|
93
|
+
the documentation comments should look like, not the actual executable Ruby
|
94
|
+
code.
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,44 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2025-08-27 v0.0.26
|
4
|
+
|
5
|
+
- Enhanced `/last` command to support numeric argument, allowing users to
|
6
|
+
specify the number of messages to display
|
7
|
+
- Configured tests to protect environment variables by using `protect_env:
|
8
|
+
true` option and direct `ENV` manipulation
|
9
|
+
- Refactored spec helper with modularized `AssetHelpers`, `StubOllamaServer`,
|
10
|
+
and `ProtectEnvVars` modules for better organization
|
11
|
+
- Improved code clarity and added comprehensive documentation across multiple
|
12
|
+
modules including `OllamaChat`, `Chat`, `MessageList`, and others
|
13
|
+
- Added detailed class-level documentation for `OllamaChatConfig` with examples
|
14
|
+
- Included documentation for the `Parsing`, `Vim`, `MessageFormat`,
|
15
|
+
`KramdownANSI`, `Information`, `UserAgent`, and `History` modules
|
16
|
+
- Improved cache hit message formatting and wording for better user experience
|
17
|
+
|
18
|
+
## 2025-08-18 v0.0.25
|
19
|
+
|
20
|
+
- Integrated `context_spook` gem as development dependency
|
21
|
+
- Added new context files: `.contexts/full.rb`, `.contexts/info.rb`, and
|
22
|
+
`.contexts/lib.rb`
|
23
|
+
- Updated `ollama-ruby` dependency version constraint from `~> 1.2` to `~> 1.6`
|
24
|
+
- Bumped **tins** dependency from ~> **1.34** to ~> **1.41**
|
25
|
+
- Refactored `web` method in `chat.rb` to conditionally handle embeddings
|
26
|
+
- Split web prompt templates into `web_embed` and `web_import`
|
27
|
+
- Moved cache check message to display before cache retrieval
|
28
|
+
- Fixed `show_last` behavior for empty lists with comprehensive tests
|
29
|
+
- Added nil check to `kramdown_ansi_parse` method to prevent `NoMethodError`
|
30
|
+
- Added documentation comments to `OllamaChat::Clipboard`,
|
31
|
+
`OllamaChat::Dialog`, `OllamaChat::Utils::Chooser`, and
|
32
|
+
`OllamaChat::Utils::FileArgument` modules
|
33
|
+
- Added new command line option `-d DIR` to specify runtime directory for
|
34
|
+
socket file
|
35
|
+
- Updated `OllamaChat::ServerSocket.send_to_server_socket` method to accept
|
36
|
+
`runtime_dir` parameter
|
37
|
+
- Modified `create_socket_server` method to use provided `runtime_dir` when
|
38
|
+
creating Unix socket server
|
39
|
+
- Updated help text to document the new `-d` option
|
40
|
+
- Added separate context for `runtime_dir` parameter testing in spec
|
41
|
+
|
3
42
|
## 2025-08-17 v0.0.24
|
4
43
|
|
5
44
|
- Updated `kramdown-ansi` dependency version constraint from **0.0** to **0.1**
|
data/README.md
CHANGED
@@ -153,7 +153,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
|
|
153
153
|
/stream toggle stream output
|
154
154
|
/location toggle location submission
|
155
155
|
/voice [change] toggle voice output or change the voice
|
156
|
-
/last
|
156
|
+
/last [n] show the last n / 1 system/assistant message
|
157
157
|
/list [n] list the last n / all conversation exchanges
|
158
158
|
/clear [what] clear what=messages|links|history|tags|all
|
159
159
|
/clobber clear the conversation, links, and collection
|
@@ -177,6 +177,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
|
|
177
177
|
/load filename load conversation messages
|
178
178
|
/output filename save last response to filename
|
179
179
|
/pipe command write last response to command's stdin
|
180
|
+
/vim insert the last message into a vim server
|
180
181
|
/quit to quit
|
181
182
|
/help to view this help
|
182
183
|
```
|
@@ -227,6 +228,14 @@ The `ollama_chat_send` command now supports additional parameters to enhance fun
|
|
227
228
|
$ echo "Visit https://example.com for more info" | ollama_chat_send -p
|
228
229
|
```
|
229
230
|
|
231
|
+
- **Runtime Directory (`-d`)**: Specifies the directory where the Unix socket
|
232
|
+
file of `ollama_chat` was created, if you want to send to a specific
|
233
|
+
`ollama_chat`.
|
234
|
+
|
235
|
+
```bash
|
236
|
+
$ echo "Hello world" | ollama_chat_send -d /tmp/my_runtime_dir -r
|
237
|
+
```
|
238
|
+
|
230
239
|
- **Help (`-h` or `--help`)**: Displays usage information and available options.
|
231
240
|
|
232
241
|
```bash
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ GemHadar do
|
|
21
21
|
|
22
22
|
test_dir 'spec'
|
23
23
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.AppleDouble', '.bundle',
|
24
|
-
'.yardoc', 'tags', 'corpus', 'coverage', '/config/searxng/*'
|
24
|
+
'.yardoc', 'doc', 'tags', 'corpus', 'coverage', '/config/searxng/*'
|
25
25
|
|
26
26
|
readme 'README.md'
|
27
27
|
|
@@ -30,7 +30,7 @@ GemHadar do
|
|
30
30
|
executables << 'ollama_chat' << 'ollama_chat_send'
|
31
31
|
|
32
32
|
dependency 'excon', '~> 1.0'
|
33
|
-
dependency 'ollama-ruby', '~> 1.
|
33
|
+
dependency 'ollama-ruby', '~> 1.6'
|
34
34
|
dependency 'documentrix', '~> 0.0', '>= 0.0.2'
|
35
35
|
dependency 'unix_socks', '>= 0.0.1'
|
36
36
|
dependency 'rss', '~> 0.3'
|
@@ -41,7 +41,7 @@ GemHadar do
|
|
41
41
|
dependency 'xdg'
|
42
42
|
dependency 'kramdown-ansi', '~> 0.1'
|
43
43
|
dependency 'complex_config', '~> 0.22', '>= 0.22.2'
|
44
|
-
dependency 'tins', '~> 1.
|
44
|
+
dependency 'tins', '~> 1.41'
|
45
45
|
dependency 'search_ui', '~> 0.0'
|
46
46
|
dependency 'amatch', '~> 0.4.1'
|
47
47
|
dependency 'pdf-reader', '~> 2.0'
|
@@ -52,6 +52,7 @@ GemHadar do
|
|
52
52
|
development_dependency 'webmock'
|
53
53
|
development_dependency 'debug'
|
54
54
|
development_dependency 'simplecov'
|
55
|
+
development_dependency 'context_spook'
|
55
56
|
|
56
57
|
licenses << 'MIT'
|
57
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.26
|
data/bin/ollama_chat_send
CHANGED
@@ -5,7 +5,7 @@ require 'tins/go'
|
|
5
5
|
include Tins::GO
|
6
6
|
|
7
7
|
|
8
|
-
opts = go 'f:rtph', ARGV
|
8
|
+
opts = go 'f:d:rtph', ARGV
|
9
9
|
|
10
10
|
def usage(rc = 0)
|
11
11
|
puts <<~EOT
|
@@ -16,6 +16,7 @@ def usage(rc = 0)
|
|
16
16
|
-t Send input as terminal input including commands, e. g. /import
|
17
17
|
-p Send input with source parsing enabled (defaults to disabled)
|
18
18
|
-f CONFIG file to read
|
19
|
+
-d DIR the runtime directory to look for the socket file
|
19
20
|
-h Show this help message
|
20
21
|
|
21
22
|
Send data to a running Ollame Chat client via standard input.
|
@@ -31,7 +32,13 @@ begin
|
|
31
32
|
else
|
32
33
|
opts[?r] ? :socket_input_with_response : :socket_input
|
33
34
|
end
|
34
|
-
response = OllamaChat::ServerSocket.send_to_server_socket(
|
35
|
+
response = OllamaChat::ServerSocket.send_to_server_socket(
|
36
|
+
STDIN.read,
|
37
|
+
type:,
|
38
|
+
config:,
|
39
|
+
runtime_dir: opts[?d],
|
40
|
+
parse: !!opts[?p]
|
41
|
+
)
|
35
42
|
type == :socket_input_with_response and puts response.content
|
36
43
|
rescue => e
|
37
44
|
warn "Caught #{e.class}: #{e}"
|
data/lib/ollama_chat/chat.rb
CHANGED
@@ -17,6 +17,20 @@ require 'xdg'
|
|
17
17
|
require 'socket'
|
18
18
|
require 'shellwords'
|
19
19
|
|
20
|
+
# A chat client for interacting with Ollama models through a terminal
|
21
|
+
# interface.
|
22
|
+
#
|
23
|
+
# The Chat class provides a complete command-line interface for chatting with
|
24
|
+
# language models via the Ollama API. It handles configuration management,
|
25
|
+
# message history, document processing, web searching, and various interactive
|
26
|
+
# features including voice output, markdown rendering, and embedding
|
27
|
+
# capabilities.
|
28
|
+
#
|
29
|
+
# @example Initializing a chat session
|
30
|
+
# chat = OllamaChat::Chat.new(argv: ['-m', 'llama3.1'])
|
31
|
+
#
|
32
|
+
# @example Starting an interactive chat
|
33
|
+
# chat.start
|
20
34
|
class OllamaChat::Chat
|
21
35
|
include Tins::GO
|
22
36
|
include Term::ANSIColor
|
@@ -114,7 +128,6 @@ class OllamaChat::Chat
|
|
114
128
|
# @return [Ollama::Client] the configured Ollama API client
|
115
129
|
attr_reader :ollama
|
116
130
|
|
117
|
-
|
118
131
|
# Returns the documents set for this object, initializing it lazily if needed.
|
119
132
|
#
|
120
133
|
# The documents set is memoized, meaning it will only be created once per
|
@@ -205,11 +218,12 @@ class OllamaChat::Chat
|
|
205
218
|
end
|
206
219
|
:next
|
207
220
|
when %r(^/list(?:\s+(\d*))?$)
|
208
|
-
|
209
|
-
messages.list_conversation(
|
221
|
+
n = 2 * $1.to_i if $1
|
222
|
+
messages.list_conversation(n)
|
210
223
|
:next
|
211
|
-
when %r(^/last
|
212
|
-
|
224
|
+
when %r(^/last(?:\s+(\d*))?$)
|
225
|
+
n = $1.to_i if $1
|
226
|
+
messages.show_last(n)
|
213
227
|
:next
|
214
228
|
when %r(^/clear(?:\s+(messages|links|history|tags|all))?$)
|
215
229
|
clean($1)
|
@@ -348,23 +362,34 @@ class OllamaChat::Chat
|
|
348
362
|
end
|
349
363
|
end
|
350
364
|
|
351
|
-
# The web method
|
352
|
-
#
|
353
|
-
#
|
365
|
+
# The web method performs a web search and processes the results based on
|
366
|
+
# embedding configuration.
|
367
|
+
#
|
368
|
+
# It searches for the given query using the configured search engine and
|
369
|
+
# processes up to the specified number of URLs. If embeddings are enabled, it
|
370
|
+
# embeds each result and interpolates the query into the web_embed prompt.
|
371
|
+
# Otherwise, it imports each result and interpolates both the query and
|
372
|
+
# results into the web_import prompt.
|
354
373
|
#
|
355
|
-
# @param count [ String ] the number of
|
374
|
+
# @param count [ String ] the maximum number of search results to process
|
356
375
|
# @param query [ String ] the search query string
|
357
376
|
#
|
358
|
-
# @return [ String ] the
|
377
|
+
# @return [ String, Symbol ] the interpolated prompt content or :next if no URLs were found
|
359
378
|
def web(count, query)
|
360
|
-
urls
|
361
|
-
|
362
|
-
|
379
|
+
urls = search_web(query, count.to_i) or return :next
|
380
|
+
if @embedding.on?
|
381
|
+
prompt = config.prompts.web_embed
|
382
|
+
urls.each do |url|
|
383
|
+
fetch_source(url) { |url_io| embed_source(url_io, url) }
|
384
|
+
end
|
385
|
+
prompt.named_placeholders_interpolate({query:})
|
386
|
+
else
|
387
|
+
prompt = config.prompts.web_import
|
388
|
+
results = urls.each_with_object('') do |url, content|
|
389
|
+
import(url).full? { |c| content << c }
|
390
|
+
end
|
391
|
+
prompt.named_placeholders_interpolate({query:, results:})
|
363
392
|
end
|
364
|
-
urls_summarized = urls.map { summarize(_1) }
|
365
|
-
results = urls.zip(urls_summarized).
|
366
|
-
map { |u, s| "%s as \n:%s" % [ u, s ] } * "\n\n"
|
367
|
-
config.prompts.web % { query:, results: }
|
368
393
|
end
|
369
394
|
|
370
395
|
# The manage_links method handles operations on a collection of links, such
|
@@ -650,7 +675,6 @@ class OllamaChat::Chat
|
|
650
675
|
#
|
651
676
|
# @see fetch_source
|
652
677
|
# @see embed_source
|
653
|
-
# @see documents.clear
|
654
678
|
def add_documents_from_argv(document_list)
|
655
679
|
if document_list.any?(&:empty?)
|
656
680
|
STDOUT.puts "Clearing collection #{bold{documents.collection}}."
|
@@ -1,3 +1,15 @@
|
|
1
|
+
# A module that provides clipboard functionality for copying and pasting chat
|
2
|
+
# messages.
|
3
|
+
#
|
4
|
+
# This module enables users to copy the last assistant message to the system
|
5
|
+
# clipboard and paste content from input, facilitating easy transfer of
|
6
|
+
# conversation content between different applications and contexts.
|
7
|
+
#
|
8
|
+
# @example Copying a message to clipboard
|
9
|
+
# chat.copy_to_clipboard
|
10
|
+
#
|
11
|
+
# @example Pasting content from input
|
12
|
+
# content = chat.paste_from_input
|
1
13
|
module OllamaChat::Clipboard
|
2
14
|
# Copy the last assistant's message to the system clipboard.
|
3
15
|
#
|
data/lib/ollama_chat/dialog.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# A module that provides interactive selection and configuration functionality
|
2
|
+
# for OllamaChat.
|
3
|
+
#
|
4
|
+
# The Dialog module encapsulates various helper methods for choosing models,
|
5
|
+
# system prompts, document policies, and voices, as well as displaying
|
6
|
+
# information and managing chat sessions. It leverages user interaction
|
7
|
+
# components like choosers and prompts to enable dynamic configuration during
|
8
|
+
# runtime.
|
9
|
+
#
|
10
|
+
# @example Selecting a model from available options
|
11
|
+
# chat.choose_model('-m llama3.1', 'llama3.1')
|
12
|
+
#
|
13
|
+
# @example Changing the system prompt
|
14
|
+
# chat.change_system_prompt('default_prompt', system: '?sherlock')
|
15
|
+
#
|
16
|
+
# @example Choosing a document policy
|
17
|
+
# chat.choose_document_policy
|
1
18
|
module OllamaChat::Dialog
|
2
19
|
# The model_with_size method formats a model's size for display
|
3
20
|
# by creating a formatted string that includes the model name and its size
|
@@ -1,20 +1,38 @@
|
|
1
|
+
# Module for handling document caching and retrieval using embedding
|
2
|
+
# similarity.
|
3
|
+
#
|
4
|
+
# This module provides methods to configure cache backends and manage document
|
5
|
+
# storage with semantic search capabilities. It integrates with Documentrix's
|
6
|
+
# document management system to enable efficient storage, retrieval, and
|
7
|
+
# similarity-based searching of documents using vector embeddings.
|
1
8
|
module OllamaChat::DocumentCache
|
2
|
-
#
|
3
|
-
# configuration.
|
9
|
+
# Retrieves the cache class specified in the configuration.
|
4
10
|
#
|
5
|
-
#
|
11
|
+
# This method resolves the cache class name from the application's
|
12
|
+
# configuration to dynamically load the appropriate cache implementation.
|
13
|
+
#
|
14
|
+
# @return [Class] The cache class referenced by the configuration's cache
|
15
|
+
# setting.
|
16
|
+
# @raise [NameError] If the configured cache class name does not correspond
|
17
|
+
# to an existing constant.
|
6
18
|
def document_cache_class
|
7
19
|
Object.const_get(config.cache)
|
8
20
|
end
|
9
21
|
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# If
|
15
|
-
# and
|
22
|
+
# Configures and returns the appropriate cache class based on command-line
|
23
|
+
# options.
|
24
|
+
#
|
25
|
+
# Determines which cache implementation to use based on command-line flags: -
|
26
|
+
# If the `-M` flag is set, uses {Documentrix::Documents::MemoryCache} -
|
27
|
+
# Otherwise, resolves and returns the cache class specified in configuration
|
28
|
+
#
|
29
|
+
# Falls back to {Documentrix::Documents::MemoryCache} if configuration
|
30
|
+
# resolution fails.
|
16
31
|
#
|
17
|
-
# @return [
|
32
|
+
# @return [Class] The selected cache class for document storage and
|
33
|
+
# retrieval.
|
34
|
+
# @raise [StandardError] If there is an error resolving the configured cache
|
35
|
+
# class, logs the error to standard error and falls back to MemoryCache.
|
18
36
|
def configure_cache
|
19
37
|
if @opts[?M]
|
20
38
|
Documentrix::Documents::MemoryCache
|
@@ -1,3 +1,15 @@
|
|
1
|
+
# A class that handles chat responses and manages the flow of conversation
|
2
|
+
# between the user and Ollama models.
|
3
|
+
#
|
4
|
+
# This class is responsible for processing Ollama API responses, updating
|
5
|
+
# message history, displaying formatted output to the terminal, and managing
|
6
|
+
# voice synthesis for spoken responses. It acts as a handler for streaming
|
7
|
+
# responses and ensures proper formatting and display of both regular content
|
8
|
+
# and thinking annotations.
|
9
|
+
#
|
10
|
+
# @example Processing a chat response
|
11
|
+
# follow_chat = OllamaChat::FollowChat.new(chat: chat_instance, messages: message_list)
|
12
|
+
# follow_chat.call(response)
|
1
13
|
class OllamaChat::FollowChat
|
2
14
|
include Ollama
|
3
15
|
include Ollama::Handlers::Concern
|
@@ -6,10 +18,13 @@ class OllamaChat::FollowChat
|
|
6
18
|
|
7
19
|
# Initializes a new instance of OllamaChat::FollowChat.
|
8
20
|
#
|
9
|
-
# @param [OllamaChat::Chat] chat The chat object, which represents the
|
10
|
-
#
|
21
|
+
# @param [OllamaChat::Chat] chat The chat object, which represents the
|
22
|
+
# conversation context.
|
23
|
+
# @param [#to_a] messages A collection of message objects, representing the
|
24
|
+
# conversation history.
|
11
25
|
# @param [String] voice (optional) to speek with if any.
|
12
|
-
# @param [IO] output (optional) The output stream where terminal output
|
26
|
+
# @param [IO] output (optional) The output stream where terminal output
|
27
|
+
# should be printed. Defaults to STDOUT.
|
13
28
|
#
|
14
29
|
# @return [OllamaChat::FollowChat] A new instance of OllamaChat::FollowChat.
|
15
30
|
def initialize(chat:, messages:, voice: nil, output: STDOUT)
|
@@ -23,7 +38,8 @@ class OllamaChat::FollowChat
|
|
23
38
|
|
24
39
|
# Returns the conversation history (an array of message objects).
|
25
40
|
#
|
26
|
-
# @return [OllamaChat::MessageList<Ollama::Message>] The array of messages in
|
41
|
+
# @return [OllamaChat::MessageList<Ollama::Message>] The array of messages in
|
42
|
+
# the conversation.
|
27
43
|
attr_reader :messages
|
28
44
|
|
29
45
|
# Invokes the chat flow based on the provided Ollama server response.
|
@@ -32,15 +48,18 @@ class OllamaChat::FollowChat
|
|
32
48
|
# about the user input and the assistant's response.
|
33
49
|
#
|
34
50
|
# If the response indicates an assistant message, this method:
|
35
|
-
# 1. Ensures that an assistant response exists in the message history (if
|
36
|
-
#
|
51
|
+
# 1. Ensures that an assistant response exists in the message history (if
|
52
|
+
# not already present).
|
53
|
+
# 2. Updates the last message with the new content and thinking (if
|
54
|
+
# applicable).
|
37
55
|
# 3. Displays the formatted terminal output for the user.
|
38
56
|
# 4. Outputs the voice response (if configured).
|
39
57
|
#
|
40
58
|
# Regardless of whether an assistant message is present, this method also
|
41
59
|
# outputs evaluation statistics (if applicable).
|
42
60
|
#
|
43
|
-
# @param [Ollama::Response] response The parsed JSON response from the Ollama
|
61
|
+
# @param [Ollama::Response] response The parsed JSON response from the Ollama
|
62
|
+
# server.
|
44
63
|
#
|
45
64
|
# @return [OllamaChat::FollowChat] The current instance for method chaining.
|
46
65
|
def call(response)
|