Class: Kward::Compaction::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/compactor.rb

Overview

Interactive settings menu actions mixed into the CLI frontend.

Constant Summary collapse

DEFAULT_ENABLED =
true
DEFAULT_RESERVE_TOKENS =
16_384
DEFAULT_KEEP_RECENT_TOKENS =
20_000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: DEFAULT_ENABLED, reserve_tokens: DEFAULT_RESERVE_TOKENS, keep_recent_tokens: DEFAULT_KEEP_RECENT_TOKENS, context_window: nil) ⇒ Settings

Creates an object for conversation compaction.



48
49
50
51
52
53
# File 'lib/kward/compactor.rb', line 48

def initialize(enabled: DEFAULT_ENABLED, reserve_tokens: DEFAULT_RESERVE_TOKENS, keep_recent_tokens: DEFAULT_KEEP_RECENT_TOKENS, context_window: nil)
  @enabled = enabled != false
  @reserve_tokens = positive_integer(reserve_tokens, DEFAULT_RESERVE_TOKENS)
  @keep_recent_tokens = positive_integer(keep_recent_tokens, DEFAULT_KEEP_RECENT_TOKENS)
  @context_window = context_window.nil? ? nil : positive_integer(context_window, nil)
end

Instance Attribute Details

#context_windowObject (readonly)

Returns the value of attribute context_window.



45
46
47
# File 'lib/kward/compactor.rb', line 45

def context_window
  @context_window
end

#enabledObject (readonly)

Returns the value of attribute enabled.



45
46
47
# File 'lib/kward/compactor.rb', line 45

def enabled
  @enabled
end

#keep_recent_tokensObject (readonly)

Returns the value of attribute keep_recent_tokens.



45
46
47
# File 'lib/kward/compactor.rb', line 45

def keep_recent_tokens
  @keep_recent_tokens
end

#reserve_tokensObject (readonly)

Returns the value of attribute reserve_tokens.



45
46
47
# File 'lib/kward/compactor.rb', line 45

def reserve_tokens
  @reserve_tokens
end

Class Method Details

.from_config(config = ConfigFiles.read_config) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kward/compactor.rb', line 55

def self.from_config(config = ConfigFiles.read_config)
  values = config["compaction"].is_a?(Hash) ? config["compaction"] : {}
  new(
    enabled: values.key?("enabled") ? values["enabled"] : DEFAULT_ENABLED,
    reserve_tokens: values["reserve_tokens"] || values["reserveTokens"] || DEFAULT_RESERVE_TOKENS,
    keep_recent_tokens: values["keep_recent_tokens"] || values["keepRecentTokens"] || DEFAULT_KEEP_RECENT_TOKENS,
    context_window: values["context_window"] || values["contextWindow"]
  )
rescue StandardError
  new
end