line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAI::API::Config; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
94942
|
use Types::Standard qw(Int Num Str); |
|
18
|
|
|
|
|
1868329
|
|
|
18
|
|
|
|
|
210
|
|
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
56883
|
use Moo; |
|
18
|
|
|
|
|
106894
|
|
|
18
|
|
|
|
|
112
|
|
6
|
18
|
|
|
18
|
|
32400
|
use strictures 2; |
|
18
|
|
|
|
|
27042
|
|
|
18
|
|
|
|
|
765
|
|
7
|
18
|
|
|
18
|
|
11238
|
use namespace::clean; |
|
18
|
|
|
|
|
247902
|
|
|
18
|
|
|
|
|
132
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $DEFAULT_API_BASE = 'https://api.openai.com/v1'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has api_key => ( is => 'rw', isa => Str, default => sub { $ENV{OPENAI_API_KEY} }, required => 1 ); |
12
|
|
|
|
|
|
|
has api_base => ( is => 'rw', isa => Str, default => sub { $ENV{OPENAI_API_BASE} // $DEFAULT_API_BASE }, ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has timeout => ( is => 'rw', isa => Num, default => sub { 60 } ); |
15
|
|
|
|
|
|
|
has retry => ( is => 'rw', isa => Int, default => sub { 3 } ); |
16
|
|
|
|
|
|
|
has sleep => ( is => 'rw', isa => Num, default => sub { 1 } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__END__ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
OpenAI::API::Config - Configuration options for OpenAI::API |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use OpenAI::API::Config; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $config = OpenAI::API::Config->new( |
31
|
|
|
|
|
|
|
api_base => 'https://api.openai.com/v1', |
32
|
|
|
|
|
|
|
timeout => 60, |
33
|
|
|
|
|
|
|
retry => 3, |
34
|
|
|
|
|
|
|
sleep => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Later... |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
use OpenAI::API; |
41
|
|
|
|
|
|
|
my $openai = OpenAI::API->new( config => $config ); |
42
|
|
|
|
|
|
|
my $res = $openai->models(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# or... |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
use OpenAI::API::Request::Model::List; |
48
|
|
|
|
|
|
|
my $request = OpenAI::API::Request::Model::List->new( config => $config ); |
49
|
|
|
|
|
|
|
my $res = $request->send(); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This module defines a configuration object for the OpenAI API client. It |
55
|
|
|
|
|
|
|
provides default values for various options, such as the API base URL, |
56
|
|
|
|
|
|
|
the API key, and the timeout period for API requests. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 4 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * api_key |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The API key to use when making requests to the OpenAI API. This is a |
65
|
|
|
|
|
|
|
required attribute, and if not provided, it will default to the value |
66
|
|
|
|
|
|
|
of the C<OPENAI_API_KEY> environment variable. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * api_base |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The base URL for the OpenAI API. This defaults to |
71
|
|
|
|
|
|
|
'https://api.openai.com/v1', but can be overridden by setting the |
72
|
|
|
|
|
|
|
C<OPENAI_API_BASE> environment variable. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * timeout |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The timeout period (in seconds) for API requests. This defaults to |
77
|
|
|
|
|
|
|
60 seconds. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * retry |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The number of times to retry a failed API request. This defaults to |
82
|
|
|
|
|
|
|
3 retries. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * sleep |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The number of seconds to wait between retry attempts. This defaults to |
87
|
|
|
|
|
|
|
1 second. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 METHODS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * new(%args) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Constructs a new OpenAI::API::Config object with the provided options. The |
98
|
|
|
|
|
|
|
available options are the same as the attributes listed above. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * L<OpenAI::API> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L<OpenAI::API::Request> modules |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |