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 providing a modular information dashboard for chat sessions. It includes user agent capabilities for HTTP requests and provides focused information views.

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

#clientString

The client method returns the application name and its current version as a single string

Returns:

  • (String)

    the progname followed by the OllamaChat version separated by a space



62
63
64
# File 'lib/ollama_chat/information.rb', line 62

def client
  [ progname, OllamaChat::VERSION ] * ' '
end

#collection_stats(output: STDOUT) ⇒ Object

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.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to write the message to



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ollama_chat/information.rb', line 74

def collection_stats(output: STDOUT)
  length       = (Tins::Terminal.cols - 10).clamp(0..)
  wrapped_tags = Kramdown::ANSI::Width.
    wrap(@documents.tags.to_a.join(', '), length:).
    gsub(/(?<!\A)^/, ' ' * 4)
  output.puts <<~EOT
    Current Collection
      Name: #{bold{collection}}
      #Embeddings: #{@documents.size}
      #Tags: #{@documents.tags.size}
      Tags:
        #{wrapped_tags}
  EOT
  nil
end

#display_chat_help(pattern = nil) ⇒ nil

The display_chat_help method outputs the chat help message to standard output, eventually using the configured pager.

Parameters:

  • pattern (String, Regexp, nil) (defaults to: nil)

    An optional pattern to filter the commands displayed in the help message.

Returns:

  • (nil)

    This method always returns nil after printing the help message.



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

def display_chat_help(pattern = nil)
  use_pager do |output|
    output.puts help_message(pattern)
  end
  nil
end

#dynamic_runtime_informationString

The dynamic_runtime_information method generates a formatted string containing real-time environment details (the “heartbeat”).

It returns the result of interpolating the dynamic values into the configured ‘dynamic_runtime_info` prompt template.

Returns:

  • (String)

    the formatted dynamic runtime information string.



351
352
353
# File 'lib/ollama_chat/information.rb', line 351

def dynamic_runtime_information
  prompt(:dynamic_runtime_info).to_s % dynamic_runtime_information_values
end

#dynamic_runtime_information_valuesHash

The dynamic_runtime_information_values method compiles a set of volatile runtime details that change frequently.

These include the current timestamp, weekday, session name, git branch and origin, terminal dimensions, and feature switch statuses.

Returns:

  • (Hash)

    a hash containing dynamic runtime values.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ollama_chat/information.rb', line 328

def dynamic_runtime_information_values
  now = Time.now
  {
    git_current_branch:   `git rev-parse --abbrev-ref HEAD 2>/dev/null`.chomp.full? || 'n/a',
    git_remote_origin:    `git remote get-url origin 2>/dev/null`.chomp.full? || 'n/a',
    markdown:             markdown.on? ? 'enabled' : 'disabled',
    session_name:         session.name,
    terminal_cols:        Tins::Terminal.cols,
    terminal_rows:        Tins::Terminal.rows,
    time:                 now.iso8601,
    tools_support:        tools_support.on? ? 'enabled' : 'disabled',
    voice:                voice.on? ? 'enabled' : 'disabled',
    weekday:              now.strftime('%A'),
  }
end

#info(output: STDOUT) ⇒ nil

Displays a high-level summary dashboard of the current state of the ollama_chat instance.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to write the information to, defaults to STDOUT

Returns:

  • (nil)

    This method does not return a value; it outputs information directly to standard output.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ollama_chat/information.rb', line 185

def info(output: STDOUT)
  output.puts "💎 Running ollama_chat version: #{bold{OllamaChat::VERSION}}"
  output.puts "🔌 Connected to ollama server version: #{bold{server_version}} on: #{bold{server_url}}"
  output.puts "📜 Documents database cache is #{@documents.nil? ? 'n/a' : bold{@documents.cache.class}}"
  output.puts "🔎 Currently selected search engine is #{bold{search_engine}}."
  output.puts "🧠 Current chat model is #{bold{@model}}."
  output.puts "🗣️ Session: #{bold{@session.name}} (#{italic{@session.id}})"
  output.puts "  Current System Prompt: #{bold{current_system_prompt_name}}"
  if name = default_persona_name
    output.puts "  💃 Persona: #{bold{name}}"
  else
    output.puts "  No persona selected."
  end
  output.print '  🛠️ '; tools_support.show(output:)
  output.print '  🏃 '; runtime_info.show(output:)
  nil
end

#info_model(output: STDOUT) ⇒ Object

Displays detailed information about the current chat model, including capabilities, families, and configuration options.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to print the model information to (defaults to STDOUT).



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ollama_chat/information.rb', line 95

def info_model(output: STDOUT)
  output.puts "🧠 Current chat model is #{bold{@model}}."
  output.puts   "  Capabilities: #{Array(@model_metadata&.capabilities) * ', '}"
  output.puts   "  Families: #{Array(@model_metadata&.families) * ', '}"

  profiles = models::ModelOptions.where(model_name: @model).order(:profile).all
  if profiles.full?
    output.puts "  Stored Profile Options:"
    profiles.each do |p|
      output.puts <<~EOT.gsub(/^/, '      ')
        #{bold{p.profile}}:
          #{JSON.pretty_generate(p.options)}
      EOT
    end
  elsif config.model.options.full?
    output.puts "  Default Options: #{JSON.pretty_generate(mo).gsub(/(?<!\A)^/, '  ')}"
  end

  if model_options.present?
    output.puts "  Session Options: #{JSON.pretty_generate(model_options).gsub(/(?<!\A)^/, '  ')}"
  end
end

#info_rag(output: STDOUT) ⇒ Object

Displays information regarding the Retrieval Augmented Generation (RAG) configuration, including the embedding model and collection statistics.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to write the information to, defaults to STDOUT



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ollama_chat/information.rb', line 166

def info_rag(output: STDOUT)
  if @embedding.on?
    output.puts "🗄️ Current RAG model is #{bold{@embedding_model}}"
    if @embedding_model_options.present?
      output.puts "  Options: #{JSON.pretty_generate(@embedding_model_options).gsub(/(?<!\A)^/, '  ')}"
    end
    output.puts "Text splitter is #{bold{config.embedding.splitter.name}}."
    collection_stats(output:)
  end
  @embedding.show(output:)
  output.puts "📜 Document policy for parsing in user text: #{bold{document_policy}}"
end

#info_runtime(output: STDOUT) ⇒ Object

Displays the current runtime environment details, split into static (session-level) and dynamic (real-time) information.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to write the information to, defaults to STDOUT



151
152
153
154
155
156
157
158
159
160
# File 'lib/ollama_chat/information.rb', line 151

def info_runtime(output: STDOUT)
  output.puts "🏃 Runtime Information:"
  output.print '  '; runtime_info.show(output:)
  output.puts 'Static:'
  output.puts static_runtime_information_values.stringify_keys_recursive.to_yaml.
    sub(/\A---\s*\n/, '').gsub(/^/, '  ')
  output.puts 'Dynamic:'
  output.puts dynamic_runtime_information_values.stringify_keys_recursive.to_yaml.
    sub(/\A---\s*\n/, '').gsub(/^/, '  ')
end

#info_session(output: STDOUT) ⇒ Object

Displays a detailed view of the current chat session state, including the system prompt, persona, active model, thinking modes, tools, and audio settings.

Parameters:

  • output (IO) (defaults to: STDOUT)

    the output stream to write the information to, defaults to STDOUT



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ollama_chat/information.rb', line 123

def info_session(output: STDOUT)
  output.print "🗣️ Current session: "; show_session(output:)
  output.puts "  Current Session Working Directory: \"#{bold{session.working_directory}}\""
  output.puts "  Current System Prompt: #{bold{current_system_prompt_name}}"
  if name = default_persona_name
    output.puts "  💃 Persona: #{bold{name}}"
  else
    output.puts "  No persona selected."
  end
  output.puts "🧠 Current chat model is #{bold{@model}}."
  output.print '  '; think_mode.show(output:)
  output.print '  '; think_loud.show(output:)
  output.print '  '; think_strip.show(output:)
  output.print '  🛠️ '; tools_support.show(output:)
  output.print '⚙️ Chat Settings'
  output.print '  '; markdown.show(output:)
  output.print '  '; stream.show(output:)
  output.print '  🎙️ '; voice.show(output:)
  if voice.on?
    output.print '  '; voices.show(output:)
  end
  output.print '  '; location.show(output:)
end

#infobar_messageHash

Returns the infobar message configuration as a hash.

This configuration is used by the ‘infobar` gem to define the progress bar’s format and spinner settings.

