Class: RosettAi::AiConfig::ContextWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/ai_config/context_window.rb

Overview

Manages context window configuration settings.

Tracks max tokens, output reserve, and truncation strategy for compilation into engine-native settings.

Constant Summary collapse

TRUNCATION_STRATEGIES =
['tail', 'head', 'middle'].freeze
DEFAULT_MAX_TOKENS =
200_000
DEFAULT_RESERVE =
8192

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_tokens: DEFAULT_MAX_TOKENS, output_reserve: DEFAULT_RESERVE, truncation_strategy: 'tail') ⇒ ContextWindow

Returns a new instance of ContextWindow.

Parameters:

  • max_tokens (Integer) (defaults to: DEFAULT_MAX_TOKENS)

    maximum context window tokens

  • output_reserve (Integer) (defaults to: DEFAULT_RESERVE)

    tokens reserved for output

  • truncation_strategy (String) (defaults to: 'tail')


22
23
24
25
26
27
28
29
# File 'lib/rosett_ai/ai_config/context_window.rb', line 22

def initialize(max_tokens: DEFAULT_MAX_TOKENS, output_reserve: DEFAULT_RESERVE,
               truncation_strategy: 'tail')
  validate_strategy!(truncation_strategy)

  @max_tokens = max_tokens
  @output_reserve = output_reserve
  @truncation_strategy = truncation_strategy.freeze
end

Instance Attribute Details

#max_tokensObject (readonly)

Returns the value of attribute max_tokens.



17
18
19
# File 'lib/rosett_ai/ai_config/context_window.rb', line 17

def max_tokens
  @max_tokens
end

#output_reserveObject (readonly)

Returns the value of attribute output_reserve.



17
18
19
# File 'lib/rosett_ai/ai_config/context_window.rb', line 17

def output_reserve
  @output_reserve
end

#truncation_strategyObject (readonly)

Returns the value of attribute truncation_strategy.



17
18
19
# File 'lib/rosett_ai/ai_config/context_window.rb', line 17

def truncation_strategy
  @truncation_strategy
end

Instance Method Details

#effective_input_tokensInteger

Returns effective input tokens (max minus reserve).

Returns:

  • (Integer)

    effective input tokens (max minus reserve)



32
33
34
# File 'lib/rosett_ai/ai_config/context_window.rb', line 32

def effective_input_tokens
  @max_tokens - @output_reserve
end

#to_hHash

Returns serializable representation.

Returns:

  • (Hash)

    serializable representation



37
38
39
40
41
42
43
# File 'lib/rosett_ai/ai_config/context_window.rb', line 37

def to_h
  {
    'max_tokens' => @max_tokens,
    'output_reserve' => @output_reserve,
    'truncation_strategy' => @truncation_strategy
  }
end