blib/lib/Langertha/Role/PromptCache.pm

filter: Statementstmt 66.6% 18 / 27 Branchbran 50.0% 12 / 24 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 57.1% 4 / 7 Podpod 100% 4 / 4 totaltotal 59.7% 43 / 72 CC 15 SCAR 25.3
CC
15
Cov
58%
prompt_cache_kwargs_for
16.0
prompt_cache_kwargs_for
16.0
prompt_cache_kwargs
2.0
CRAP 12.5
« blib/lib/Langertha/RateLimit.pm ↑ Summary blib/lib/Langertha/HTTP/BoundedDecode.pm »
1 package Langertha::Role::PromptCache;
2 # ABSTRACT: Role for an engine with a request-side prompt-caching control
3 171 our $VERSION = '0.505';
4 171 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 171 ▶use Langertha::PromptCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 171 has prompt_cache => (
8 is => 'ro',
9 isa => 'Bool',
10 default => 0,
11 );
12  
13  
14 171 has prompt_cache_ttl => (
15 is => 'ro',
16 isa => 'Str',
17 predicate => 'has_prompt_cache_ttl',
18 );
19  
20  
21 171 has prompt_cache_key => (
22 is => 'ro',
23 isa => 'Str',
24 predicate => 'has_prompt_cache_key',
25 );
26  
27  
28 171 has cache_wire_format => (
29 is => 'ro',
30 isa => 'Str',
31 lazy => 1,
32 builder => '_build_cache_wire_format',
33 );
34  
35 # Defaults to the OpenAI dialect; AnthropicBase overrides the builder. This role
36 # is composed only on OpenAIBase and AnthropicBase (the two providers with a
37 # real request-side knob), so those are the only two formats.
38 9 ▶sub _build_cache_wire_format { 'openai' }
Subroutine _build_cache_wire_format: called CC=1 SCAR=0.0
39  
40  
41 2374 ▶sub prompt_cache_kwargs_for {
Subroutine prompt_cache_kwargs_for: called CC=8 SCAR=27.7
Pod documented
42 0 ▶ my ( $self, %args ) = @_;
Subroutine prompt_cache_kwargs_for: not called CC=8 SCAR=27.7
Pod documented
43  
44 # Per-request controls (chat_f, karr #46) beat the engine attributes on a
45 # per-key basis: %args may carry prompt_cache / prompt_cache_ttl /
46 # prompt_cache_key, and any key it does not carry falls back to the
47 # configured attribute.
48 0 ▶ my %merged = (
Branch: 4 branches
BranchTrueFalseTotal
$self->has_prompt_cache_ttl ? : 1 2373 2374
$self->has_prompt_cache_key ? : 20 2354 2374
$self->has_prompt_cache_ttl ? : 0 0 0
$self->has_prompt_cache_key ? : 0 0 0
49 ( prompt_cache => $self->prompt_cache ),
50 ( $self->has_prompt_cache_ttl ? ( prompt_cache_ttl => $self->prompt_cache_ttl ) : () ),
51 ( $self->has_prompt_cache_key ? ( prompt_cache_key => $self->prompt_cache_key ) : () ),
52 %args,
53 );
54 # The wire agrees with the capability registry for the routing key (karr
55 # #200, ADR 0009): an engine that clears prompt_cache_key does not send it.
56 # prompt_cache is deliberately not gated -- the family-wide flag would drop
57 # cache_control under an explicit cache_wire_format => 'anthropic' override.
58 0 ▶ delete $merged{prompt_cache_key} unless $self->supports('prompt_cache_key');
Branch: 2 branches
BranchTrueFalseTotal
unless $self->supports("prompt_cache_key") 951 1423 2374
unless $self->supports("prompt_cache_key") 0 0 0
59 0 ▶ return () unless $merged{prompt_cache} || defined $merged{prompt_cache_key};
Branch: 2 branches
BranchTrueFalseTotal
unless $merged{"prompt_cache"} or defined $merged{"prompt_cache_key"} 2354 20 2374
unless $merged{"prompt_cache"} or defined $merged{"prompt_cache_key"} 0 0 0
Condition50%3/6
$merged{"prompt_cache"} or defined $merged{"prompt_cache_key"}
l!l&&r!l&&!r
9112354
$merged{"prompt_cache"} or defined $merged{"prompt_cache_key"}
l!l&&r!l&&!r
000
MC/DC100%2/2
$merged{"prompt_cache"} or defined $merged{"prompt_cache_key"}
$merged{"prompt_cache"} defined $merged{"prompt_cache_key"}
MC/DC0%0/2
$merged{"prompt_cache"} or defined $merged{"prompt_cache_key"}
$merged{"prompt_cache"} defined $merged{"prompt_cache_key"}
Truth table100%3/3
A or B
A= $merged{"prompt_cache"}B= defined $merged{"prompt_cache_key"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $merged{"prompt_cache"}B= defined $merged{"prompt_cache_key"}
ABresult
1X1
011
000
60 return Langertha::PromptCache->new(
61 enable => $merged{prompt_cache},
62 ( defined $merged{prompt_cache_ttl} ? ( ttl => $merged{prompt_cache_ttl} ) : () ),
63 0 ▶ ( defined $merged{prompt_cache_key} ? ( key => $merged{prompt_cache_key} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $merged{'prompt_cache_ttl'} ? : 1 19 20
defined $merged{'prompt_cache_key'} ? : 11 9 20
defined $merged{'prompt_cache_ttl'} ? : 0 0 0
defined $merged{'prompt_cache_key'} ? : 0 0 0
64 )->to( $self->cache_wire_format );
65 }
66  
67  
68 0 ▶sub prompt_cache_kwargs {
Subroutine prompt_cache_kwargs: not called CC=1 SCAR=6.9
Pod documented
69 0 ▶ my ( $self ) = @_;
Subroutine prompt_cache_kwargs: not called CC=1 SCAR=6.9
Pod documented
70 0 return $self->prompt_cache_kwargs_for;
71 }
72  
73  
74  
75 171 1;
76  
77 __END__
« blib/lib/Langertha/RateLimit.pm ↑ Summary blib/lib/Langertha/HTTP/BoundedDecode.pm »