Starting of test of server stuff, async methods using pre-release patch for F:AA

This commit is contained in:
Ryan Voots 2024-01-09 13:21:58 -05:00
parent 30cb348269
commit d3b801b5f4
16 changed files with 331 additions and 14 deletions

View file

@ -39,7 +39,7 @@ role OpenAIAsync::Server::API::v1::AudioTTS :strict(params) {
);
}
async method audio_create_speech($obj, $http_req, $ctx) {...}
async method audio_create_speech($obj, $http_req, $ctx);
}
role OpenAIAsync::Server::API::v1::AudioSTT :strict(params) {
@ -53,7 +53,7 @@ role OpenAIAsync::Server::API::v1::AudioSTT :strict(params) {
);
}
async method audio_create_transcript($obj, $http_req, $ctx) {...}
async method audio_create_transcript($obj, $http_req, $ctx);
}
role OpenAIAsync::Server::API::v1::AudioTranslate :strict(params) {
@ -67,7 +67,7 @@ role OpenAIAsync::Server::API::v1::AudioTranslate :strict(params) {
);
}
async method audio_create_translation($obj, $http_req, $ctx) {...}
async method audio_create_translation($obj, $http_req, $ctx);
}
role OpenAIAsync::Server::API::v1::Audio :strict(params) {

View file

@ -39,5 +39,5 @@ role OpenAIAsync::Server::API::v1::ChatCompletion :strict(params) {
);
}
method chat($obj, $http_req, $ctx);
async method chat($obj, $http_req, $ctx);
}

View file

@ -37,5 +37,5 @@ role OpenAIAsync::Server::API::v1::Completions :strict(params) {
);
}
async method completion($obj, $http_req, $ctx) {...}
async method completion($obj, $http_req, $ctx);
}

View file

@ -37,5 +37,5 @@ role OpenAIAsync::Server::API::v1::Embeddings :strict(params) {
);
}
async method embeddings($obj, $http_req, $ctx) {...}
async method embeddings($obj, $http_req, $ctx);
}

View file

@ -66,9 +66,9 @@ role OpenAIAsync::Server::API::v1::File :strict(params) {
);
}
async method file_list($http_req, $ctx) {...}
async method file_info($http_req, $ctx, $params) {...}
async method file_delete($http_req, $ctx, $params) {...}
async method file_upload($http_req, $ctx, $params) {...}
async method file_download($http_req, $ctx, $params) {...}
async method file_list($http_req, $ctx);
async method file_info($http_req, $ctx, $params);
async method file_delete($http_req, $ctx, $params);
async method file_upload($http_req, $ctx, $params);
async method file_download($http_req, $ctx, $params);
}

View file

@ -36,5 +36,5 @@ role OpenAIAsync::Server::API::v1::Image :strict(params) {
);
}
async method create_image($http_req, $ctx) {...}
async method create_image($http_req, $ctx);
}

View file

@ -36,5 +36,5 @@ role OpenAIAsync::Server::API::v1::ModelList :strict(params) {
);
}
async method model_list($obj, $http_req, $ctx) {...}
async method model_list($obj, $http_req, $ctx);
}

View file

@ -36,5 +36,5 @@ role OpenAIAsync::Server::API::v1::Moderations :strict(params) {
);
}
async method moderations($obj, $http_req, $ctx) {...}
async method moderations($obj, $http_req, $ctx);
}

View file

