| 1 | package Langertha::PromptCache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Immutable prompt-caching request control with cross-provider conversion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 171 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 171 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 171 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 171 | has enable => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | has ttl => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 19 | ▶ | default => sub { undef }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 171 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | has key => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | default => sub { undef }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 171 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | sub to_anthropic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_anthropic: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_anthropic: not called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return () unless $self->enable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | cache_control => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | type => 'ephemeral', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ( defined $self->ttl ? ( ttl => $self->ttl ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | sub to_openai { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_openai: called CC=3 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_openai: not called CC=3 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return () unless defined $self->key && length $self->key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition16%1/6
defined $self->key and length $self->key
defined $self->key and length $self->key
MC/DC0%0/2
defined $self->key and length $self->key
defined $self->key
length $self->key
MC/DC0%0/2
defined $self->key and length $self->key
defined $self->key
length $self->key
Truth table33%1/3
A and B
A= defined $self->keyB= length $self->key
Truth table0%0/3
A and B
A= defined $self->keyB= length $self->key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return ( prompt_cache_key => $self->key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Maps a cache_wire_format tag to the per-format serializer method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 171 | my %TO_METHOD = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | openai => 'to_openai', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | anthropic => 'to_anthropic', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | sub to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to: called CC=4 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my ( $self, $fmt ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to: not called CC=4 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $method = $TO_METHOD{ $fmt // '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition12%1/8
$fmt // ""
$fmt // ""
$fmt // ""
$fmt // ""
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
Truth table50%1/2
A
A= $fmt
Truth table0%0/2
A
A= $fmt
Truth table0%0/2
A
A= $fmt
Truth table0%0/2
A
A= $fmt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | or croak "Langertha::PromptCache: unknown cache wire format '" . ( $fmt // '' ) . "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return $self->$method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 171 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 171 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||