File Coverage

blib/lib/OpenAI/API/Request/Image/Generation.pm
Criterion Covered Total %
statement 18 20 90.0
branch n/a
condition n/a
subroutine 6 8 75.0
pod 2 2 100.0
total 26 30 86.6


line stmt bran cond sub pod time code
1             package OpenAI::API::Request::Image::Generation;
2              
3 16     16   116 use strict;
  16         45  
  16         485  
4 16     16   98 use warnings;
  16         52  
  16         500  
5              
6 16     16   114 use Types::Standard qw(Int Str Enum);
  16         44  
  16         146  
7              
8 16     16   30072 use Moo;
  16         46  
  16         113  
9 16     16   6587 use strictures 2;
  16         132  
  16         721  
10 16     16   3130 use namespace::clean;
  16         55  
  16         166  
11              
12             extends 'OpenAI::API::Request';
13              
14             has prompt => ( is => 'ro', isa => Str, required => 1, );
15              
16             has n => ( is => 'ro', isa => Int, );
17             has size => ( is => 'ro', isa => Enum [ '256x256', '512x512', '1024x1024' ], );
18             has response_format => ( is => 'ro', isa => Enum [ 'url', 'b64_json' ], );
19             has user => ( is => 'ro', isa => Str, );
20              
21 0     0 1   sub endpoint { 'images/generations' }
22 0     0 1   sub method { 'POST' }
23              
24             1;
25              
26             __END__
27              
28             =head1 NAME
29              
30             OpenAI::API::Request::Image::Generation - generates images from a prompt
31              
32             =head1 SYNOPSIS
33              
34             use OpenAI::API::Request::Image::Generation;
35              
36             my $request = OpenAI::API::Request::Image::Generation->new(
37             prompt => 'A cute baby sea otter',
38             size => '256x256',
39             n => 1,
40             );
41              
42             my $res = $request->send();
43              
44             my @images = @{ $res->{data} };
45              
46             =head1 DESCRIPTION
47              
48             Creates an image given a prompt.
49              
50             =head1 METHODS
51              
52             =head2 new()
53              
54             =over
55              
56             =item * prompt
57              
58             A text description of the desired image(s).
59              
60             =item * n [optional]
61              
62             The number of images to generate. Must be between 1 and 10. Defaults to 1.
63              
64             =item * size [optional]
65              
66             The size of the generated images. Must be one of C<256x256>, C<512x512>,
67             or C<1024x1024>. Defaults to C<1024x1024>.
68              
69             =item * response_format [optional]
70              
71             The format in which the generated images are returned. Must be one of
72             C<url> or C<b64_json>. Defaults to C<url>.
73              
74             =item * user [optional]
75              
76             A unique identifier representing your end-user.
77              
78             =back
79              
80             =head2 send()
81              
82             Sends the request and returns a data structured similar to the one
83             documented in the API reference.
84              
85             =head1 SEE ALSO
86              
87             OpenAI API Reference: L<Models|https://platform.openai.com/docs/api-reference/images>