blib/lib/Langertha/Role/ResponseSize.pm

filter: Statementstmt 79.3% 23 / 29 Branchbran 65.0% 13 / 20 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 80.0% 4 / 5 Podpod 100% 3 / 3 totaltotal 72.3% 47 / 65 CC 19 SCAR 18.3
CC
19
Cov
72%
_model_response_size_default
7.1
_model_response_size_default
7.1
get_response_size
6.0
CRAP 6.2
« blib/lib/Langertha/Runtime/Metrics.pm ↑ Summary blib/lib/Langertha/PromptCache.pm »
1 package Langertha::Role::ResponseSize;
2 # ABSTRACT: Role for an engine where you can specify the response size (in tokens)
3 193 our $VERSION = '0.505';
4 193 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 193 has response_size => (
7 isa => 'Int',
8 is => 'ro',
9 predicate => 'has_response_size',
10 );
11  
12  
13 4114 ▶sub get_response_size {
Subroutine get_response_size: called CC=4 SCAR=17.9
Pod documented
14 0 ▶ my ( $self ) = @_;
Subroutine get_response_size: not called CC=4 SCAR=17.9
Pod documented
15 0 ▶ return $self->response_size if $self->has_response_size;
Branch: 2 branches
BranchTrueFalseTotal
if $self->has_response_size 159 3955 4114
if $self->has_response_size 0 0 0
16 0 my $model_default = $self->_model_response_size_default;
17 0 ▶ return $model_default if defined $model_default;
Branch: 2 branches
BranchTrueFalseTotal
if defined $model_default 461 3494 3955
if defined $model_default 0 0 0
18 0 ▶ return $self->default_response_size if $self->can('default_response_size');
Branch: 2 branches
BranchTrueFalseTotal
if $self->can("default_response_size") 1335 2159 3494
if $self->can("default_response_size") 0 0 0
19 0 return;
20 }
21  
22  
23 # Default: no per-model defaults. Engines override with an ordered list of
24 # ( $matcher => $tokens ) pairs, matched against chat_model like
25 # Role::Capabilities' model_capability_corrections (ADR 0019 k225 Update).
26 3442 ▶sub model_response_size_defaults { return () }
Subroutine model_response_size_defaults: called CC=1 SCAR=0.0
Pod documented
27  
28 3955 ▶sub _model_response_size_default {
Subroutine _model_response_size_default: called CC=7 SCAR=19.6
29 3955 my ( $self ) = @_;
30 3955 my @defaults = $self->model_response_size_defaults;
31 3955 ▶ return unless @defaults && $self->can('chat_model');
Branch: 1 branch
BranchTrueFalseTotal
unless @defaults and $self->can("chat_model") 3442 513 3955
Condition66%2/3
@defaults and $self->can("chat_model")
!ll&&!rl&&r
34420513
MC/DC50%1/2
@defaults and $self->can("chat_model")
@defaults $self->can("chat_model")
Truth table66%2/3
A and B
A= @defaultsB= $self->can("chat_model")
ABresult
0X0
100
111
32 513 ▶ my $model = $self->chat_model // '';
Condition50%1/2
$self->chat_model // ""
l!l
5130
MC/DC0%0/1
$self->chat_model // ""
$self->chat_model
Truth table50%1/2
A
A= $self->chat_model
Aresult
11
00
33 513 my $size;
34 513 ▶ while ( @defaults >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@defaults >= 2) 1026 513 1539
35 1026 my ( $matcher, $tokens ) = splice @defaults, 0, 2;
36 1026 ▶ my $hit = ref $matcher eq 'Regexp' ? ( $model =~ $matcher )
Branch: 1 branch
BranchTrueFalseTotal
ref $matcher eq 'Regexp' ? : 1026 0 1026
37 : ( $model eq $matcher );
38 1026 ▶ $size = $tokens if $hit; # later matching entries win
Branch: 1 branch
BranchTrueFalseTotal
if $hit 461 565 1026
39 }
40 513 return $size;
41 }
42  
43  
44  
45 193 1;
46  
47 __END__
« blib/lib/Langertha/Runtime/Metrics.pm ↑ Summary blib/lib/Langertha/PromptCache.pm »