ollama_chat 0.0.12 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c11573f3fe926d4b3a52336ae1fbae81587365725b1fe3724406b0d0d6fd2bf1
4
- data.tar.gz: 756a07f1f4eb9056b5b2ff8441a034022d31df4c5b6c199c409c34438dad9aa7
3
+ metadata.gz: a6a03b8af7c470d83520d269829f51fe480f7a5813bc1b4df50c63d339e28953
4
+ data.tar.gz: cb86dd9896d6948fb736c889a672fb29e4f21c8174a3ddb62d6fcc93be59f020
5
5
  SHA512:
6
- metadata.gz: a58029a24c550ee8b1b934ea0c995fe95ce6015fd23af0a503b939dfa8fb681e451293b5b4437bd04fb036b7d6643b4c30468c1c129a5bb0a546247e3b51a0cf
7
- data.tar.gz: 0bf0ea4532ea5dea7977cb5ef97505c336082c60f67f0be03ee1ffda815de76fd8fa23625b1e88b2595434476f6258a59e251150f1aa7705de8881a70f2a12f9
6
+ metadata.gz: ef19594894b1bb11217e710e1a302a2d30add6140da629c66e3e60d990e30f45a29196d310e06f7c06b36d8ddf33f84e7bd4278f87705b48e501b06d5f53d290
7
+ data.tar.gz: 332c66cdca39a187ecb3aff193e5a2522ad11deabaedb584c32a78a620d4c068be3cc062d181a5e6c1d0bf44fed371b3409010f2a4e404614ba142e37d5afbdc
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-06-05 v0.0.13
4
+
5
+ * Improved chat command handling
6
+ - Added support for '/clear tags' to clear all tags.
7
+ - Updated cases for 'history', 'all' and added case for 'tags'.
8
+ - Added commands to clear documents collection and print a message in `information.rb`.
9
+ - `OllamaChat::Chat#clean` now accepts 'tags' as an option.
10
+ * Apply read and write timeouts from configuration (300 seconds) for ollama server.
11
+ * Added method comments
12
+
3
13
  ## 2025-06-01 v0.0.12
4
14
 
5
15
  * **API Compatibility**: Enforces Ollama API version `0.9.0` or higher to
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -41,8 +41,11 @@ class OllamaChat::Chat
41
41
  setup_switches(config)
42
42
  base_url = @opts[?u] || config.url
43
43
  @ollama = Ollama::Client.new(
44
- base_url: base_url,
45
- debug: config.debug,
44
+ connect_timeout: config.timeouts.connect_timeout?,
45
+ read_timeout: config.timeouts.read_timeout?,
46
+ write_timeout: config.timeouts.write_timeout?,
47
+ base_url: base_url,
48
+ debug: config.debug,
46
49
  user_agent:
47
50
  )
48
51
  if server_version.version < '0.9.0'.version
@@ -136,7 +139,7 @@ class OllamaChat::Chat
136
139
  last = 2 * $1.to_i if $1
137
140
  messages.list_conversation(last)
138
141
  :next
139
- when %r(^/clear(?:\s+(messages|links|history|all))?$)
142
+ when %r(^/clear(?:\s+(messages|links|history|tags|all))?$)
140
143
  clean($1)
141
144
  :next
142
145
  when %r(^/clobber$)
@@ -306,6 +309,9 @@ class OllamaChat::Chat
306
309
  when 'history'
307
310
  clear_history
308
311
  STDOUT.puts "Cleared history."
312
+ when 'tags'
313
+ @documents.clear
314
+ STDOUT.puts "Cleared all tags."
309
315
  when 'all'
310
316
  if ask?(prompt: 'Are you sure to clear messages and collection? (y/n) ') =~ /\Ay/i
311
317
  messages.clear
@@ -1,4 +1,13 @@
1
1
  module OllamaChat::Clipboard
2
+
3
+ # Copy the last assistant's message to the system clipboard.
4
+ #
5
+ # This method checks if there is a last message from an assistant in the `@messages`
6
+ # array and copies its content to the clipboard using the specified command from `config.copy`.
7
+ # If no assistant response is available or the clipboard command is not found, appropriate
8
+ # error messages are displayed.
9
+ #
10
+ # @return [NilClass] Always returns nil.
2
11
  def copy_to_clipboard
