Module: OllamaChat::Information
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.
Defined Under Namespace
Modules: UserAgent
Instance Method Summary collapse
-
#client ⇒ String
The client method returns the application name and its current version as a single string.
-
#collection_descriptions ⇒ Hash{String => String}
Retrieves a hash of collection names and their descriptions from the database.
-
#collection_stats(output: STDOUT) ⇒ Object
The collection_stats method displays statistics about the current document collection.
-
#context_filled ⇒ Float
Computes the fraction of the context window currently in use.
-
#context_usage ⇒ String?
Formats the current context usage as a human-readable string.
-
#current_context_length ⇒ Integer, NilClass
Resolves the effective context window size for the current model.
-
#display_chat_help(pattern = nil) ⇒ Object
The display_chat_help method outputs the chat help message to standard output, eventually using the configured pager.
-
#dynamic_runtime_information ⇒ String
The dynamic_runtime_information method generates a formatted string containing real-time environment details (the "heartbeat").
-
#dynamic_runtime_information_values ⇒ Hash
The dynamic_runtime_information_values method compiles a set of volatile runtime details that change frequently.
-
#info(output: STDOUT) ⇒ Object
Displays a high-level summary dashboard of the current state of the ollama_chat instance.
-
#info_model(output: STDOUT) ⇒ Object
Displays detailed information about the current chat model, including capabilities, families, and configuration options.
-
#info_rag(output: STDOUT) ⇒ Object
Displays information regarding the Retrieval Augmented Generation (RAG) configuration, including the embedding model and collection statistics.
-
#info_runtime(output: STDOUT) ⇒ Object
Displays the current runtime environment details, split into static (session-level) and dynamic (real-time) information.
-
#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.
-
#infobar_message ⇒ Hash
Returns the infobar message configuration as a hash.
-
#print_welcome(output: STDOUT) ⇒ Object
The print_welcome method prints a welcome message containing the application version, the connected ollama server version, and the server URL.
-
#server_url ⇒ String
The server_url method returns the base URL of the Ollama server connection.
-
#server_version ⇒ String
The server_version method retrieves the version of the Ollama server.
-
#static_runtime_information ⇒ String
Generates a formatted string of static runtime information.
-
#static_runtime_information_values ⇒ Hash
Generates a hash containing static runtime information.
-
#usage ⇒ Integer
The usage method displays the command-line idea help text and returns an exit code of 0.
-
#user ⇒ String
Retrieves the name of the chat user.
-
#user_name ⇒ String
Retrieves the name of the chat user.
-
#version ⇒ Integer
The version method outputs the program name and its version number to standard output.
Instance Method Details
#client ⇒ String
The client method returns the application name and its current version as a single string
62 63 64 |
# File 'lib/ollama_chat/information.rb', line 62 def client [ progname, OllamaChat::VERSION ] * ' ' end |
#collection_descriptions ⇒ Hash{String => String}
Retrieves a hash of collection names and their descriptions from the database.
This is used to provide context to the AI model about available RAG collections.
311 312 313 314 315 316 |
# File 'lib/ollama_chat/information.rb', line 311 def collection_descriptions cols = models::Collection.select(:name, :description).order(:name) cols.each_with_object({}) do |c, hash| hash[c.name] = c.description end 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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ollama_chat/information.rb', line 74 def collection_stats(output: STDOUT) col = database_collection?(collection) length = (Tins::Terminal.cols - 10).clamp(0..) = Kramdown::ANSI::Width. wrap(@documents..to_a.join(', '), length:). gsub(/(?<!\A)^/, ' ' * 4) output.puts <<~EOT Current Collection Name: #{bold{collection}} Patterns: #{italic{col&.patterns&.join(' ')}} #Embeddings: #{@documents.size} #Tags: #{@documents..size} Tags: #{} EOT nil end |
#context_filled ⇒ Float
Computes the fraction of the context window currently in use.
Divides the estimated token count of the session's messages by the effective context length, clamped to the range 0.0–1.0.
404 405 406 407 |
# File 'lib/ollama_chat/information.rb', line 404 def context_filled es = session.estimate_tokens (es.tokens.to_f / current_context_length).clamp(0..1).to_f end |
#context_usage ⇒ String?
Formats the current context usage as a human-readable string.
Returns a string like "167.7 KT of 262.1 KT (64.0%)" combining
the estimated tokens in use, the effective context length, and
the percentage (via context_filled).
417 418 419 420 421 422 423 424 425 |
# File 'lib/ollama_chat/information.rb', line 417 def context_usage if cl = current_context_length '%s of %s (%s)' % [ session.estimate_tokens.tokens_formatted, format_tokens(current_context_length), '%.1f%%' % (100 * context_filled), ] end end |
#current_context_length ⇒ Integer, NilClass
Resolves the effective context window size for the current model.
Prefers the session-level num_ctx override (set via /model_options
or the stored model options profile). Falls back to the model's native
context_length in the default profile or as reported by the Ollama server
if possible.
392 393 394 395 396 |
# File 'lib/ollama_chat/information.rb', line 392 def current_context_length [:num_ctx] || (@model)[:num_ctx] || ollama.ps&.models&.find { _1.name == @model }&.context_length end |
#display_chat_help(pattern = nil) ⇒ Object
The display_chat_help method outputs the chat help message to standard output, eventually using the configured pager.
226 227 228 229 230 231 |
# File 'lib/ollama_chat/information.rb', line 226 def display_chat_help(pattern = nil) use_pager do |output| output.puts (pattern) end nil end |
#dynamic_runtime_information ⇒ String
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.
380 381 382 |
# File 'lib/ollama_chat/information.rb', line 380 def dynamic_runtime_information prompt(:dynamic_runtime_info).to_s % dynamic_runtime_information_values end |
#dynamic_runtime_information_values ⇒ Hash
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.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/ollama_chat/information.rb', line 354 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', git_sha: `git rev-parse HEAD 2>/dev/null`.chomp.full? || 'n/a', git_sha_short: `git rev-parse --short HEAD 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'), context_usage: , } end |
#info(output: STDOUT) ⇒ Object
Displays a high-level summary dashboard of the current state of the ollama_chat instance.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ollama_chat/information.rb', line 204 def info(output: STDOUT) print_welcome(output:) 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ollama_chat/information.rb', line 97 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.)} EOT end elsif config.model..full? output.puts " Default Options: #{JSON.pretty_generate(mo).gsub(/(?<!\A)^/, ' ')}" end if .present? output.puts " Session Options: #{JSON.pretty_generate().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.
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ollama_chat/information.rb', line 175 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..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.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ollama_chat/information.rb', line 160 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.
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 125 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}}." context_usage = '%s of %s (%s)' % [ session.estimate_tokens.tokens_formatted, format_tokens(current_context_length), bold { '%.1f%%' % (100 * context_filled)}, ] output.puts " Context Length: #{context_usage}" 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 "\u2699\uFE0F 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:) output.print ' '; context_format.show(output:) end |
#infobar_message ⇒ Hash
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.
299 300 301 |
# File 'lib/ollama_chat/information.rb', line 299 def config...to_h end |
#print_welcome(output: STDOUT) ⇒ Object
The print_welcome method prints a welcome message containing the application version, the connected ollama server version, and the server URL.
194 195 196 197 |
# File 'lib/ollama_chat/information.rb', line 194 def print_welcome(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}}" end |
#server_url ⇒ String
The server_url method returns the base URL of the Ollama server connection.
275 276 277 |
# File 'lib/ollama_chat/information.rb', line 275 def server_url @server_url ||= ollama.base_url end |
#server_version ⇒ String
The server_version method retrieves the version of the Ollama server.
268 269 270 |
# File 'lib/ollama_chat/information.rb', line 268 def server_version @server_version ||= ollama.version.version end |
#static_runtime_information ⇒ String
Generates a formatted string of static runtime information.
This method interpolates the static runtime values into the
configured static_runtime_info prompt template.
343 344 345 |
# File 'lib/ollama_chat/information.rb', line 343 def static_runtime_information prompt(:static_runtime_info).to_s % static_runtime_information_values end |
#static_runtime_information_values ⇒ Hash
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.
325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/ollama_chat/information.rb', line 325 def static_runtime_information_values { client: , collections: JSON.pretty_generate(collection_descriptions), current_directory: Pathname.pwd..to_path, languages: config.languages * ', ', location: location.on?.full? { location_description } || 'n/a', tool_paths_allowed: JSON.pretty_generate(tool_paths_allowed), user: , } end |
#usage ⇒ Integer
The usage method displays the command-line idea help text and returns an exit code of 0.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/ollama_chat/information.rb', line 237 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 chat model, OLLAMA_CHAT_MODEL, ?selector -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 `-l` to filter options. Multiple matches will open a chooser dialog. EOT 0 end |
#user ⇒ String
Retrieves the name of the chat user.
282 283 284 |
# File 'lib/ollama_chat/information.rb', line 282 def user user_name || 'n/a' end |
#user_name ⇒ String
Retrieves the name of the chat user.
289 290 291 |
# File 'lib/ollama_chat/information.rb', line 289 def user_name OC::OLLAMA::CHAT::USER end |
#version ⇒ Integer
The version method outputs the program name and its version number to standard output.
260 261 262 263 |
# File 'lib/ollama_chat/information.rb', line 260 def version STDOUT.puts "%s %s" % [ progname, OllamaChat::VERSION ] 0 end |