ollama_chat 0.0.19 → 0.0.20
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 +12 -0
- data/VERSION +1 -1
- data/lib/ollama_chat/clipboard.rb +0 -1
- data/lib/ollama_chat/dialog.rb +61 -0
- data/lib/ollama_chat/document_cache.rb +12 -0
- data/lib/ollama_chat/follow_chat.rb +0 -1
- data/lib/ollama_chat/information.rb +43 -0
- data/lib/ollama_chat/message_format.rb +18 -0
- data/lib/ollama_chat/message_output.rb +28 -3
- data/lib/ollama_chat/model_handling.rb +0 -1
- data/lib/ollama_chat/ollama_chat_config.rb +41 -0
- data/lib/ollama_chat/parsing.rb +76 -0
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +2 -2
- 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: f42ba971131695901f87aea1e9b7c99a41781a61acfae487e812c5c3f185aa01
|
4
|
+
data.tar.gz: b27f7e733b13c3f0023c189fc7be8ac9a1efab943ef562ad5c322e6ad085c7c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 393146c6eb88e53e056ef5b303076c0584cb8f28f32db4e37b44dd24a845bc86c2987239f31cbfd600906030af004f020e68e4a30491945be250704353b3a567
|
7
|
+
data.tar.gz: b9ab5d2f1ab4d9abf34da61e341304fcf0f1a7fd7fe5e14eb3819ea41f37e3394102b4990a71bf7abd6641b181ef1cf2e40d90fd47e5e3f5665ee081bfb32568
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2025-08-11 v0.0.20
|
4
|
+
|
5
|
+
### Documentation
|
6
|
+
|
7
|
+
- Added more YARD-style documentation to all public methods throughout the codebase.
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- **Message Output**:
|
12
|
+
- Corrected `output(filename)` method to pass the message object to
|
13
|
+
`write_file_unless_exist` for proper content writing.
|
14
|
+
|
3
15
|
## 2025-08-11 v0.0.19
|
4
16
|
|
5
17
|
* Added `/last` command to show last assistant message:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
data/lib/ollama_chat/dialog.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
module OllamaChat::Dialog
|
2
|
+
# The model_with_size method formats a model's size for display
|
3
|
+
# by creating a formatted string that includes the model name and its size
|
4
|
+
# in a human-readable format with appropriate units.
|
5
|
+
#
|
6
|
+
# @param model [ Object ] the model object that has name and size attributes
|
7
|
+
#
|
8
|
+
# @return [ Object ] a result object with an overridden to_s method
|
9
|
+
# that combines the model name and formatted size
|
2
10
|
private def model_with_size(model)
|
3
11
|
result = model.name
|
4
12
|
formatted_size = Term::ANSIColor.bold {
|
@@ -10,6 +18,13 @@ module OllamaChat::Dialog
|
|
10
18
|
result
|
11
19
|
end
|
12
20
|
|
21
|
+
# The choose_model method selects a model from the available list based on
|
22
|
+
# CLI input or user interaction.
|
23
|
+
# It processes the provided CLI model parameter to determine if a regex
|
24
|
+
# selector is used, filters the models accordingly, and prompts the user to
|
25
|
+
# choose from the filtered list if needed.
|
26
|
+
# The method ensures that a model is selected and displays a connection
|
27
|
+
# message with the chosen model and base URL.
|
13
28
|
def choose_model(cli_model, current_model)
|
14
29
|
selector = if cli_model =~ /\A\?+(.*)\z/
|
15
30
|
cli_model = ''
|
@@ -26,11 +41,23 @@ module OllamaChat::Dialog
|
|
26
41
|
STDOUT.puts green { "Connecting to #{model}@#{ollama.base_url} now…" }
|
27
42
|
end
|
28
43
|
|
44
|
+
# The ask? method prompts the user with a question and returns their input.
|
45
|
+
#
|
46
|
+
# @param prompt [ String ] the message to display to the user
|
47
|
+
#
|
48
|
+
# @return [ String ] the user's response with trailing newline removed
|
29
49
|
def ask?(prompt:)
|
30
50
|
print prompt
|
31
51
|
STDIN.gets.chomp
|
32
52
|
end
|
33
53
|
|
54
|
+
# The choose_collection method presents a menu to select or create a document
|
55
|
+
# collection. It displays existing collections along with options to create a
|
56
|
+
# new one or exit.
|
57
|
+
# The method prompts the user for input and updates the document collection
|
58
|
+
# accordingly.
|
59
|
+
#
|
60
|
+
# @param current_collection [ String, nil ] the name of the currently active collection
|
34
61
|
def choose_collection(current_collection)
|
35
62
|
collections = [ current_collection ] + @documents.collections
|
36
63
|
collections = collections.compact.map(&:to_s).uniq.sort
|
@@ -49,8 +76,19 @@ module OllamaChat::Dialog
|
|
49
76
|
info
|
50
77
|
end
|
51
78
|
|
79
|
+
# The document_policy method sets the policy for handling document imports.
|
80
|
+
#
|
81
|
+
# @param value [ String ] the document policy to be set
|
52
82
|
attr_writer :document_policy
|
53
83
|
|
84
|
+
# The choose_document_policy method presents a menu to select a document policy.
|
85
|
+
# It allows the user to choose from importing, embedding, summarizing, or
|
86
|
+
# ignoring documents.
|
87
|
+
# The method displays available policies and sets the selected policy as the
|
88
|
+
# current document policy.
|
89
|
+
# If no valid policy is found, it defaults to the first option.
|
90
|
+
# After selection, it outputs the chosen policy and displays the current
|
91
|
+
# configuration information.
|
54
92
|
def choose_document_policy
|
55
93
|
policies = %w[ importing embedding summarizing ignoring ].sort
|
56
94
|
current = if policies.index(@document_policy)
|
@@ -73,6 +111,15 @@ module OllamaChat::Dialog
|
|
73
111
|
info
|
74
112
|
end
|
75
113
|
|
114
|
+
# The change_system_prompt method allows the user to select or enter a new
|
115
|
+
# system prompt for the chat session.
|
116
|
+
# It provides an interactive chooser when multiple prompts match the given
|
117
|
+
# selector, and sets the selected prompt as the current system prompt for the
|
118
|
+
# messages.
|
119
|
+
#
|
120
|
+
# @param default [ String ] the default system prompt to fall back to
|
121
|
+
# @param system [ String ] the system prompt identifier or pattern to
|
122
|
+
# search for
|
76
123
|
def change_system_prompt(default, system: nil)
|
77
124
|
selector = if system =~ /\A\?(.+)\z/
|
78
125
|
Regexp.new($1)
|
@@ -103,6 +150,11 @@ module OllamaChat::Dialog
|
|
103
150
|
@messages.set_system_prompt(system)
|
104
151
|
end
|
105
152
|
|
153
|
+
# The choose_prompt method presents a menu of available prompts for selection.
|
154
|
+
# It retrieves the list of prompt attributes from the configuration,
|
155
|
+
# adds an '[EXIT]' option to the list, and displays it to the user.
|
156
|
+
# After the user makes a choice, the method either exits the chooser
|
157
|
+
# or applies the selected prompt configuration.
|
106
158
|
def choose_prompt
|
107
159
|
prompts = config.prompts.attribute_names.sort
|
108
160
|
prompts.unshift('[EXIT]')
|
@@ -115,11 +167,20 @@ module OllamaChat::Dialog
|
|
115
167
|
end
|
116
168
|
end
|
117
169
|
|
170
|
+
# The change_voice method allows the user to select a voice from a list of
|
171
|
+
# available options. It uses the chooser to present the options and sets the
|
172
|
+
# selected voice as the current voice.
|
173
|
+
#
|
174
|
+
# @return [ String ] the full name of the chosen voice
|
118
175
|
def change_voice
|
119
176
|
chosen = OllamaChat::Utils::Chooser.choose(config.voice.list)
|
120
177
|
@current_voice = chosen.full? || config.voice.default
|
121
178
|
end
|
122
179
|
|
180
|
+
# The message_list method creates and returns a new MessageList instance
|
181
|
+
# initialized with the current object as its argument.
|
182
|
+
#
|
183
|
+
# @return [ MessageList ] a new MessageList object
|
123
184
|
def message_list
|
124
185
|
MessageList.new(self)
|
125
186
|
end
|
@@ -1,8 +1,20 @@
|
|
1
1
|
module OllamaChat::DocumentCache
|
2
|
+
# The document_cache_class method returns the cache class specified in the
|
3
|
+
# configuration.
|
4
|
+
#
|
5
|
+
# @return [ Class ] the cache class defined by the config.cache setting
|
2
6
|
def document_cache_class
|
3
7
|
Object.const_get(config.cache)
|
4
8
|
end
|
5
9
|
|
10
|
+
# The configure_cache method determines the appropriate cache class to use
|
11
|
+
# for document storage.
|
12
|
+
# It checks if the -M option was specified to use MemoryCache, otherwise it
|
13
|
+
# attempts to use the configured cache class.
|
14
|
+
# If an error occurs during this process, it falls back to using MemoryCache
|
15
|
+
# and reports the error.
|
16
|
+
#
|
17
|
+
# @return [ Class ] the selected cache class to be used for document caching
|
6
18
|
def configure_cache
|
7
19
|
if @opts[?M]
|
8
20
|
Documentrix::Documents::MemoryCache
|
@@ -7,15 +7,31 @@ module OllamaChat::Information
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module UserAgent
|
10
|
+
# The progname method returns the name of the application.
|
11
|
+
#
|
12
|
+
# @return [ String ] the application name "ollama_chat"
|
10
13
|
def progname
|
11
14
|
'ollama_chat'
|
12
15
|
end
|
13
16
|
|
17
|
+
# The user_agent method constructs and returns a user agent string
|
18
|
+
# that combines the program name and the OllamaChat version
|
19
|
+
# separated by a forward slash.
|
20
|
+
#
|
21
|
+
# @return [ String ] the formatted user agent string
|
14
22
|
def user_agent
|
15
23
|
[ progname, OllamaChat::VERSION ] * ?/
|
16
24
|
end
|
17
25
|
end
|
18
26
|
|
27
|
+
# The collection_stats method displays statistics about the current document
|
28
|
+
# collection.
|
29
|
+
#
|
30
|
+
# This method outputs information regarding the active document collection,
|
31
|
+
# including the collection name, total number of embeddings, and a list of
|
32
|
+
# tags.
|
33
|
+
#
|
34
|
+
# @return [ nil ] This method always returns nil.
|
19
35
|
def collection_stats
|
20
36
|
STDOUT.puts <<~EOT
|
21
37
|
Current Collection
|
@@ -27,6 +43,13 @@ module OllamaChat::Information
|
|
27
43
|
nil
|
28
44
|
end
|
29
45
|
|
46
|
+
# The info method displays comprehensive information about the current state
|
47
|
+
# of the ollama_chat instance.
|
48
|
+
# This includes version details, server connection status, model
|
49
|
+
# configurations, embedding settings, and various operational switches.
|
50
|
+
#
|
51
|
+
# @return [ nil ] This method does not return a value; it outputs information
|
52
|
+
# directly to standard output.
|
30
53
|
def info
|
31
54
|
STDOUT.puts "Running ollama_chat version: #{bold(OllamaChat::VERSION)}"
|
32
55
|
STDOUT.puts "Connected to ollama server version: #{bold(server_version)} on: #{bold(server_url)}"
|
@@ -58,6 +81,9 @@ module OllamaChat::Information
|
|
58
81
|
nil
|
59
82
|
end
|
60
83
|
|
84
|
+
# The display_chat_help_message method returns a formatted string containing
|
85
|
+
# all available command-line options and their descriptions for the chat
|
86
|
+
# interface.
|
61
87
|
private def display_chat_help_message
|
62
88
|
<<~EOT
|
63
89
|
/copy to copy last response to clipboard
|
@@ -95,11 +121,18 @@ module OllamaChat::Information
|
|
95
121
|
EOT
|
96
122
|
end
|
97
123
|
|
124
|
+
# The display_chat_help method outputs the chat help message to standard output.
|
125
|
+
#
|
126
|
+
# @return [ nil ] This method always returns nil after printing the help message.
|
98
127
|
def display_chat_help
|
99
128
|
STDOUT.puts display_chat_help_message
|
100
129
|
nil
|
101
130
|
end
|
102
131
|
|
132
|
+
# The usage method displays the command-line interface help text
|
133
|
+
# and returns an exit code of 0.
|
134
|
+
#
|
135
|
+
# @return [ Integer ] always returns 0 indicating successful help display
|
103
136
|
def usage
|
104
137
|
STDOUT.puts <<~EOT
|
105
138
|
Usage: #{progname} [OPTIONS]
|
@@ -123,15 +156,25 @@ module OllamaChat::Information
|
|
123
156
|
0
|
124
157
|
end
|
125
158
|
|
159
|
+
# The version method outputs the program name and its version number to
|
160
|
+
# standard output.
|
161
|
+
#
|
162
|
+
# @return [ Integer ] returns 0 indicating successful execution
|
126
163
|
def version
|
127
164
|
STDOUT.puts "%s %s" % [ progname, OllamaChat::VERSION ]
|
128
165
|
0
|
129
166
|
end
|
130
167
|
|
168
|
+
# The server_version method retrieves the version of the Ollama server.
|
169
|
+
#
|
170
|
+
# @return [ String ] the version string of the connected Ollama server
|
131
171
|
def server_version
|
132
172
|
@server_version ||= ollama.version.version
|
133
173
|
end
|
134
174
|
|
175
|
+
# The server_url method returns the base URL of the Ollama server connection.
|
176
|
+
#
|
177
|
+
# @return [ String ] the base URL used for communicating with the Ollama API
|
135
178
|
def server_url
|
136
179
|
@server_url ||= ollama.base_url
|
137
180
|
end
|
@@ -1,8 +1,20 @@
|
|
1
1
|
module OllamaChat::MessageFormat
|
2
|
+
# The message_type method determines the appropriate message icon based on
|
3
|
+
# whether images are present.
|
4
|
+
#
|
5
|
+
# @param images [ Array ] an array of images
|
6
|
+
#
|
7
|
+
# @return [ String ] returns 📸 if images are present, 📨 otherwise
|
2
8
|
def message_type(images)
|
3
9
|
images.present? ? ?📸 : ?📨
|
4
10
|
end
|
5
11
|
|
12
|
+
# The think_annotate method processes a string and conditionally annotates it
|
13
|
+
# with a thinking emoji if the think feature is enabled.
|
14
|
+
#
|
15
|
+
# @param block [ Proc ] a block that returns a string to be processed
|
16
|
+
#
|
17
|
+
# @return [ String, nil ] the annotated string with a thinking emoji if enabled, otherwise nil
|
6
18
|
def think_annotate(&block)
|
7
19
|
string = block.()
|
8
20
|
string.to_s.size == 0 and return
|
@@ -11,6 +23,12 @@ module OllamaChat::MessageFormat
|
|
11
23
|
end
|
12
24
|
end
|
13
25
|
|
26
|
+
# The talk_annotate method processes a string output by a block and
|
27
|
+
# conditionally adds annotation.
|
28
|
+
#
|
29
|
+
# @param block [ Proc ] a block that returns a string to be processed
|
30
|
+
#
|
31
|
+
# @return [ String, nil ] the annotated string if it has content, otherwise nil
|
14
32
|
def talk_annotate(&block)
|
15
33
|
string = block.()
|
16
34
|
string.to_s.size == 0 and return
|
@@ -1,4 +1,12 @@
|
|
1
1
|
module OllamaChat::MessageOutput
|
2
|
+
# The pipe method forwards the last assistant message to a command's standard
|
3
|
+
# input.
|
4
|
+
#
|
5
|
+
# @param cmd [ String ] the command to which the output should be piped
|
6
|
+
#
|
7
|
+
# @return [ OllamaChat::Chat ] returns self
|
8
|
+
# @return [ nil ] returns nil if the command is not provided or if there is
|
9
|
+
# no assistant message
|
2
10
|
def pipe(cmd)
|
3
11
|
cmd.present? or return
|
4
12
|
if message = @messages.last and message.role == 'assistant'
|
@@ -21,10 +29,19 @@ module OllamaChat::MessageOutput
|
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
32
|
+
# The output method writes the last assistant message to a file.
|
33
|
+
#
|
34
|
+
# @param filename [ String ] the path to the file where the output should be written
|
35
|
+
#
|
36
|
+
# @return [ Chat ] returns self on success, nil on failure
|
37
|
+
#
|
38
|
+
# @see write_file_unless_exist
|
39
|
+
#
|
40
|
+
# @note If no assistant message is available, an error message is printed to stderr.
|
24
41
|
def output(filename)
|
25
42
|
if message = @messages.last and message.role == 'assistant'
|
26
43
|
begin
|
27
|
-
write_file_unless_exist(filename)
|
44
|
+
write_file_unless_exist(filename, message)
|
28
45
|
STDOUT.puts "Last response was written to #{filename.inspect}."
|
29
46
|
self
|
30
47
|
rescue => e
|
@@ -37,7 +54,15 @@ module OllamaChat::MessageOutput
|
|
37
54
|
|
38
55
|
private
|
39
56
|
|
40
|
-
|
57
|
+
# The write_file_unless_exist method creates a new file with the specified
|
58
|
+
# message content, but only if a file with that name does not already exist.
|
59
|
+
#
|
60
|
+
# @param filename [ String ] the path of the file to be created
|
61
|
+
# @param message [ Ollama::Message ] the message object containing the content to write
|
62
|
+
#
|
63
|
+
# @return [ TrueClass ] if the file was successfully created
|
64
|
+
# @return [ nil ] if the file already exists and was not created
|
65
|
+
def write_file_unless_exist(filename, message)
|
41
66
|
if File.exist?(filename)
|
42
67
|
STDERR.puts "File #{filename.inspect} already exists. Choose another filename."
|
43
68
|
return
|
@@ -47,4 +72,4 @@ module OllamaChat::MessageOutput
|
|
47
72
|
end
|
48
73
|
true
|
49
74
|
end
|
50
|
-
|
75
|
+
end
|
@@ -9,6 +9,15 @@ class OllamaChat::OllamaChatConfig
|
|
9
9
|
|
10
10
|
DEFAULT_CONFIG = File.read(DEFAULT_CONFIG_PATH)
|
11
11
|
|
12
|
+
# The initialize method sets up the configuration file path and ensures the
|
13
|
+
# cache directory exists.
|
14
|
+
# It attempts to load configuration from the specified filename or uses a
|
15
|
+
# default path.
|
16
|
+
# If the configuration file is missing and the default path is used, it
|
17
|
+
# creates the necessary directory structure and writes a default
|
18
|
+
# configuration file.
|
19
|
+
#
|
20
|
+
# @param filename [ String, nil ] the path to the configuration file
|
12
21
|
def initialize(filename = nil)
|
13
22
|
@filename = filename || default_path
|
14
23
|
unless File.directory?(cache_dir_path)
|
@@ -27,30 +36,62 @@ class OllamaChat::OllamaChatConfig
|
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
39
|
+
# The filename reader returns the name of the file associated with this instance.
|
30
40
|
attr_reader :filename
|
31
41
|
|
42
|
+
# The config reader returns the configuration object for the chat instance.
|
43
|
+
#
|
44
|
+
# @return [ ComplexConfig::Settings ] the configuration object
|
32
45
|
attr_reader :config
|
33
46
|
|
47
|
+
# The default_config_path method returns the path to the default
|
48
|
+
# configuration file.
|
49
|
+
#
|
50
|
+
# @return [ String ] the path to the default configuration file
|
34
51
|
def default_config_path
|
35
52
|
DEFAULT_CONFIG_PATH
|
36
53
|
end
|
37
54
|
|
55
|
+
# The default_path method constructs the full path to the default
|
56
|
+
# configuration file.
|
57
|
+
#
|
58
|
+
# @return [ Pathname ] a Pathname object representing the path to the
|
59
|
+
# config.yml file within the configuration directory
|
38
60
|
def default_path
|
39
61
|
config_dir_path + 'config.yml'
|
40
62
|
end
|
41
63
|
|
64
|
+
# The config_dir_path method returns the path to the ollama_chat
|
65
|
+
# configuration directory by combining the XDG config home directory with the
|
66
|
+
# 'ollama_chat' subdirectory.
|
67
|
+
#
|
68
|
+
# @return [ Pathname ] the pathname object representing the configuration
|
69
|
+
# directory
|
42
70
|
def config_dir_path
|
43
71
|
XDG.new.config_home + 'ollama_chat'
|
44
72
|
end
|
45
73
|
|
74
|
+
# The cache_dir_path method returns the path to the ollama_chat cache
|
75
|
+
# directory within the XDG cache home directory.
|
76
|
+
#
|
77
|
+
# @return [ Pathname ] the pathname object representing the cache directory path
|
46
78
|
def cache_dir_path
|
47
79
|
XDG.new.cache_home + 'ollama_chat'
|
48
80
|
end
|
49
81
|
|
82
|
+
# The database_path method constructs the full path to the documents database
|
83
|
+
# file by joining the cache directory path with the filename 'documents.db'.
|
84
|
+
#
|
85
|
+
# @return [ Pathname ] the full path to the documents database file
|
50
86
|
def database_path
|
51
87
|
cache_dir_path + 'documents.db'
|
52
88
|
end
|
53
89
|
|
90
|
+
# The diff_tool method returns the preferred diff tool command.
|
91
|
+
# It checks for the DIFF_TOOL environment variable and falls back to
|
92
|
+
# 'vimdiff' if not set.
|
93
|
+
#
|
94
|
+
# @return [ String ] the command name of the diff tool to be used
|
54
95
|
def diff_tool
|
55
96
|
ENV.fetch('DIFF_TOOL', 'vimdiff')
|
56
97
|
end
|
data/lib/ollama_chat/parsing.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module OllamaChat::Parsing
|
2
|
+
# The parse_source method processes different types of input sources and
|
3
|
+
# converts them into a standardized text representation.
|
4
|
+
#
|
5
|
+
# @param source_io [IO] the input source to be parsed
|
6
|
+
#
|
7
|
+
# @return [ String, nil ] the parsed content as a string or nil if the
|
8
|
+
# content type is not supported
|
2
9
|
def parse_source(source_io)
|
3
10
|
case source_io&.content_type
|
4
11
|
when 'text/html'
|
@@ -28,6 +35,16 @@ module OllamaChat::Parsing
|
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
38
|
+
# The parse_csv method processes CSV content from an input source and
|
39
|
+
# converts it into a formatted string representation.
|
40
|
+
# It iterates through each row of the CSV, skipping empty rows, and
|
41
|
+
# constructs a structured output where each row's fields are formatted with
|
42
|
+
# indentation and separated by newlines. The resulting string includes double
|
43
|
+
# newlines between rows for readability.
|
44
|
+
#
|
45
|
+
# @param source_io [ IO ] the input source containing CSV data
|
46
|
+
#
|
47
|
+
# @return [ String ] a formatted string representation of the CSV content
|
31
48
|
def parse_csv(source_io)
|
32
49
|
result = +''
|
33
50
|
CSV.table(File.new(source_io), col_sep: ?,).each do |row|
|
@@ -40,6 +57,18 @@ module OllamaChat::Parsing
|
|
40
57
|
result
|
41
58
|
end
|
42
59
|
|
60
|
+
# The parse_rss method processes an RSS feed source and converts it into a
|
61
|
+
# formatted text representation.
|
62
|
+
# It extracts the channel title and iterates through each item in the feed to
|
63
|
+
# build a structured output.
|
64
|
+
# The method uses the RSS parser to handle the source input and formats the
|
65
|
+
# title, link, publication date, and description of each item into a readable
|
66
|
+
# text format with markdown-style headers and links.
|
67
|
+
#
|
68
|
+
# @param source_io [IO] the input stream containing the RSS feed data
|
69
|
+
#
|
70
|
+
# @return [String] a formatted string representation of the RSS feed with
|
71
|
+
# channel title and item details
|
43
72
|
def parse_rss(source_io)
|
44
73
|
feed = RSS::Parser.parse(source_io, false, false)
|
45
74
|
title = <<~EOT
|
@@ -58,6 +87,18 @@ module OllamaChat::Parsing
|
|
58
87
|
end
|
59
88
|
end
|
60
89
|
|
90
|
+
# The parse_atom method processes an Atom feed from the provided IO source
|
91
|
+
# and converts it into a formatted text representation.
|
92
|
+
# It extracts the feed title and iterates through each item to build a
|
93
|
+
# structured output containing titles, links, and update dates.
|
94
|
+
#
|
95
|
+
# The content of each item is converted using reverse_markdown for better
|
96
|
+
# readability.
|
97
|
+
#
|
98
|
+
# @param source_io [IO] the input stream containing the Atom feed data
|
99
|
+
#
|
100
|
+
# @return [String] a formatted string representation of the Atom feed with
|
101
|
+
# title, items, links, update dates, and content
|
61
102
|
def parse_atom(source_io)
|
62
103
|
feed = RSS::Parser.parse(source_io, false, false)
|
63
104
|
title = <<~EOT
|
@@ -76,11 +117,26 @@ module OllamaChat::Parsing
|
|
76
117
|
end
|
77
118
|
end
|
78
119
|
|
120
|
+
# The pdf_read method extracts text content from a PDF file by reading all
|
121
|
+
# pages.
|
122
|
+
#
|
123
|
+
# @param io [IO] the input stream containing the PDF data
|
124
|
+
#
|
125
|
+
# @return [String] the concatenated text content from all pages in the PDF
|
79
126
|
def pdf_read(io)
|
80
127
|
reader = PDF::Reader.new(io)
|
81
128
|
reader.pages.inject(+'') { |result, page| result << page.text }
|
82
129
|
end
|
83
130
|
|
131
|
+
|
132
|
+
# Reads and processes PDF content using Ghostscript for conversion
|
133
|
+
#
|
134
|
+
# This method takes an IO object containing PDF data, processes it through
|
135
|
+
# Ghostscript's pdfwrite device, and returns the processed PDF content.
|
136
|
+
# If Ghostscript is not available in the system path, it outputs an error message.
|
137
|
+
#
|
138
|
+
# @param io [IO] An IO object containing PDF data to be processed
|
139
|
+
# @return [String, nil] The processed PDF content as a string, or nil if processing fails
|
84
140
|
def ps_read(io)
|
85
141
|
gs = `which gs`.chomp
|
86
142
|
if gs.present?
|
@@ -102,6 +158,15 @@ module OllamaChat::Parsing
|
|
102
158
|
end
|
103
159
|
end
|
104
160
|
|
161
|
+
# The reverse_markdown method converts HTML content into Markdown format.
|
162
|
+
#
|
163
|
+
# This method processes HTML input and transforms it into equivalent
|
164
|
+
# Markdown, using specific conversion options to ensure compatibility and
|
165
|
+
# formatting.
|
166
|
+
#
|
167
|
+
# @param html [ String ] the HTML string to be converted
|
168
|
+
#
|
169
|
+
# @return [ String ] the resulting Markdown formatted string
|
105
170
|
def reverse_markdown(html)
|
106
171
|
ReverseMarkdown.convert(
|
107
172
|
html,
|
@@ -111,6 +176,17 @@ module OllamaChat::Parsing
|
|
111
176
|
)
|
112
177
|
end
|
113
178
|
|
179
|
+
# Parses content and processes embedded resources based on document policy
|
180
|
+
#
|
181
|
+
# This method analyzes input content for URLs, tags, and file references,
|
182
|
+
# fetches referenced resources, and processes them according to the current
|
183
|
+
# document policy. It supports different processing modes for various content
|
184
|
+
# types.
|
185
|
+
#
|
186
|
+
# @param content [String] The input content string to parse
|
187
|
+
# @param images [Array] An array to collect image references (will be cleared)
|
188
|
+
# @return [Array<String, Documentrix::Utils::Tags>] Returns an array containing
|
189
|
+
# the processed content string and tags object if any tags were found
|
114
190
|
def parse_content(content, images)
|
115
191
|
images.clear
|
116
192
|
tags = Documentrix::Utils::Tags.new valid_tag: /\A#*([\w\]\[]+)/
|
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.20 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.20".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]
|