3
12
  if message = @messages.last and message.role == 'assistant'
4
13
  copy = `which #{config.copy}`.chomp
@@ -16,6 +25,13 @@ module OllamaChat::Clipboard
16
25
  nil
17
26
  end
18
27
 
28
+ # Paste content from the input.
29
+ #
30
+ # Prompts the user to paste their content and then press C-d (Ctrl+D) to terminate
31
+ # input. Reads all lines from standard input until Ctrl+D is pressed and returns
32
+ # the pasted content as a string.
33
+ #
34
+ # @return [String] The pasted content entered by the user.
19
35
  def paste_from_input
20
36
  STDOUT.puts bold { "Paste your content and then press C-d!" }
21
37
  STDIN.read
@@ -66,7 +66,7 @@ module OllamaChat::Information
66
66
  /location toggle location submission
67
67
  /voice [change] toggle voice output or change the voice
68
68
  /list [n] list the last n / all conversation exchanges
69
- /clear [messages|links|history] clear the all messages, links, or the chat history (defaults to messages)
69
+ /clear [what] clear what=messages|links|history|tags|all
70
70
  /clobber clear the conversation, links, and collection
71
71
  /drop [n] drop the last n exchanges, defaults to 1
72
72
  /model change the model
@@ -5,6 +5,10 @@ model:
5
5
  name: <%= ENV.fetch('OLLAMA_CHAT_MODEL', 'llama3.1') %>
6
6
  options:
7
7
  num_ctx: 8192
8
+ timeouts:
9
+ connect_timeout: null
10
+ read_timeout: 300
11
+ write_timeout: 300
8
12
  location:
9
13
  enabled: false
10
14
  name: Berlin
@@ -1,13 +1,23 @@
1
1
  module OllamaChat::ServerSocket
2
2
  class << self
3
+ # Returns the path to the XDG runtime directory, or a default path if not set.
4
+ # @return [String] the expanded path to the XDG runtime directory
3
5
  def runtime_dir
4
6
  File.expand_path(ENV.fetch('XDG_RUNTIME_DIR', '~/.local/run'))
5
7
  end
6
8
 
9
+ # Constructs the full path to the server socket file.
10
+ # @return [String] the full path to the Unix socket
7
11
  def server_socket_path
8
12
  File.join(runtime_dir, 'ollama_chat.sock')
9
13
  end
10
14
 
15
+ # Sends a message to the server socket.
16
+ #
17
+ # @param content [String] the content to send
18
+ # @param type [Symbol] the type of message (default: :socket_input)
19
+ # @raise [Errno::ENOENT] if the socket file does not exist
20
+ # @raise [Errno::ECONNREFUSED] if the socket is not listening (server no running)
11
21
  def send_to_server_socket(content, type: :socket_input)
12
22
  FileUtils.mkdir_p runtime_dir
13
23
  message = { content:, type: }
@@ -17,8 +27,20 @@ module OllamaChat::ServerSocket
17
27
  end
18
28
  end
19
29
 
30
+ # Accessor for the server socket message.
31
+ # Holds the last message received from the Unix socket.
32
+ # @return [String, nil] the message content, or nil if not set
33
+ # @see OllamaChat::ServerSocket#init_server_socket
34
+ # @see OllamaChat::ServerSocket#send_to_server_socket
20
35
  attr_accessor :server_socket_message
21
36
 
37
+ # Initializes a Unix domain socket server for OllamaChat.
38
+ #
39
+ # Creates the necessary runtime directory, checks for existing socket file,
40
+ # and starts a server loop in a new thread. Listens for incoming connections,
41
+ # reads JSON data, and terminates the server upon receiving a message.
42
+ #
43
+ # Raises Errno::EEXIST if the socket path already exists.
22
44
  def init_server_socket
23
45
  FileUtils.mkdir_p OllamaChat::ServerSocket.runtime_dir
24
46
  if File.exist?(OllamaChat::ServerSocket.server_socket_path)
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.12'
3
+ VERSION = '0.0.13'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.12 ruby lib
2
+ # stub: ollama_chat 0.0.13 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.12".freeze
6
+ s.version = "0.0.13".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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank