API/Response.pm

filter: Statementstmt 48.2% 28 / 58 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.0% 8 / 17 Podpod 11.1% 1 / 9 totaltotal 42.0% 37 / 88 CC 4 SCAR 12.5
CC
4
Cov
45%
init
12.0
error
6.0
new
2.0
CRAP 3.5
« API/Content.pm ↑ Summary API/Usage.pm »
1 package LLM::API::Response;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use LLM::API::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LLM::API::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our @ACCESSORS = qw(
14 content
15 decoded_content
16 id
17 model
18 raw_response
19 role
20 stop_reason
21 stop_sequence
22 type
23 usage
24 );
25  
26 1 __PACKAGE__->mk_accessors(@ACCESSORS);
27  
28 1 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 our $VERSION = '1.0.0';
31  
32 ########################################################################
33 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
34 ########################################################################
35 0 my ( $class, $raw_response ) = @_;
36  
37 0 my $self = $class->SUPER::new( { raw_response => $raw_response } );
38  
39 0 $self->init;
40  
41 0 return $self;
42 }
43  
44 ########################################################################
45 0 ▶sub is_success {
Subroutine is_success: not called CC=1 SCAR=6.9
Pod undocumented
46 ########################################################################
47 0 my ($self) = @_;
48  
49 0 return $self->raw_response->{success};
50 }
51  
52 ########################################################################
53 0 ▶sub status {
Subroutine status: not called CC=1 SCAR=6.9
Pod undocumented
54 ########################################################################
55 0 my ($self) = @_;
56  
57 0 return $self->raw_response->{status};
58 }
59  
60 ########################################################################
61 0 ▶sub reason {
Subroutine reason: not called CC=1 SCAR=6.9
Pod undocumented
62 ########################################################################
63 0 my ($self) = @_;
64  
65 0 return $self->raw_response->{reason};
66 }
67  
68 ########################################################################
69 0 ▶sub code {
Subroutine code: not called CC=1 SCAR=6.9
Pod undocumented
70 ########################################################################
71 0 my ($self) = @_;
72  
73 0 return $self->raw_response->{code};
74 }
75  
76 ########################################################################
77 0 ▶sub raw_content {
Subroutine raw_content: not called CC=1 SCAR=6.9
Pod undocumented
78 ########################################################################
79 0 my ($self) = @_;
80  
81 0 return $self->raw_response->{content};
82 }
83  
84 ########################################################################
85 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod undocumented
86 ########################################################################
87 0 my ($self) = @_;
88  
89 0 my $rsp = $self->raw_response;
90  
91 return q{}
92 0 ▶ if $rsp->{success};
Branch: 1 branch
BranchTrueFalseTotal
if $rsp->{"success"} 0 0 0
93  
94 0 return sprintf '%s: %s', $rsp->{code}, decode_json( $rsp->{content} );
95 }
96  
97 ########################################################################
98 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod undocumented
99 ########################################################################
100 0 my ($self) = @_;
101  
102 0 my $rsp = $self->raw_response;
103  
104 return
105 0 ▶ if !$self->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_success 0 0 0
106  
107 0 my $decoded_content = decode_json( $rsp->{content} );
108 0 $self->decoded_content($decoded_content);
109  
110 0 $self->usage( LLM::API::Usage->new( $decoded_content->{usage} ) );
111 0 $self->content( LLM::API::Content->new( $decoded_content->{content} ) );
112  
113 0 foreach my $attr (qw(type role model id stop_reason stop_sequence)) {
114 0 $self->set( $attr, $decoded_content->{$attr} );
115 }
116  
117 0 return $self;
118 }
119  
120 ########################################################################
121 0 ▶sub was_cutoff {
Subroutine was_cutoff: not called CC=1 SCAR=6.9
Pod undocumented
122 ########################################################################
123 0 my ($self) = @_;
124  
125 0 return $self->stop_reason eq 'max_tokens';
126 }
127  
128 1 1;
129  
130 __END__
« API/Content.pm ↑ Summary API/Usage.pm »