Returns:

  • (Hash)

    the infobar message configuration



288
289
290
# File 'lib/ollama_chat/information.rb', line 288

def infobar_message
  config.infobar.message.to_h
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



264
265
266
# File 'lib/ollama_chat/information.rb', line 264

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



257
258
259
# File 'lib/ollama_chat/information.rb', line 257

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

#static_runtime_informationString

Generates a formatted string of static runtime information.

This method interpolates the static runtime values into the configured ‘static_runtime_info` prompt template.

Returns:

  • (String)

    a formatted static runtime information string.



317
318
319
# File 'lib/ollama_chat/information.rb', line 317

def static_runtime_information
  prompt(:static_runtime_info).to_s % static_runtime_information_values
end

#static_runtime_information_valuesHash

Generates a hash containing static runtime information.

This method collects session-level constants including the user, language preferences, location, client version, working directory, allowed tool paths, and available RAG collections.

Returns:

  • (Hash)

    a hash containing static runtime data.



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ollama_chat/information.rb', line 299

def static_runtime_information_values
  {
    client:               ,
    collections:          JSON.pretty_generate(config.embedding.collection_descriptions?),
    current_directory:    Pathname.pwd.expand_path.to_path,
    languages:            config.languages * ', ',
    location:             location.on?.full? { location_description } || 'n/a',
    tool_paths_allowed:   JSON.pretty_generate(tool_paths_allowed),
    user:                 ,
  }
end

#usageInteger

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

Returns:

  • (Integer)

    always returns 0 indicating successful help display



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/ollama_chat/information.rb', line 221

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

      -f CONFIG      config file to read
      -l SESSION     load session with name/id SESSION
      -n             create a new session
      -u URL         the ollama base url, OLLAMA_URL
      -m MODEL       the ollama model to chat with, OLLAMA_CHAT_MODEL, ?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

#userString

Retrieves the name of the chat user.

Returns:

  • (String)

    the chat user’s name or ‘n/a’ if not set



271
272
273
# File 'lib/ollama_chat/information.rb', line 271

def user
  user_name || 'n/a'
end

#user_nameString

Retrieves the name of the chat user.

Returns:

  • (String)

    the chat user’s name or nil if not set



278
279
280
# File 'lib/ollama_chat/information.rb', line 278

def user_name
  OC::OLLAMA::CHAT::USER
end

#versionInteger

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

Returns:

  • (Integer)

    returns 0 indicating successful execution



249
250
251
252
# File 'lib/ollama_chat/information.rb', line 249

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