@ -17,6 +17,13 @@ BEGIN {
class TestServer {
inherit OpenAIAsync::Server;
apply OpenAIAsync::Server::API::Test::ChatCompletion;
apply OpenAIAsync::Server::API::Test::Audio;
apply OpenAIAsync::Server::API::Test::Completions;
apply OpenAIAsync::Server::API::Test::Embeddings;
apply OpenAIAsync::Server::API::Test::File;
apply OpenAIAsync::Server::API::Test::Image;
apply OpenAIAsync::Server::API::Test::ModelList;
apply OpenAIAsync::Server::API::Test::Moderations;
}
my $server = TestServer->new(listen => '127.0.0.1', port => 12345);

View file

@ -0,0 +1,52 @@
package OpenAIAsync::Server::API::Test::Audio;
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::Audio - Basic audio api role, consumed to implement the OpenAI audio api. Does not provide an implementation, you are expected to override them in your class
TODO document the subroles here, split up because TTS is much simpler to implement than the others and will be more valuable to support alone if someone chooses
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::Test::AudioTTS :strict(params) {
apply OpenAIAsync::Server::API::v1::AudioTTS;
async method audio_create_speech($obj, $http_req, $ctx) {...}
}
role OpenAIAsync::Server::API::Test::AudioSTT :strict(params) {
apply OpenAIAsync::Server::API::v1::AudioSTT;
async method audio_create_transcript($obj, $http_req, $ctx) {...}
}
role OpenAIAsync::Server::API::Test::AudioTranslate :strict(params) {
apply OpenAIAsync::Server::API::v1::AudioTranslate;
async method audio_create_translation($obj, $http_req, $ctx) {...}
}
role OpenAIAsync::Server::API::Test::Audio :strict(params) {
apply OpenAIAsync::Server::API::Test::AudioTTS;
apply OpenAIAsync::Server::API::Test::AudioSTT;
apply OpenAIAsync::Server::API::Test::AudioTranslate;
}
1;

View file

@ -0,0 +1,32 @@
package OpenAIAsync::Server::API::Test::Completions;
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::Completions - Basic completion api role, consumed to implement the OpenAI chat completion api. Does not provide an implementation, you are expected to override them in your class
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::Test::Completions :strict(params) {
apply OpenAIAsync::Server::API::v1::Completions;
async method completion($obj, $http_req, $ctx) { ... }
}

View file

@ -0,0 +1,32 @@
package OpenAIAsync::Server::API::Test::Embeddings;
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::Embeddings - Basic embeddings api role, consumed to implement the OpenAI embeddings api. Does not provide an implementation, you are expected to override them in your class
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::Test::Embeddings {
apply OpenAIAsync::Server::API::v1::Embeddings;
async method embeddings($obj, $http_req, $ctx) { ... }
}

View file

@ -0,0 +1,74 @@
package OpenAIAsync::Server::API::v1::File;
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::File - Basic file api role, consumed to implement the OpenAI file server. Does not provide an implementation, you are expected to override them in your class
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::v1::File :strict(params) {
ADJUST {
$self->register_url(
method => 'POST',
url => qr{^/v1/files$},
handle => async sub($req, $ctx, $obj, $params) {await $self->file_upload($obj, $req, $ctx)},
request_class => "OpenAIAsync::Type::Request::FileUpload",
result_class => "OpenAIAsync::Type::Shared::File",
decoder => 'www-form-urlencoded', # default is json, we need this for this api
);
$self->register_url(
method => 'GET',
url => qr{^/v1/files/(?<file_id>[^/]+)/content$},
handle => async sub($req, $ctx, $obj, $params) {await $self->file_download($obj, $req, $ctx, $params)},
request_class => "", # No req type here
result_class => "", # TODO this should be special, it's raw content, make it undef? leave it off?
);
$self->register_url(
method => 'GET',
url => qr{^/v1/files/(?<file_id>[^/]+)$},
handle => async sub($req, $ctx, $obj, $params) {await $self->file_info($obj, $req, $ctx, $params)},
request_class => "", # No req type here
result_class => "OpenAIAsync::Type::Shared::File",
);
$self->register_url(
method => 'DELETE',
url => qr{^/v1/files/(?<file_id>[^/]+)$},
handle => async sub($req, $ctx, $obj, $params) {await $self->file_delete($obj, $req, $ctx, $params)},
request_class => "", # No req type here
result_class => "OpenAIAsync::Type::Results::FileDeletion",
);
$self->register_url(
method => 'GET',
url => qr{^/v1/files$},
handle => async sub($req, $ctx, $obj, $params) {await $self->file_list($obj, $req, $ctx)},
request_class => "OpenAIAsync::Type::Request::FileList",
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.
);
}
method file_list($http_req, $ctx);
method file_info($http_req, $ctx, $params);
method file_delete($http_req, $ctx, $params);
method file_upload($http_req, $ctx, $params);
method file_download($http_req, $ctx, $params);
}

View file

@ -0,0 +1,40 @@
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::GenerateImage",
result_class => "",
);
}
method create_image($http_req, $ctx);
}

View file

@ -0,0 +1,40 @@
package OpenAIAsync::Server::API::v1::ModelList;
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::ModelList - Basic model list api role, consumed to implement the OpenAI model list api. Does not provide an implementation, you are expected to override them in your class
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::v1::ModelList :strict(params) {
ADJUST {
$self->register_url(
method => 'POST',
url => qr{^/v1/models$},
handle => async sub($req, $ctx, $obj, $params) {await $self->model_list($obj, $req, $ctx)},
request_class => "",
result_class => "OpenAIAsync::Type::Result::ModelList",
);
}
method model_list($obj, $http_req, $ctx);
}

View file

@ -0,0 +1,40 @@
package OpenAIAsync::Server::API::v1::Moderations;
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::Moderations - Basic moderation api role, consumed to implement the OpenAI moderation api. Does not provide an implementation, you are expected to override them in your class
=head1 SYNOPSIS
...
=cut
role OpenAIAsync::Server::API::v1::Moderations :strict(params) {
ADJUST {
$self->register_url(
method => 'POST',
url => qr{^/v1/moderations$},
handle => async sub($req, $ctx, $obj, $params) {await $self->moderations($obj, $req, $ctx)},
request_class => "OpenAIAsync::Type::Requests::CreateModeration",
result_class => "OpenAIAsync::Type::Results::Moderations",
);
}
method moderations($obj, $http_req, $ctx);
}