| 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
| |||||||||||||||||||||||||||||
| 29 | 16 | ▶ | return {} unless $self->has_worker_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | return { output_hidden_states => JSON::MaybeXS::true() } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $v eq "HASH" or ref $v eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | 4 | my $encoded = $self->_encode_xargs($xargs); | |||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $per_call = $extra{vllm_xargs} // {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$extra{"vllm_xargs"} // {}
MC/DC0%0/1
$extra{"vllm_xargs"} // {}
$extra{"vllm_xargs"}
Truth table50%1/2
A
A= $extra{"vllm_xargs"}
| |||||||||||||||||||||||||||||
| 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 // {}
MC/DC0%0/1
$resp->raw // {}
$resp->raw
Truth table50%1/2
A
A= $resp->raw
| |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if ( defined $raw->{probes} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||