| 1 | package OpenAI::API; | ||||||||||||||||||||
| 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 OpenAI::API::Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 16 | our $VERSION = 0.36; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | BEGIN { | ||||||||||||||||||||
| 11 | 16 | ▶ | my %module_dispatcher = ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 12 | chat => 'OpenAI::API::Request::Chat', | ||||||||||||||||||||
| 13 | completions => 'OpenAI::API::Request::Completion', | ||||||||||||||||||||
| 14 | edits => 'OpenAI::API::Request::Edit', | ||||||||||||||||||||
| 15 | embeddings => 'OpenAI::API::Request::Embedding', | ||||||||||||||||||||
| 16 | files => 'OpenAI::API::Request::File::List', | ||||||||||||||||||||
| 17 | file_retrieve => 'OpenAI::API::Request::File::Retrieve', | ||||||||||||||||||||
| 18 | image_create => 'OpenAI::API::Request::Image::Generation', | ||||||||||||||||||||
| 19 | models => 'OpenAI::API::Request::Model::List', | ||||||||||||||||||||
| 20 | model_retrieve => 'OpenAI::API::Request::Model::Retrieve', | ||||||||||||||||||||
| 21 | moderations => 'OpenAI::API::Request::Moderation', | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 16 | for my $sub_name ( keys %module_dispatcher ) { | |||||||||||||||||||
| 25 | 160 | my $module = $module_dispatcher{$sub_name}; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 160 | ▶ | eval "require $module" or die $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 16 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 160 | *{"$sub_name"} = sub { | |||||||||||||||||||
| 31 | 10 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 32 | 10 | ▶ | my %params = ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 10 | my $request = $module->new( %params, config => $self->config ); | |||||||||||||||||||
| 35 | 4 | return $request->send(); | |||||||||||||||||||
| 36 | 160 | }; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub new { | ||||||||||||||||||||
| 41 | 3 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 3 | ▶ | my %param = ref $_[0] ? %{ $_[0] } : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 3 | ▶ | my $self = bless \%param, ref $class || $class; | ||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 3 | $self->{config} = OpenAI::API::Config->new(%param); | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | return $self; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub config { | ||||||||||||||||||||
| 53 | 10 | ▶ | my ( $self, %param ) = @_; | ||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 54 | 10 | return $self->{config}; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 16 | 1; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||