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 =

Returns Supported context truncation strategy names.

Returns:

  • (Array)

    Supported context truncation strategy names.

['tail', 'head', 'middle'].freeze
DEFAULT_MAX_TOKENS =

Returns Default maximum token budget.

Returns:

  • (Object)

    Default maximum token budget.

200_000
DEFAULT_RESERVE =

Returns Default token reserve for response generation.

Returns:

  • (Integer)

    Default token reserve for response generation.

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')


25
26
27
28
29
30
31
32
# File 'lib/rosett_ai/ai_config/context_window.rb', line 25

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.



20
21
22
# File 'lib/rosett_ai/ai_config/context_window.rb', line 20

def max_tokens
  @max_tokens
end

#output_reserveObject (readonly)

Returns the value of attribute output_reserve.



20
21
22
# File 'lib/rosett_ai/ai_config/context_window.rb', line 20

def output_reserve
  @output_reserve
end

#truncation_strategyObject (readonly)

Returns the value of attribute truncation_strategy.



20
21
22
# File 'lib/rosett_ai/ai_config/context_window.rb', line 20

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)



35
36
37
# File 'lib/rosett_ai/ai_config/context_window.rb', line 35

def effective_input_tokens
  @max_tokens - @output_reserve
end

#to_hHash

Returns serializable representation.

Returns:

  • (Hash)

    serializable representation



40
41
42
43
44
45
46
# File 'lib/rosett_ai/ai_config/context_window.rb', line 40

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