line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenAI::API::Config; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
170763
|
use Types::Standard qw(Int Num Str); |
|
18
|
|
|
|
|
2048315
|
|
|
18
|
|
|
|
|
206
|
|
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
59955
|
use Moo; |
|
18
|
|
|
|
|
111002
|
|
|
18
|
|
|
|
|
108
|
|
6
|
18
|
|
|
18
|
|
34601
|
use strictures 2; |
|
18
|
|
|
|
|
28212
|
|
|
18
|
|
|
|
|
798
|
|
7
|
18
|
|
|
18
|
|
11514
|
use namespace::clean; |
|
18
|
|
|
|
|
263173
|
|
|
18
|
|
|
|
|
136
|
|
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
|
|
|
|
|
|
|
has 'event_loop_class' => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
default => 'IO::Async::Loop', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__END__ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
OpenAI::API::Config - Configuration options for OpenAI::API |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use OpenAI::API::Config; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $config = OpenAI::API::Config->new( |
36
|
|
|
|
|
|
|
api_base => 'https://api.openai.com/v1', |
37
|
|
|
|
|
|
|
timeout => 60, |
38
|
|
|
|
|
|
|
retry => 3, |
39
|
|
|
|
|
|
|
sleep => 1, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Later... |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
use OpenAI::API; |
46
|
|
|
|
|
|
|
my $openai = OpenAI::API->new( config => $config ); |
47
|
|
|
|
|
|
|
my $res = $openai->models(); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# or... |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
use OpenAI::API::Request::Model::List; |
53
|
|
|
|
|
|
|
my $request = OpenAI::API::Request::Model::List->new( config => $config ); |
54
|
|
|
|
|
|
|
my $res = $request->send(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This module defines a configuration object for the OpenAI API client. It |
60
|
|
|
|
|
|
|
provides default values for various options, such as the API base URL, |
61
|
|
|
|
|
|
|
the API key, and the timeout period for API requests. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=over 4 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * api_key |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The API key to use when making requests to the OpenAI API. This is a |
70
|
|
|
|
|
|
|
required attribute, and if not provided, it will default to the value |
71
|
|
|
|
|
|
|
of the C<OPENAI_API_KEY> environment variable. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item * api_base |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The base URL for the OpenAI API. This defaults to |
76
|
|
|
|
|
|
|
'https://api.openai.com/v1', but can be overridden by setting the |
77
|
|
|
|
|
|
|
C<OPENAI_API_BASE> environment variable. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * timeout |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The timeout period (in seconds) for API requests. This defaults to |
82
|
|
|
|
|
|
|
60 seconds. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * retry |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The number of times to retry a failed API request. This defaults to |
87
|
|
|
|
|
|
|
3 retries. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * sleep |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The number of seconds to wait between retry attempts. This defaults to |
92
|
|
|
|
|
|
|
1 second. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item * event_loop_class |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
IO::Async event loop class (if you are doing asynchronous programming). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Default: L<IO::Async::Loop>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Possible values: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * L<IO::Async::Loop::AnyEvent> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * L<IO::Async::Loop::Mojo> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L<IO::Async::Loop::POE> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * and L<many others|IO::Async#SEE-ALSO> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * new(%args) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Constructs a new OpenAI::API::Config object with the provided options. The |
123
|
|
|
|
|
|
|
available options are the same as the attributes listed above. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * L<OpenAI::API> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * L<OpenAI::API::Request> modules |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |