blib/lib/Langertha/Engine/VLLMHook.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 91.6% 11 / 12 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 88.7% 63 / 71 CC 11 SCAR 11.4
CC
11
Cov
92%
resolved_xargs
4.1
_encode_xargs
4.0
__ANON__
3.0
CRAP 3.1
« blib/lib/Langertha/Embedder.pm ↑ Summary blib/lib/Langertha/Manifest/Model.pm »
1 package Langertha::Engine::VLLMHook;
2 # ABSTRACT: vLLM inference server with vLLM-Hook probe capture
3 13 our $VERSION = '0.505';
4 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 extends 'Langertha::Engine::vLLM';
8  
9  
10 has vllm_xargs => (
11 is => 'ro',
12 isa => 'HashRef',
13 37 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 13 );
15  
16  
17 13 has worker_name => (
18 is => 'ro',
19 isa => 'Str',
20 predicate => 'has_worker_name',
21 );
22  
23  
24  
25 20 ▶sub resolved_xargs {
Subroutine resolved_xargs: called CC=4 SCAR=14.0
Pod documented
26 20 my ( $self ) = @_;
27 20 my $xargs = $self->vllm_xargs;
28 20 ▶ return $xargs if keys %$xargs;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$xargs 4 16 20
29 16 ▶ return {} unless $self->has_worker_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_worker_name 15 1 16
30 1 ▶ return { output_hidden_states => JSON::MaybeXS::true() }
Branch: 1 branch
BranchTrueFalseTotal
if $self->worker_name eq "hidden_states" 1 0 1
31 if $self->worker_name eq 'hidden_states';
32 0 return {};
33 }
34  
35  
36 4 ▶sub _encode_xargs {
Subroutine _encode_xargs: called CC=4 SCAR=13.9
37 4 my ( $self, $xargs ) = @_;
38 4 my %out;
39 4 for my $k ( keys %$xargs ) {
40 5 my $v = $xargs->{$k};
41 5 ▶ $out{$k} = ( ref $v eq 'HASH' || ref $v eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'HASH' || ref $v eq 'ARRAY' ? : 3 2 5
Condition66%2/3
ref $v eq "HASH" or ref $v eq "ARRAY"
l!l&&r!l&&!r
302
MC/DC50%1/2
ref $v eq "HASH" or ref $v eq "ARRAY"
ref $v eq "HASH" ref $v eq "ARRAY"
Truth table66%2/3
A or B
A= ref $v eq "HASH"B= ref $v eq "ARRAY"
ABresult
1X1
011
000
42 ? $self->encode_json_text($v)
43 : $v;
44 }
45 4 return \%out;
46 }
47  
48 19 ▶around 'chat_request' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
49 19 my ( $orig, $self, $messages, %extra ) = @_;
50 19 my $xargs = $self->resolved_xargs;
51 19 ▶ if ( keys %$xargs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$xargs) 4 15 19
52 4 my $encoded = $self->_encode_xargs($xargs);
53 4 ▶ my $per_call = $extra{vllm_xargs} // {};
Condition50%1/2
$extra{"vllm_xargs"} // {}
l!l
04
MC/DC0%0/1
$extra{"vllm_xargs"} // {}
$extra{"vllm_xargs"}
Truth table50%1/2
A
A= $extra{"vllm_xargs"}
Aresult
11
00
54 4 $extra{vllm_xargs} = { %$encoded, %$per_call };
55 }
56 19 return $self->$orig( $messages, %extra );
57 13 };
58  
59  
60 3 ▶around 'chat_response' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
61 3 my ( $orig, $self, $http_response ) = @_;
62 3 my $resp = $self->$orig($http_response);
63 3 ▶ my $raw = $resp->raw // {};
Condition50%1/2
$resp->raw // {}
l!l
30
MC/DC0%0/1
$resp->raw // {}
$resp->raw
Truth table50%1/2
A
A= $resp->raw
Aresult
11
00
64 3 ▶ if ( defined $raw->{probes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$raw{"probes"}) 1 2 3
65 1 $resp = $resp->clone_with( probes => $raw->{probes} );
66 }
67 3 return $resp;
68 13 };
69  
70  
71 13 __PACKAGE__->meta->make_immutable;
72  
73  
74 13 1;
75  
76 __END__
« blib/lib/Langertha/Embedder.pm ↑ Summary blib/lib/Langertha/Manifest/Model.pm »