Class: Kward::Compaction::Settings

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

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

Returns a new instance of Settings.



36
37
38
39
40
41
# File 'lib/kward/compactor.rb', line 36

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.



34
35
36
# File 'lib/kward/compactor.rb', line 34

def context_window
  @context_window
end

#enabledObject (readonly)

Returns the value of attribute enabled.



34
35
36
# File 'lib/kward/compactor.rb', line 34

def enabled
  @enabled
end

#keep_recent_tokensObject (readonly)

Returns the value of attribute keep_recent_tokens.



34
35
36
# File 'lib/kward/compactor.rb', line 34

def keep_recent_tokens
  @keep_recent_tokens
end

#reserve_tokensObject (readonly)

Returns the value of attribute reserve_tokens.



34
35
36
# File 'lib/kward/compactor.rb', line 34

def reserve_tokens
  @reserve_tokens
end

Class Method Details

.from_config(config = ConfigFiles.read_config) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kward/compactor.rb', line 43

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