This commit is contained in:
parent
1e9a5b1fe2
commit
ccafe0deae
5 changed files with 92 additions and 4 deletions
2
.vstags
2
.vstags
|
@ -9862,7 +9862,6 @@ OpenAIAsync::Server .build/S3aTKnbkmA/lib/OpenAIAsync/Server.pm 1;" p
|
||||||
OpenAIAsync::Server .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server.pm 1;" p
|
OpenAIAsync::Server .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server.pm 1;" p
|
||||||
OpenAIAsync::Server .build/kBWSNkpY90/lib/OpenAIAsync/Server.pm 1;" p
|
OpenAIAsync::Server .build/kBWSNkpY90/lib/OpenAIAsync/Server.pm 1;" p
|
||||||
OpenAIAsync::Server lib/OpenAIAsync/Server.pm 1;" p
|
OpenAIAsync::Server lib/OpenAIAsync/Server.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::Audio lib/OpenAIAsync/Server/API/v1/Audio.pm 1;" p
|
|
||||||
OpenAIAsync::Server::API::v1::ChatCompletion .build/S3aTKnbkmA/blib/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
OpenAIAsync::Server::API::v1::ChatCompletion .build/S3aTKnbkmA/blib/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::ChatCompletion .build/S3aTKnbkmA/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
OpenAIAsync::Server::API::v1::ChatCompletion .build/S3aTKnbkmA/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::ChatCompletion .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
OpenAIAsync::Server::API::v1::ChatCompletion .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm 1;" p
|
||||||
|
@ -9883,6 +9882,7 @@ OpenAIAsync::Server::API::v1::File .build/S3aTKnbkmA/lib/OpenAIAsync/Server/API/
|
||||||
OpenAIAsync::Server::API::v1::File .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
OpenAIAsync::Server::API::v1::File .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::File .build/kBWSNkpY90/lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
OpenAIAsync::Server::API::v1::File .build/kBWSNkpY90/lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::File lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
OpenAIAsync::Server::API::v1::File lib/OpenAIAsync/Server/API/v1/File.pm 1;" p
|
||||||
|
OpenAIAsync::Server::API::v1::Image lib/OpenAIAsync/Server/API/v1/Image.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::ModelList .build/S3aTKnbkmA/blib/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
OpenAIAsync::Server::API::v1::ModelList .build/S3aTKnbkmA/blib/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::ModelList .build/S3aTKnbkmA/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
OpenAIAsync::Server::API::v1::ModelList .build/S3aTKnbkmA/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
||||||
OpenAIAsync::Server::API::v1::ModelList .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
OpenAIAsync::Server::API::v1::ModelList .build/kBWSNkpY90/blib/lib/OpenAIAsync/Server/API/v1/ModelList.pm 1;" p
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package OpenAIAsync::Server::API::v1::Audio;
|
cpackage OpenAIAsync::Server::API::v1::Audio;
|
||||||
|
|
||||||
use v5.36.0;
|
use v5.36.0;
|
||||||
use Object::Pad;
|
use Object::Pad;
|
||||||
|
|
41
lib/OpenAIAsync/Server/API/v1/Image.pm
Normal file
41
lib/OpenAIAsync/Server/API/v1/Image.pm
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package OpenAIAsync::Server::API::v1::Image;
|
||||||
|
|
||||||
|
use v5.36.0;
|
||||||
|
use Object::Pad;
|
||||||
|
use IO::Async::SSL; # We're not directly using it but I want to enforce that we pull it in when detecting dependencies, since openai itself is always https
|
||||||
|
use Future::AsyncAwait;
|
||||||
|
use IO::Async;
|
||||||
|
|
||||||
|
use OpenAIAsync::Types::Results;
|
||||||
|
use OpenAIAsync::Types::Requests;
|
||||||
|
|
||||||
|
our $VERSION = '0.02';
|
||||||
|
|
||||||
|
# ABSTRACT: Async server for OpenAI style REST API for various AI systems (LLMs, Images, Video, etc.)
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
OpenAIAsync::Server::API::Image - Basic image role, consumed to implement the OpenAI image api. Does not provide an implementation, you are expected to override them in your class
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
role OpenAIAsync::Server::API::v1::Image :strict(params) {
|
||||||
|
ADJUST {
|
||||||
|
$self->register_url(
|
||||||
|
method => 'GET',
|
||||||
|
url => qr{^/v1/files$},
|
||||||
|
handle => async sub($req, $ctx, $obj, $params) {await $self->create_image($obj, $req, $ctx)},
|
||||||
|
request_class => "OpenAIAsync::Type::Requests::",
|
||||||
|
result_class => "OpenAIAsync::Type::Results::FileList",
|
||||||
|
decoder => 'optional_json', # this API input is OPTIONAL, if it's not present then we create a blank object to use.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async method create_image($http_req, $ctx) {...}
|
||||||
|
}
|
|
@ -284,4 +284,41 @@ class OpenAIAsync::Types::Requests::Moderations :does(OpenAIAsync::Types::Reques
|
||||||
field $model :JSONStr = undef;
|
field $model :JSONStr = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
class OpenAIAsync::Types::Requests::GenerateImage :does(OpenAIAsync::Types::Requests::Base) :Struct {
|
||||||
|
method _endpoint() {"/images/generations"}
|
||||||
|
|
||||||
|
field $prompt :JSONStr;
|
||||||
|
field $model :JSONStr = undef;
|
||||||
|
field $n :JSONNum = undef; # how many to generate
|
||||||
|
field $quality :JSONStr = undef; # defaults to "standard", can also be "hd"
|
||||||
|
field $response_format :JSONStr = undef; # url, or b64_json
|
||||||
|
field $size :JSONStr = undef; # defaults to 1024x1024
|
||||||
|
field $style :JSONStr = undef; # vivid or natural, defaults to vivid
|
||||||
|
field $user :JSONStr = undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
class OpenAIAsync::Types::Requests::CreateImageEdit :does(OpenAIAsync::Types::Requests::BaseFormEncoding) :Struct {
|
||||||
|
method _endpoint() {"/images/edits"}
|
||||||
|
|
||||||
|
field $image; # Image file data, TODO document?
|
||||||
|
field $mask = undef; # Image file data for mask, TODO document
|
||||||
|
field $prompt :JSONStr;
|
||||||
|
field $model :JSONStr = undef;
|
||||||
|
field $n :JSONNum = undef; # how many to generate
|
||||||
|
field $response_format :JSONStr = undef; # url, or b64_json
|
||||||
|
field $size :JSONStr = undef; # defaults to 1024x1024
|
||||||
|
field $user :JSONStr = undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
class OpenAIAsync::Types::Requests::CreateImageVariation :does(OpenAIAsync::Types::Requests::BaseFormEncoding) :Struct {
|
||||||
|
method _endpoint() {"/images/variations"}
|
||||||
|
|
||||||
|
field $image; # Image file data, TODO document?
|
||||||
|
field $model :JSONStr = undef;
|
||||||
|
field $n :JSONNum = undef; # how many to generate
|
||||||
|
field $response_format :JSONStr = undef; # url, or b64_json
|
||||||
|
field $size :JSONStr = undef; # defaults to 1024x1024
|
||||||
|
field $user :JSONStr = undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -159,4 +159,14 @@ class OpenAIAsync::Types::Results::ModerationResultsCategoryScores :does(OpenAIA
|
||||||
field $sexual_minors :JSONNum :JSONKey(sexual/minors);
|
field $sexual_minors :JSONNum :JSONKey(sexual/minors);
|
||||||
field $violence :JSONNum;
|
field $violence :JSONNum;
|
||||||
field $violence_graphic :JSONNum :JSONKey(violence/graphic);
|
field $violence_graphic :JSONNum :JSONKey(violence/graphic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OpenAIAsync::Types::Results::Image :does(OpenAIAsync::Types::Base) :Struct {
|
||||||
|
field $b64_json :JSONStr = undef;
|
||||||
|
field $url :JSONStr = undef;
|
||||||
|
field $revised_prompt :JSONStr = undef;
|
||||||
|
|
||||||
|
ADJUST {
|
||||||
|
die "Missing required value one of b64_json or url" unless ($b64_json or $url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue