blib/lib/Langertha/Role/RuntimeKnobs.pm

filter: Statementstmt 87.8% 29 / 33 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 87.2% 41 / 47 CC 5 SCAR 11.6
CC
5
Cov
90%
knobs_kwargs_for
5.0
_build_knob_wire_format
2.0
knobs_kwargs
2.0
CRAP 3.2
« blib/lib/Langertha/Role/KeepAlive.pm ↑ Summary blib/lib/Langertha/ImageGen.pm »
1 package Langertha::Role::RuntimeKnobs;
2 # ABSTRACT: Role for a self-hosted engine with per-request prefix-cache runtime knobs
3 39 our $VERSION = '0.505';
4 39 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use Langertha::Runtime::Knobs;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 has prefix_cache_salt => (
9 is => 'ro',
10 isa => 'Str',
11 predicate => 'has_prefix_cache_salt',
12 );
13  
14  
15 39 has cache_prompt => (
16 is => 'ro',
17 isa => 'Bool',
18 predicate => 'has_cache_prompt',
19 );
20  
21  
22 39 has n_cache_reuse => (
23 is => 'ro',
24 isa => 'Int',
25 predicate => 'has_n_cache_reuse',
26 );
27  
28  
29 39 has id_slot => (
30 is => 'ro',
31 isa => 'Int',
32 predicate => 'has_id_slot',
33 );
34  
35  
36 39 has priority => (
37 is => 'ro',
38 isa => 'Int',
39 predicate => 'has_priority',
40 );
41  
42  
43 39 has return_cached_tokens_details => (
44 is => 'ro',
45 isa => 'Bool',
46 predicate => 'has_return_cached_tokens_details',
47 );
48  
49  
50 39 has extra_key => (
51 is => 'ro',
52 isa => 'Str',
53 predicate => 'has_extra_key',
54 );
55  
56  
57 39 has knob_wire_format => (
58 is => 'ro',
59 isa => 'Str',
60 lazy => 1,
61 builder => '_build_knob_wire_format',
62 );
63  
64 # No shared default exists — an 'openai' knob dialect does not exist (the
65 # self-hosted servers each speak their own field set), so every engine that
66 # composes this role must set its tag explicitly. Engines override the builder
67 # (sub _build_knob_wire_format { 'vllm' }) — the codebase convention for
68 # wire-format tags (cf. _build_tool_wire_format).
69 0 ▶sub _build_knob_wire_format {
Subroutine _build_knob_wire_format: not called CC=1 SCAR=6.9
70 0 my ( $self ) = @_;
71 0 croak ref($self) . " composes Langertha::Role::RuntimeKnobs but does not set "
72 . "knob_wire_format — there is no shared default (an 'openai' knob dialect "
73 . "does not exist); set it explicitly (vllm | sglang | llamacpp)";
74 }
75  
76  
77 39 my @KNOBS = qw(
78 prefix_cache_salt
79 cache_prompt
80 n_cache_reuse
81 id_slot
82 priority
83 return_cached_tokens_details
84 extra_key
85 );
86  
87 264 ▶sub knobs_kwargs_for {
Subroutine knobs_kwargs_for: called CC=5 SCAR=16.1
Pod documented
88 264 my ( $self, %args ) = @_;
89  
90 # Per-request controls (chat_f, karr #46) beat the engine attributes on a
91 # per-key basis: %args may carry any of the canonical knob names (the same
92 # names as the attributes — there is no separate alias vocabulary), and any
93 # key it does not carry falls back to the configured attribute.
94 264 my %merged;
95 264 for my $knob (@KNOBS) {
96 1848 my $has = "has_$knob";
97 1848 ▶ $merged{$knob} = $self->$knob if $self->$has;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$has 9 1839 1848
98 1848 ▶ $merged{$knob} = $args{$knob} if exists $args{$knob};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$knob} 4 1844 1848
99 }
100 264 ▶ return () unless %merged;
Branch: 1 branch
BranchTrueFalseTotal
unless %merged 258 6 264
101 return Langertha::Runtime::Knobs->new(
102 6 map { $_ => $merged{$_} } keys %merged,
103 )->to( $self->knob_wire_format );
104 }
105  
106  
107 0 ▶sub knobs_kwargs {
Subroutine knobs_kwargs: not called CC=1 SCAR=6.9
Pod documented
108 0 my ( $self ) = @_;
109 0 return $self->knobs_kwargs_for;
110 }
111  
112  
113  
114 39 1;
115  
116 __END__
« blib/lib/Langertha/Role/KeepAlive.pm ↑ Summary blib/lib/Langertha/ImageGen.pm »