API/Request/Chat.pm

filter: Statementstmt 72.5% 37 / 51 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 100% 4 / 4 totaltotal 64.8% 48 / 74 SCAR 12.1
CC
3
Cov
66%
add_message
12.0
endpoint
2.0
method
2.0
CRAP 3.4
« API.pm ↑ Summary API/Error.pm »
1 package OpenAI::API::Request::Chat;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 16 extends 'OpenAI::API::Request';
13  
14 16 ▶use Types::Standard qw(Any Bool Int Num Str Map ArrayRef HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 16 has model => ( is => 'rw', isa => Str, default => 'gpt-3.5-turbo' );
17 0 ▶has messages => ( is => 'rw', isa => ArrayRef [HashRef], default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
18  
19 16 has max_tokens => ( is => 'rw', isa => Int, );
20 16 has temperature => ( is => 'rw', isa => Num, );
21 16 has top_p => ( is => 'rw', isa => Num, );
22 16 has n => ( is => 'rw', isa => Int, );
23 16 has stream => ( is => 'rw', isa => Bool, );
24 16 has logprobs => ( is => 'rw', isa => Int, );
25 16 has echo => ( is => 'rw', isa => Bool, );
26 16 has stop => ( is => 'rw', isa => Any, );
27 16 has presence_penalty => ( is => 'rw', isa => Num, );
28 16 has frequency_penalty => ( is => 'rw', isa => Num, );
29 16 has logit_bias => ( is => 'rw', isa => Map [ Int, Int ], );
30 16 has user => ( is => 'rw', isa => Str, );
31  
32 0 ▶sub endpoint { 'chat/completions' }
Subroutine endpoint: not called CC=1 SCAR=6.9
Pod documented
33 0 ▶sub method { 'POST' }
Subroutine method: not called CC=1 SCAR=6.9
Pod documented
34  
35 sub add_message {
36 0 ▶ my ( $self, $role, $content ) = @_;
Subroutine add_message: not called CC=3 SCAR=24.8
Pod documented
37  
38 0 ▶ croak 'add_message() requires two parameters: role and content' if !defined $role || !defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $role and defined $content 0 0 0
Condition0%0/3
defined $role and defined $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $role and defined $content
defined $role defined $content
Truth table0%0/3
A and B
A= defined $roleB= defined $content
ABresult
0X0
100
111
39  
40 0 push @{ $self->messages }, { role => $role, content => $content };
41  
42 0 return $self;
43 }
44  
45 sub send_message {
46 0 ▶ my ( $self, $content ) = @_;
Subroutine send_message: not called CC=1 SCAR=6.9
Pod documented
47  
48 0 $self->add_message( 'user', $content );
49  
50 0 my $res = $self->send();
51 0 my $assistant_response = $res->{choices}[0]{message}{content};
52  
53 0 $self->add_message( 'assistant', $assistant_response );
54  
55 0 return $res;
56 }
57  
58 16 1;
59  
60 __END__
« API.pm ↑ Summary API/Error.pm »