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

#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



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

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



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

def collection_stats(output: STDOUT)
  output.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, evenutally using the configured pager.

Returns:

  • (nil)

    This method always returns nil after printing the help message.



140
141
142
143
144
145
# File 'lib/ollama_chat/information.rb', line 140

def display_chat_help
  use_pager do |output|
    output.puts help_message
  end
  nil
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.

Returns:

  • (nil)

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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ollama_chat/information.rb', line 93

def info
  use_pager do |output|
    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 "Current conversation model is #{bold{@model}}."
    output.puts   "  Capabilities: #{Array(@model_metadata&.capabilities) * ', '}"
    if @model_options.present?
      output.puts "  Options: #{JSON.pretty_generate(@model_options).gsub(/(?<!\A)^/, '  ')}"
    end
    @embedding.show(output:)
    if @embedding.on?
      output.puts "Current embedding 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
    markdown.show(output:)
    stream.show(output:)
    think_mode.show(output:)
    think_loud.show(output:)
    location.show(output:)
    voice.show(output:)
    @voice.on? and @voices.show(output:)
    if runtime_info.on?
      output.puts "Runtime Information:"
      output.puts runtime_information_values.transform_keys(&:to_s).to_yaml.
        sub(/\A---\s*\n/, '').gsub(/^/, '  ')
    else
      runtime_info.show(output:)
    end
    tools_support.show(output:)
    output.puts "Documents database cache is #{@documents.nil? ? 'n/a' : bold{@documents.cache.class}}"
    output.puts "Document policy for references in user text: #{bold{document_policy}}"
    output.puts "Currently selected search engine is #{bold(search_engine)}."
    name = default_persona_name and output.puts "Default persona: #{bold{name}}"
    output.puts "Conversation length: #{bold(@messages.size.to_s)} message(s)."
  end
  nil
end

#runtime_informationString

The runtime_information method generates a formatted string containing various runtime values such as languages, location description, git branch and origin, client agent, current directory, terminal size, time, voice and markdown status, and allowed tool paths. It returns the result of interpolating these values into the configured runtime_info prompt template.

Returns:

  • (String)

    the formatted runtime information string.



231
232
233
# File 'lib/ollama_chat/information.rb', line 231

def runtime_information
  config.prompts.runtime_info % runtime_information_values
end

#runtime_information_valuesHash

The runtime_information_values method compiles a set of key runtime details such as languages, location description, default persona name, current git branch and remote origin, client agent string, current directory, terminal dimensions, timestamp, voice and markdown status, and allowed tool paths.

Returns:

  • (Hash)

    a hash containing runtime information values.



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/ollama_chat/information.rb', line 204

def runtime_information_values
  {
    user:                 OC::OLLAMA::CHAT::USER || 'n/a',
    languages:            config.languages * ', ',
    time:                 Time.now.iso8601,
    location:             location.on?.full? { location_description } || 'n/a',
    default_persona:      default_persona_name.full? || 'n/a',
    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',
    client:               ,
    current_directory:    Pathname.pwd.expand_path.to_path,
    terminal_rows:        Tins::Terminal.rows,
    terminal_cols:        Tins::Terminal.cols,
    voice:                voice.on? ? 'enabled' : 'disabled',
    markdown:             markdown.on? ? 'enabled' : 'disabled',
    tool_paths_allowed:   JSON.pretty_generate(tool_paths_allowed),
  }
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



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

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



187
188
189
# File 'lib/ollama_chat/information.rb', line 187

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



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/ollama_chat/information.rb', line 151

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
      -p PERSONA     load a persona via name/file for roleplay at startup
      -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



179
180
181
182
# File 'lib/ollama_chat/information.rb', line 179

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