ollama_chat 0.0.56 → 0.0.58
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 +46 -0
- data/Rakefile +2 -1
- data/docker-compose.yml +1 -1
- data/lib/ollama_chat/chat.rb +47 -20
- data/lib/ollama_chat/clipboard.rb +8 -7
- data/lib/ollama_chat/conversation.rb +2 -2
- data/lib/ollama_chat/dialog.rb +2 -41
- data/lib/ollama_chat/document_cache.rb +8 -7
- data/lib/ollama_chat/env_config.rb +9 -0
- data/lib/ollama_chat/follow_chat.rb +8 -8
- data/lib/ollama_chat/history.rb +1 -1
- data/lib/ollama_chat/information.rb +5 -7
- data/lib/ollama_chat/kramdown_ansi.rb +2 -2
- data/lib/ollama_chat/message_list.rb +7 -5
- data/lib/ollama_chat/message_output.rb +8 -5
- data/lib/ollama_chat/model_handling.rb +2 -4
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +3 -2
- data/lib/ollama_chat/ollama_chat_config.rb +2 -2
- data/lib/ollama_chat/parsing.rb +6 -5
- data/lib/ollama_chat/server_socket.rb +4 -4
- data/lib/ollama_chat/source_fetching.rb +8 -7
- data/lib/ollama_chat/state_selectors.rb +146 -0
- data/lib/ollama_chat/switches.rb +7 -9
- data/lib/ollama_chat/think_control.rb +11 -39
- data/lib/ollama_chat/utils/fetcher.rb +1 -1
- data/lib/ollama_chat/version.rb +1 -1
- data/lib/ollama_chat/web_searching.rb +3 -3
- data/lib/ollama_chat.rb +1 -0
- data/ollama_chat.gemspec +6 -5
- data/spec/ollama_chat/chat_spec.rb +5 -9
- data/spec/ollama_chat/clipboard_spec.rb +1 -1
- data/spec/ollama_chat/information_spec.rb +1 -1
- data/spec/ollama_chat/input_content_spec.rb +1 -1
- data/spec/ollama_chat/message_editing_spec.rb +1 -1
- data/spec/ollama_chat/message_output_spec.rb +1 -1
- data/spec/ollama_chat/model_handling_spec.rb +1 -1
- data/spec/ollama_chat/parsing_spec.rb +6 -6
- data/spec/ollama_chat/source_fetching_spec.rb +1 -3
- data/spec/ollama_chat/state_selectors_spec.rb +193 -0
- data/spec/ollama_chat/think_control_spec.rb +41 -101
- data/spec/ollama_chat/web_searching_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -2
- metadata +19 -1
|
@@ -75,7 +75,7 @@ class OllamaChat::OllamaChatConfig
|
|
|
75
75
|
# configuration file.
|
|
76
76
|
#
|
|
77
77
|
# @return [ Pathname ] a Pathname object representing the path to the
|
|
78
|
-
#
|
|
78
|
+
# config.yml file within the configuration directory
|
|
79
79
|
def default_path
|
|
80
80
|
config_dir_path + 'config.yml'
|
|
81
81
|
end
|
|
@@ -85,7 +85,7 @@ class OllamaChat::OllamaChatConfig
|
|
|
85
85
|
# 'ollama_chat' subdirectory.
|
|
86
86
|
#
|
|
87
87
|
# @return [ Pathname ] the pathname object representing the configuration
|
|
88
|
-
#
|
|
88
|
+
# directory
|
|
89
89
|
def config_dir_path
|
|
90
90
|
OllamaChat::EnvConfig::XDG_CONFIG_HOME
|
|
91
91
|
end
|
data/lib/ollama_chat/parsing.rb
CHANGED
|
@@ -18,7 +18,7 @@ module OllamaChat::Parsing
|
|
|
18
18
|
# @param source_io [IO] the input source to be parsed
|
|
19
19
|
#
|
|
20
20
|
# @return [ String, nil ] the parsed content as a string or nil if the
|
|
21
|
-
#
|
|
21
|
+
# content type is not supported
|
|
22
22
|
def parse_source(source_io)
|
|
23
23
|
case source_io&.content_type
|
|
24
24
|
when 'text/html'
|
|
@@ -79,7 +79,7 @@ module OllamaChat::Parsing
|
|
|
79
79
|
# @param source_io [IO] the input stream containing the RSS feed data
|
|
80
80
|
#
|
|
81
81
|
# @return [String] a formatted string representation of the RSS feed with
|
|
82
|
-
#
|
|
82
|
+
# channel title and item details
|
|
83
83
|
def parse_rss(source_io)
|
|
84
84
|
feed = RSS::Parser.parse(source_io, false, false)
|
|
85
85
|
title = <<~EOT
|
|
@@ -109,7 +109,7 @@ module OllamaChat::Parsing
|
|
|
109
109
|
# @param source_io [IO] the input stream containing the Atom feed data
|
|
110
110
|
#
|
|
111
111
|
# @return [String] a formatted string representation of the Atom feed with
|
|
112
|
-
#
|
|
112
|
+
# title, items, links, update dates, and content
|
|
113
113
|
def parse_atom(source_io)
|
|
114
114
|
feed = RSS::Parser.parse(source_io, false, false)
|
|
115
115
|
title = <<~EOT
|
|
@@ -147,7 +147,8 @@ module OllamaChat::Parsing
|
|
|
147
147
|
# If Ghostscript is not available in the system path, it outputs an error message.
|
|
148
148
|
#
|
|
149
149
|
# @param io [IO] An IO object containing PDF data to be processed
|
|
150
|
-
# @return [String, nil] The processed PDF content as a string, or nil if
|
|
150
|
+
# @return [String, nil] The processed PDF content as a string, or nil if
|
|
151
|
+
# processing fails
|
|
151
152
|
def ps_read(io)
|
|
152
153
|
gs = `which gs`.chomp
|
|
153
154
|
if gs.present?
|
|
@@ -245,7 +246,7 @@ module OllamaChat::Parsing
|
|
|
245
246
|
when 'image'
|
|
246
247
|
add_image(images, source_io, source)
|
|
247
248
|
when 'text', 'application', nil
|
|
248
|
-
case
|
|
249
|
+
case document_policy.selected
|
|
249
250
|
when 'ignoring'
|
|
250
251
|
nil
|
|
251
252
|
when 'importing'
|
|
@@ -43,7 +43,7 @@ module OllamaChat::ServerSocket
|
|
|
43
43
|
# @param parse [ TrueClass, FalseClass ] whether to parse the response, defaults to false
|
|
44
44
|
#
|
|
45
45
|
# @return [ UnixSocks::Message, nil ] the response from transmit_with_response if type
|
|
46
|
-
#
|
|
46
|
+
# is :socket_input_with_response, otherwise nil
|
|
47
47
|
def send_to_server_socket(content, config:, type: :socket_input, runtime_dir: nil, working_dir: nil, parse: false)
|
|
48
48
|
server = create_socket_server(config:, runtime_dir:, working_dir:)
|
|
49
49
|
message = { content:, type:, parse: }
|
|
@@ -66,12 +66,12 @@ module OllamaChat::ServerSocket
|
|
|
66
66
|
# for Unix domain sockets.
|
|
67
67
|
#
|
|
68
68
|
# @param config [ComplexConfig::Settings] the configuration object
|
|
69
|
-
#
|
|
69
|
+
# containing server settings
|
|
70
70
|
# @param runtime_dir [ String ] pathname to runtime_dir of socket file
|
|
71
71
|
# @param working_dir [ String ] pathname to working_dir used for deriving socket file
|
|
72
72
|
#
|
|
73
73
|
# @return [UnixSocks::DomainSocketServer] a configured Unix domain socket server
|
|
74
|
-
#
|
|
74
|
+
# instance ready to receive messages
|
|
75
75
|
def create_socket_server(config:, runtime_dir: nil, working_dir: nil)
|
|
76
76
|
working_dir ||= Dir.pwd
|
|
77
77
|
if runtime_dir
|
|
@@ -91,7 +91,7 @@ module OllamaChat::ServerSocket
|
|
|
91
91
|
# the server socket message instance variable.
|
|
92
92
|
#
|
|
93
93
|
# @return [ Object, nil ] the current server socket message object or nil if
|
|
94
|
-
#
|
|
94
|
+
# not set
|
|
95
95
|
attr_accessor :server_socket_message
|
|
96
96
|
|
|
97
97
|
# Initializes the server socket to receive messages from the Ollama Chat
|
|
@@ -32,7 +32,7 @@ module OllamaChat::SourceFetching
|
|
|
32
32
|
# @param url [ String ] the URL for which HTTP options are being prepared
|
|
33
33
|
#
|
|
34
34
|
# @return [ Hash ] a hash containing HTTP options such as ssl_verify_peer and
|
|
35
|
-
#
|
|
35
|
+
# proxy settings
|
|
36
36
|
def http_options(url)
|
|
37
37
|
options = {}
|
|
38
38
|
if ssl_no_verify = config.ssl_no_verify?
|
|
@@ -49,7 +49,8 @@ module OllamaChat::SourceFetching
|
|
|
49
49
|
# including commands, URLs, and file paths. It processes the source based on
|
|
50
50
|
# its type and yields a temporary file handle for further processing.
|
|
51
51
|
#
|
|
52
|
-
# @param source [ String ] the source identifier which can be a command, URL,
|
|
52
|
+
# @param source [ String ] the source identifier which can be a command, URL,
|
|
53
|
+
# or file path
|
|
53
54
|
#
|
|
54
55
|
# @yield [ tmp ]
|
|
55
56
|
def fetch_source(source, check_exist: false, &block)
|
|
@@ -135,7 +136,7 @@ module OllamaChat::SourceFetching
|
|
|
135
136
|
# @param source [ String ] the source identifier or path
|
|
136
137
|
#
|
|
137
138
|
# @return [ String ] a formatted message indicating the import result and the
|
|
138
|
-
#
|
|
139
|
+
# parsed content
|
|
139
140
|
def import_source(source_io, source)
|
|
140
141
|
source = source.to_s
|
|
141
142
|
document_type = source_io&.content_type.full? { |ct| italic { ct } + ' ' }
|
|
@@ -150,7 +151,7 @@ module OllamaChat::SourceFetching
|
|
|
150
151
|
# passes the resulting IO object to the import_source method for processing.
|
|
151
152
|
#
|
|
152
153
|
# @param source [String] The source identifier which can be a command, URL,
|
|
153
|
-
#
|
|
154
|
+
# or file path
|
|
154
155
|
#
|
|
155
156
|
# @return [String, nil] A formatted message indicating the import result and
|
|
156
157
|
# parsed content, # or nil if the operation fails
|
|
@@ -208,7 +209,7 @@ module OllamaChat::SourceFetching
|
|
|
208
209
|
# @param count [Integer, nil] An optional counter for tracking processing order
|
|
209
210
|
#
|
|
210
211
|
# @return [Array, String, nil] The embedded chunks or processed content, or
|
|
211
|
-
#
|
|
212
|
+
# nil if embedding is disabled or fails
|
|
212
213
|
def embed_source(source_io, source, count: nil)
|
|
213
214
|
@embedding.on? or return parse_source(source_io)
|
|
214
215
|
m = "Embedding #{italic { source_io&.content_type }} document #{source.to_s.inspect}."
|
|
@@ -263,10 +264,10 @@ module OllamaChat::SourceFetching
|
|
|
263
264
|
# disabled, it falls back to generating a summary instead.
|
|
264
265
|
#
|
|
265
266
|
# @param source [String] The source identifier which can be a command, URL,
|
|
266
|
-
#
|
|
267
|
+
# or file path
|
|
267
268
|
#
|
|
268
269
|
# @return [String, nil] The formatted embedding result or summary message, or
|
|
269
|
-
#
|
|
270
|
+
# nil if the operation fails
|
|
270
271
|
def embed(source)
|
|
271
272
|
if @embedding.on?
|
|
272
273
|
STDOUT.puts "Now embedding #{source.to_s.inspect}."
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# A module that provides state selection functionality for OllamaChat.
|
|
2
|
+
#
|
|
3
|
+
# The StateSelectors module encapsulates the StateSelector class, which manages
|
|
4
|
+
# configurable states with selection and display capabilities. It is used to
|
|
5
|
+
# handle various settings in the chat application such as document policies and
|
|
6
|
+
# think modes, allowing users to dynamically configure
|
|
7
|
+
# different aspects of the chat session behavior.
|
|
8
|
+
module OllamaChat::StateSelectors
|
|
9
|
+
# A state selector that manages configurable states with selection and
|
|
10
|
+
# display capabilities.
|
|
11
|
+
class StateSelector
|
|
12
|
+
include Term::ANSIColor
|
|
13
|
+
|
|
14
|
+
# Initializes a new StateSelector with the given configuration.
|
|
15
|
+
#
|
|
16
|
+
# @param name [String] The name of the state selector for display purposes
|
|
17
|
+
# @param states [Array<String>] The list of valid states this selector can have
|
|
18
|
+
# @param default [String, nil] The default state to select (must be one of +states+)
|
|
19
|
+
# @param off [Array<String>, nil] The list of states that should be considered "off"
|
|
20
|
+
# @raise [ArgumentError] If +states+ is empty or +default+ is not in +states+
|
|
21
|
+
def initialize(name:, states:, default: nil, off: nil, allow_empty: false)
|
|
22
|
+
@name = name.to_s
|
|
23
|
+
@states = Set.new(states.map(&:to_s))
|
|
24
|
+
@allow_empty = allow_empty
|
|
25
|
+
unless allow_empty
|
|
26
|
+
@states.empty? and raise ArgumentError, 'states cannot be empty'
|
|
27
|
+
end
|
|
28
|
+
if default
|
|
29
|
+
@default = default.to_s
|
|
30
|
+
unless allow_empty?
|
|
31
|
+
@states.member?(@default) or raise ArgumentError,
|
|
32
|
+
"default has to be one of #{@states.to_a * ', '}."
|
|
33
|
+
end
|
|
34
|
+
@selected = @default
|
|
35
|
+
else
|
|
36
|
+
@selected = @states.first
|
|
37
|
+
end
|
|
38
|
+
@off = Array(off)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The selected reader returns the currently selected state of the switch.
|
|
42
|
+
#
|
|
43
|
+
# @return [Object] the currently selected state value
|
|
44
|
+
attr_reader :selected
|
|
45
|
+
|
|
46
|
+
# The selected= method sets the selected state of the switch.
|
|
47
|
+
#
|
|
48
|
+
# @param value [Object] the value to be converted to a string and set as
|
|
49
|
+
# the selected state
|
|
50
|
+
#
|
|
51
|
+
# @raise [ArgumentError] if the provided value is not one of the valid states
|
|
52
|
+
def selected=(value)
|
|
53
|
+
value = value.to_s
|
|
54
|
+
unless allow_empty?
|
|
55
|
+
@states.member?(value) or raise ArgumentError,
|
|
56
|
+
"value has to be one of #{@states.to_a * ', '}."
|
|
57
|
+
end
|
|
58
|
+
@selected = value
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# The allow_empty? method checks if the switch is allowed to be empty.
|
|
62
|
+
#
|
|
63
|
+
# @return [ TrueClass, FalseClass ] true if the switch is allowed to be
|
|
64
|
+
# empty, false otherwise
|
|
65
|
+
def allow_empty?
|
|
66
|
+
!!@allow_empty
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The off? method checks if the current state is in the off set.
|
|
70
|
+
#
|
|
71
|
+
# @return [ TrueClass, FalseClass ] true if the selected state is in the
|
|
72
|
+
# off set, false otherwise
|
|
73
|
+
def off?
|
|
74
|
+
@off.member?(@selected)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# The on? method checks if the switch is in the on state, returning true if
|
|
78
|
+
# it is enabled and false if it is disabled.
|
|
79
|
+
#
|
|
80
|
+
# @return [ TrueClass, FalseClass ] true if the switch is on, false if it
|
|
81
|
+
# is off
|
|
82
|
+
def on?
|
|
83
|
+
!off?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The choose method presents a menu to select from available states.
|
|
87
|
+
#
|
|
88
|
+
# This method displays the available states to the user and allows them to
|
|
89
|
+
# select one. It handles the user's choice by updating the selected state
|
|
90
|
+
# or exiting the chooser if the user selects '[EXIT]' or cancels the selection.
|
|
91
|
+
#
|
|
92
|
+
# @return [ nil ] This method does not return a value; it updates the instance
|
|
93
|
+
# variable @selected based on user input.
|
|
94
|
+
def choose
|
|
95
|
+
states = @states + [ '[EXIT]' ]
|
|
96
|
+
case chosen = OllamaChat::Utils::Chooser.choose(states)
|
|
97
|
+
when '[EXIT]', nil
|
|
98
|
+
STDOUT.puts "Exiting chooser."
|
|
99
|
+
when
|
|
100
|
+
@selected = chosen
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# The show method outputs the current value of the state selector.
|
|
105
|
+
#
|
|
106
|
+
# This method displays the name of the state selector along with its
|
|
107
|
+
# currently selected state in a formatted message to standard output.
|
|
108
|
+
def show
|
|
109
|
+
STDOUT.puts "#{@name} is #{bold(to_s)}."
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# The to_s method returns the string representation of the selected state.
|
|
113
|
+
#
|
|
114
|
+
# @return [ String ] the string representation of the currently selected
|
|
115
|
+
# state
|
|
116
|
+
def to_s
|
|
117
|
+
@selected.to_s
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Sets up state selectors for document policy and think mode based on the
|
|
122
|
+
# provided configuration.
|
|
123
|
+
#
|
|
124
|
+
# @param config [ComplexConfig::Settings] the configuration object containing
|
|
125
|
+
# settings for document policy and think mode
|
|
126
|
+
def setup_state_selectors(config)
|
|
127
|
+
@document_policy = StateSelector.new(
|
|
128
|
+
name: 'Document policy',
|
|
129
|
+
default: config.document_policy,
|
|
130
|
+
states: %w[ embedding ignoring importing summarizing ],
|
|
131
|
+
off: %w[ ignoring ],
|
|
132
|
+
)
|
|
133
|
+
@think_mode = StateSelector.new(
|
|
134
|
+
name: 'Think mode',
|
|
135
|
+
default: config.think.mode,
|
|
136
|
+
states: %w[ enabled disabled low medium high ],
|
|
137
|
+
off: %w[ disabled ],
|
|
138
|
+
)
|
|
139
|
+
@voices = StateSelector.new(
|
|
140
|
+
name: 'Voice',
|
|
141
|
+
default: config.voice.default,
|
|
142
|
+
states: config.voice.list,
|
|
143
|
+
allow_empty: true
|
|
144
|
+
)
|
|
145
|
+
end
|
|
146
|
+
end
|
data/lib/ollama_chat/switches.rb
CHANGED
|
@@ -64,8 +64,6 @@ module OllamaChat::Switches
|
|
|
64
64
|
#
|
|
65
65
|
# @param msg [ Hash ] a hash containing true and false messages
|
|
66
66
|
# @param value [ Object ] the default state of the switch
|
|
67
|
-
#
|
|
68
|
-
# @return [ void ]
|
|
69
67
|
def initialize(msg:, value:)
|
|
70
68
|
@value = !!value
|
|
71
69
|
@msg = msg
|
|
@@ -78,9 +76,9 @@ module OllamaChat::Switches
|
|
|
78
76
|
# and optionally displays it.
|
|
79
77
|
#
|
|
80
78
|
# @param value [ Object ] the value to be converted to a boolean and
|
|
81
|
-
#
|
|
79
|
+
# assigned
|
|
82
80
|
# @param show [ TrueClass, FalseClass ] determines whether to display the
|
|
83
|
-
#
|
|
81
|
+
# value after setting
|
|
84
82
|
def set(value, show: false)
|
|
85
83
|
@value = !!value
|
|
86
84
|
show && self.show
|
|
@@ -90,7 +88,7 @@ module OllamaChat::Switches
|
|
|
90
88
|
# optionally displays it.
|
|
91
89
|
#
|
|
92
90
|
# @param show [ TrueClass, FalseClass ] determines whether to show the
|
|
93
|
-
#
|
|
91
|
+
# value after toggling
|
|
94
92
|
def toggle(show: true)
|
|
95
93
|
@value = !@value
|
|
96
94
|
show && self.show
|
|
@@ -154,13 +152,13 @@ module OllamaChat::Switches
|
|
|
154
152
|
# The embedding attribute reader returns the embedding switch object.
|
|
155
153
|
#
|
|
156
154
|
# @return [ OllamaChat::Switches::CombinedSwitch ] the embedding switch
|
|
157
|
-
#
|
|
155
|
+
# instance
|
|
158
156
|
attr_reader :embedding
|
|
159
157
|
|
|
160
158
|
# The embedding_enabled reader returns the embedding enabled switch instance.
|
|
161
159
|
#
|
|
162
160
|
# @return [ OllamaChat::Switches::Switch ] the embedding enabled switch
|
|
163
|
-
#
|
|
161
|
+
# instance
|
|
164
162
|
attr_reader :embedding_enabled
|
|
165
163
|
|
|
166
164
|
# The embedding_paused method returns the current state of the embedding pause flag.
|
|
@@ -181,7 +179,7 @@ module OllamaChat::Switches
|
|
|
181
179
|
# output, voice output, embedding, and location settings.
|
|
182
180
|
#
|
|
183
181
|
# @param config [ ComplexConfig::Settings ] the configuration object
|
|
184
|
-
#
|
|
182
|
+
# containing settings for the switches
|
|
185
183
|
def setup_switches(config)
|
|
186
184
|
@stream = Switch.new(
|
|
187
185
|
value: config.stream,
|
|
@@ -192,7 +190,7 @@ module OllamaChat::Switches
|
|
|
192
190
|
)
|
|
193
191
|
|
|
194
192
|
@think_loud = Switch.new(
|
|
195
|
-
value: config.
|
|
193
|
+
value: config.think.loud,
|
|
196
194
|
msg: {
|
|
197
195
|
true => "Thinking out loud, show thinking annotations.",
|
|
198
196
|
false => "Thinking silently, don't show thinking annotations.",
|
|
@@ -5,52 +5,24 @@
|
|
|
5
5
|
# thinking modes, checking the current state, and displaying the current
|
|
6
6
|
# think mode status.
|
|
7
7
|
module OllamaChat::ThinkControl
|
|
8
|
-
# The think method returns the current
|
|
8
|
+
# The think method returns the current think mode selection.
|
|
9
9
|
#
|
|
10
|
-
# @return [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
think_modes = %w[ off on low medium high [EXIT] ]
|
|
19
|
-
case chosen = OllamaChat::Utils::Chooser.choose(think_modes)
|
|
20
|
-
when '[EXIT]', nil
|
|
21
|
-
STDOUT.puts "Exiting chooser."
|
|
22
|
-
when 'off'
|
|
23
|
-
@think = false
|
|
24
|
-
when 'on'
|
|
25
|
-
@think = true
|
|
26
|
-
when 'low', 'medium', 'high'
|
|
27
|
-
@think = chosen
|
|
10
|
+
# @return [ String ] the selected think mode value
|
|
11
|
+
def think
|
|
12
|
+
if think_mode.off?
|
|
13
|
+
false
|
|
14
|
+
elsif think_mode.selected == 'enabled'
|
|
15
|
+
true
|
|
16
|
+
else
|
|
17
|
+
think_mode.selected
|
|
28
18
|
end
|
|
29
19
|
end
|
|
30
20
|
|
|
31
21
|
# The think? method checks if the think mode is enabled.
|
|
32
22
|
#
|
|
33
|
-
# @return [
|
|
34
|
-
# otherwise
|
|
23
|
+
# @return [TrueClass, FalseClass] true if think mode is enabled, false otherwise
|
|
35
24
|
def think?
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# The think_mode method returns the current think mode status as a string.
|
|
40
|
-
#
|
|
41
|
-
# @return [ String ] returns 'enabled' if think mode is true, the think mode
|
|
42
|
-
# value if it's a string, or 'disabled' if think mode is false or nil
|
|
43
|
-
def think_mode
|
|
44
|
-
think == true ? 'enabled' : think || 'disabled'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# The think_show method displays the current think mode status.
|
|
48
|
-
#
|
|
49
|
-
# This method checks the current think mode setting and outputs a message
|
|
50
|
-
# indicating whether think mode is enabled, disabled, or set to a specific
|
|
51
|
-
# mode level (low, medium, high).
|
|
52
|
-
def think_show
|
|
53
|
-
STDOUT.puts "Think mode is #{bold(think_mode)}."
|
|
25
|
+
think_mode.on?
|
|
54
26
|
end
|
|
55
27
|
|
|
56
28
|
# The think_loud? method checks if both think mode and think loud mode are
|
|
@@ -127,7 +127,7 @@ class OllamaChat::Utils::Fetcher
|
|
|
127
127
|
#
|
|
128
128
|
# @return [ nil ] returns nil if the file does not exist
|
|
129
129
|
# @return [ Object ] returns the result of the block execution if the file
|
|
130
|
-
#
|
|
130
|
+
# exists
|
|
131
131
|
def self.read(filename, &block)
|
|
132
132
|
if File.exist?(filename)
|
|
133
133
|
File.open(filename) do |file|
|
data/lib/ollama_chat/version.rb
CHANGED
|
@@ -21,7 +21,7 @@ module OllamaChat::WebSearching
|
|
|
21
21
|
# @param n [ Integer ] the maximum number of results to return
|
|
22
22
|
#
|
|
23
23
|
# @return [ Array<String>, nil ] an array of URLs from the search results or
|
|
24
|
-
#
|
|
24
|
+
# nil if the search engine is not implemented
|
|
25
25
|
def search_web(query, n = nil)
|
|
26
26
|
l = @messages.at_location.full? and query += " #{l}"
|
|
27
27
|
n = n.to_i.clamp(1..)
|
|
@@ -70,10 +70,10 @@ module OllamaChat::WebSearching
|
|
|
70
70
|
#
|
|
71
71
|
# @param query [ String ] the search query string to be used
|
|
72
72
|
# @param n [ Integer ] the maximum number of URLs to extract from the search
|
|
73
|
-
#
|
|
73
|
+
# results
|
|
74
74
|
#
|
|
75
75
|
# @return [ Array<String> ] an array of URL strings extracted from the search
|
|
76
|
-
#
|
|
76
|
+
# results
|
|
77
77
|
def search_web_with_duckduckgo(query, n)
|
|
78
78
|
url = config.web_search.engines.duckduckgo.url % { query: }
|
|
79
79
|
OllamaChat::Utils::Fetcher.get(
|
data/lib/ollama_chat.rb
CHANGED
|
@@ -20,6 +20,7 @@ require 'ollama_chat/message_format'
|
|
|
20
20
|
require 'ollama_chat/ollama_chat_config'
|
|
21
21
|
require 'ollama_chat/follow_chat'
|
|
22
22
|
require 'ollama_chat/switches'
|
|
23
|
+
require 'ollama_chat/state_selectors'
|
|
23
24
|
require 'ollama_chat/message_list'
|
|
24
25
|
require 'ollama_chat/model_handling'
|
|
25
26
|
require 'ollama_chat/parsing'
|
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.58 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.58".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]
|
|
@@ -12,15 +12,15 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.description = "The app provides a command-line interface (CLI) to an Ollama AI model,\nallowing users to engage in text-based conversations and generate\nhuman-like responses. Users can import data from local files or web pages,\nwhich are then processed through three different modes: fully importing the\ncontent into the conversation context, summarizing the information for\nconcise reference, or storing it in an embedding vector database for later\nretrieval based on the conversation.\n".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
14
|
s.executables = ["ollama_chat".freeze, "ollama_chat_send".freeze]
|
|
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/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.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/redis_cache.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/think_control.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/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.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/redis_cache.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/think_control.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/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_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/redis_cache_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/think_control_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/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
|
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/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.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/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/state_selectors.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.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/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.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/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/state_selectors.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.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/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_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/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/state_selectors_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/think_control_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/vim_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]
|
|
20
20
|
s.required_ruby_version = Gem::Requirement.new(">= 3.2".freeze)
|
|
21
21
|
s.rubygems_version = "4.0.3".freeze
|
|
22
22
|
s.summary = "A command-line interface (CLI) for interacting with an Ollama AI model.".freeze
|
|
23
|
-
s.test_files = ["spec/assets/example.rb".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/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_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/redis_cache_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/think_control_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/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
23
|
+
s.test_files = ["spec/assets/example.rb".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/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_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/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/state_selectors_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/think_control_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/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
24
24
|
|
|
25
25
|
s.specification_version = 4
|
|
26
26
|
|
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
|
32
32
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
|
33
33
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
|
34
34
|
s.add_development_dependency(%q<context_spook>.freeze, [">= 0".freeze])
|
|
35
|
+
s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
|
|
35
36
|
s.add_runtime_dependency(%q<excon>.freeze, ["~> 1.0".freeze])
|
|
36
37
|
s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.18".freeze])
|
|
37
38
|
s.add_runtime_dependency(%q<documentrix>.freeze, [">= 0.0.4".freeze])
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe OllamaChat::Chat, protect_env: true do
|
|
4
|
-
use_default_config = -> a {
|
|
5
|
-
a << '-f' << 'lib/ollama_chat/ollama_chat_config/default_config.yml'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
4
|
let :argv do
|
|
9
|
-
|
|
5
|
+
chat_default_config(%w[ -C test ])
|
|
10
6
|
end
|
|
11
7
|
|
|
12
8
|
before do
|
|
@@ -134,7 +130,7 @@ describe OllamaChat::Chat, protect_env: true do
|
|
|
134
130
|
end
|
|
135
131
|
|
|
136
132
|
it 'returns :next when input is "/document_policy"' do
|
|
137
|
-
|
|
133
|
+
expect_any_instance_of(OllamaChat::StateSelectors::StateSelector).to receive(:choose)
|
|
138
134
|
expect(chat.handle_input("/document_policy")).to eq :next
|
|
139
135
|
end
|
|
140
136
|
|
|
@@ -235,7 +231,7 @@ describe OllamaChat::Chat, protect_env: true do
|
|
|
235
231
|
connect_to_ollama_server(instantiate: false)
|
|
236
232
|
|
|
237
233
|
let :argv do
|
|
238
|
-
|
|
234
|
+
chat_default_config(%w[ -C test -c ] << asset('conversation.json'))
|
|
239
235
|
end
|
|
240
236
|
|
|
241
237
|
it 'dispays the last exchange of the converstation' do
|
|
@@ -252,7 +248,7 @@ describe OllamaChat::Chat, protect_env: true do
|
|
|
252
248
|
context 'with MemoryCache' do
|
|
253
249
|
|
|
254
250
|
let :argv do
|
|
255
|
-
|
|
251
|
+
chat_default_config(%w[ -M ])
|
|
256
252
|
end
|
|
257
253
|
|
|
258
254
|
it 'can use MemoryCache' do
|
|
@@ -274,7 +270,7 @@ describe OllamaChat::Chat, protect_env: true do
|
|
|
274
270
|
connect_to_ollama_server(instantiate: false)
|
|
275
271
|
|
|
276
272
|
let :argv do
|
|
277
|
-
|
|
273
|
+
chat_default_config(%w[ -C test -D ] << asset('example.html'))
|
|
278
274
|
end
|
|
279
275
|
|
|
280
276
|
it 'Adds documents passed to app via -D option' do
|