AI-Image
view release on metacpan or search on metacpan
lib/AI/Image.pm view on Meta::CPAN
# Header for calling OpenAI
sub _get_header_openai {
my $self = shift;
$self->{'key'} = '' unless defined $self->{'key'};
return {
'Authorization' => 'Bearer ' . $self->{'key'},
'Content-type' => 'application/json'
};
}
# Get URL from image prompt
sub image {
my ($self, $prompt) = @_;
my $response = $http->post($url{$self->{'api'}}, {
'headers' => {
'Authorization' => 'Bearer ' . $self->{'key'},
'Content-type' => 'application/json'
},
content => encode_json {
model => $self->{'model'},
size => $self->{'size'},
prompt => $prompt,
}
});
if ($response->{'content'} =~ 'invalid_api_key') {
croak 'Incorrect API Key - check your API Key is correct';
}
if ($self->{'debug'} and !$response->{'success'}) {
croak $response if $self->{'debug'} eq 'verbose';
croak $response->{'content'};
}
lib/AI/Image.pm view on Meta::CPAN
=item debug
Used for testing. If set to any true value, the image method
will return details of the error encountered instead of C<undef>
=back
=head2 image
my $url = $ai->image($prompt);
Generates an image based on the provided prompt and returns the URL of the generated image. The URL is valid for 1 hour.
=head3 Parameters
=over 4
=item prompt
The textual description of the desired image.
=back
=head2 success
my $success = $ai->success();
Returns true if the last operation was successful.
( run in 1.308 second using v1.01-cache-2.11-cpan-6aa56a78535 )