Module: OllamaChat::Information

Extended by:
Tins::Concern
Included in:
Chat
Defined in:
lib/ollama_chat/information.rb

Overview

A module that provides information and user agent functionality for OllamaChat

The Information module encapsulates methods for managing application identification, displaying version and configuration details, and handling command-line interface help messages. It includes user agent capabilities for HTTP requests and provides comprehensive information display features for chat sessions.

Examples:

Displaying application information

chat.info

Showing version details

chat.version

Displaying usage help

chat.usage

Defined Under Namespace

Modules: UserAgent

Instance Method Summary collapse

Instance Method Details

#collection_statsnil

The collection_stats method displays statistics about the current document collection.

This method outputs information regarding the active document collection, including the collection name, total number of embeddings, and a list of tags.

Returns:

  • (nil)

    This method always returns nil.



66
67
68
69
70
71
72
73
74
75
# File 'lib/ollama_chat/information.rb', line 66

def collection_stats
  STDOUT.puts <<~EOT
    Current Collection
      Name: #{bold{@documents.collection}}
      #Embeddings: #{@documents.size}
      #Tags: #{@documents.tags.size}
      Tags: #{@documents.tags}
  EOT
  nil
end

#display_chat_helpnil

The display_chat_help method outputs the chat help message to standard output.

Returns:

  • (nil)

    This method always returns nil after printing the help message.



159
160
161
162
# File 'lib/ollama_chat/information.rb', line 159

def display_chat_help
  STDOUT.puts display_chat_help_message
  nil
end

#display_chat_help_messageObject (private)

The display_chat_help_message method returns a formatted string containing all available command-line options and their descriptions for the chat interface.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ollama_chat/information.rb', line 118

private def display_chat_help_message
  <<~EOT
    /copy                           to copy last response to clipboard
    /paste                          to paste content
    /markdown                       toggle markdown output
    /stream                         toggle stream output
    /location                       toggle location submission
    /voice [change]                 toggle voice output or change the voice
    /last [n]                       show the last n / 1 system/assistant message
    /list [n]                       list the last n / all conversation exchanges
    /clear [what]                   clear what=messages|links|history|tags|all
    /clobber                        clear the conversation, links, and collection
    /drop [n]                       drop the last n exchanges, defaults to 1
    /model                          change the model
    /system [show]                  change/show system prompt
    /prompt                         prefill user prompt with preset prompts
    /regenerate                     the last answer message
    /collection [clear|change]      change (default) collection or clear
    /info                           show information for current session
    /config                         output current configuration (#{@ollama_chat_config.filename.to_s.inspect})
    /document_policy                pick a scan policy for document references
    /think                          enable ollama think setting for models
    /import source                  import the source's content
    /summarize [n] source           summarize the source's content in n words
    /embedding                      toggle embedding paused or not
    /embed source                   embed the source's content
    /web [n] query                  query web & for n(=1) results (policy: #@document_policy)
    /links [clear]                  display (or clear) links used in the chat
    /save filename                  store conversation messages
    /load filename                  load conversation messages
    /output filename                save last response to filename
    /pipe command                   write last response to command's stdin
    /vim                            insert the last message into a vim server
    /quit                           to quit
    /help                           to view this help
  EOT
end

#infonil

The info method displays comprehensive information about the current state of the ollama_chat instance. This includes version details, server connection status, model configurations, embedding settings, and various operational switches.

directly to standard output.

Returns:

  • (nil)

    This method does not return a value; it outputs information



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ollama_chat/information.rb', line 84

def info
  STDOUT.puts "Running ollama_chat version: #{bold(OllamaChat::VERSION)}"
  STDOUT.puts "Connected to ollama server version: #{bold(server_version)} on: #{bold(server_url)}"
  STDOUT.puts "Current conversation model is #{bold{@model}}."
  if @model_options.present?
    STDOUT.puts "  Options: #{JSON.pretty_generate(@model_options).gsub(/(?<!\A)^/, '  ')}"
  end
  @embedding.show
  if @embedding.on?
    STDOUT.puts "Current embedding model is #{bold{@embedding_model}}"
    if @embedding_model_options.present?
      STDOUT.puts "  Options: #{JSON.pretty_generate(@embedding_model_options).gsub(/(?<!\A)^/, '  ')}"
    end
    STDOUT.puts "Text splitter is #{bold{config.embedding.splitter.name}}."
    collection_stats
  end
  markdown.show
  stream.show
  think.show
  location.show
  voice.show
  if @voice.on?
    STDOUT.puts "  Using voice #{bold{@current_voice}} to speak."
  end
  STDOUT.puts "Documents database cache is #{@documents.nil? ? 'n/a' : bold{@documents.cache.class}}"
  STDOUT.puts "Document policy for references in user text: #{bold{@document_policy}}"
  STDOUT.puts "Currently selected search engine is #{bold(search_engine)}."
  STDOUT.puts "Conversation length: #{bold(@messages.size.to_s)} message(s)."
  nil
end

#server_urlString

The server_url method returns the base URL of the Ollama server connection.

Returns:

  • (String)

    the base URL used for communicating with the Ollama API



210
211
212
# File 'lib/ollama_chat/information.rb', line 210

def server_url
  @server_url ||= ollama.base_url
end

#server_versionString

The server_version method retrieves the version of the Ollama server.

Returns:

  • (String)

    the version string of the connected Ollama server



203
204
205
# File 'lib/ollama_chat/information.rb', line 203

def server_version
  @server_version ||= ollama.version.version
end

#usageInteger

The usage method displays the command-line interface help text and returns an exit code of 0.

Returns:

  • (Integer)

    always returns 0 indicating successful help display



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ollama_chat/information.rb', line 168

def usage
  STDOUT.puts <<~EOT
    Usage: #{progname} [OPTIONS]

      -f CONFIG      config file to read
      -u URL         the ollama base url, OLLAMA_URL
      -m MODEL       the ollama model to chat with, OLLAMA_CHAT_MODEL, ?selector
      -s SYSTEM      the system prompt to use as a file, OLLAMA_CHAT_SYSTEM, ?selector
      -c CHAT        a saved chat conversation to load
      -C COLLECTION  name of the collection used in this conversation
      -D DOCUMENT    load document and add to embeddings collection (multiple)
      -M             use (empty) MemoryCache for this chat session
      -E             disable embeddings for this chat session
      -S             open a socket to receive input from ollama_chat_send
      -V             display the current version number and quit
      -h             this help

      Use `?selector` with `-m` or `-s` to filter options. Multiple matches
      will open a chooser dialog.
  EOT
  0
end

#versionInteger

The version method outputs the program name and its version number to standard output.

Returns:

  • (Integer)

    returns 0 indicating successful execution



195
196
197
198
# File 'lib/ollama_chat/information.rb', line 195

def version
  STDOUT.puts "%s %s" % [ progname, OllamaChat::VERSION ]
  0
end