diff --git a/lib/OpenAIAsync/Server.pm b/lib/OpenAIAsync/Server.pm index 2430d08..10623ab 100644 --- a/lib/OpenAIAsync/Server.pm +++ b/lib/OpenAIAsync/Server.pm @@ -360,7 +360,8 @@ class OpenAIAsync::Server :repr(HASH) :strict(params) { # TODO can I redo this to eliminate the $future_status? I want it for internal chaining inside the handler # that is needed for it to persist some code that's running in the future that populates the queue - await $route->{handle}->($req, $future_status, $queue, $ctx, $obj, $params); + my $route_method = $route->{handle}; + await $self->$route_method($req, $future_status, $queue, $ctx, $obj, $params); my $status = await $future_status; my $is_streaming_event = $status->{is_streaming}; diff --git a/lib/OpenAIAsync/Server/API/v1/Audio.pm b/lib/OpenAIAsync/Server/API/v1/Audio.pm index 57f52e7..99ed8dc 100644 --- a/lib/OpenAIAsync/Server/API/v1/Audio.pm +++ b/lib/OpenAIAsync/Server/API/v1/Audio.pm @@ -33,13 +33,13 @@ role OpenAIAsync::Server::API::v1::AudioTTS :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/audio/speech$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->audio_create_speech($obj, $req, $ctx)}, + handle => "audio_create_speech", request_class => "OpenAIAsync::Type::Requests::CreateSpeech", result_class => "", # This gives back a file of audio data ); } - async method audio_create_speech($obj, $http_req, $ctx); + async method audio_create_speech($req, $future_status, $queue, $ctx, $obj, $params); } role OpenAIAsync::Server::API::v1::AudioSTT :strict(params) { @@ -47,13 +47,13 @@ role OpenAIAsync::Server::API::v1::AudioSTT :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/audio/transcription$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->audio_create_transcript($obj, $req, $ctx)}, + handle => "audio_create_transcript", request_class => "OpenAIAsync::Type::Requests::CreateTranscription", - result_class => "", # This gives back a file, in the requested format + result_class => "OpenAIAsync::Type::Response::AudioFile", ); } - async method audio_create_transcript($obj, $http_req, $ctx); + async method audio_create_transcript($req, $future_status, $queue, $ctx, $obj, $params); } role OpenAIAsync::Server::API::v1::AudioTranslate :strict(params) { @@ -61,13 +61,13 @@ role OpenAIAsync::Server::API::v1::AudioTranslate :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->audio_create_translation($obj, $req, $ctx)}, + handle => "audio_create_translation", request_class => "OpenAIAsync::Type::Requests::CreateTranslation", - result_class => "", # This gives back a file, in the requested format + result_class => "OpenAIAsync::Type::Response::AudioFile", ); } - async method audio_create_translation($obj, $http_req, $ctx); + async method audio_create_translation($req, $future_status, $queue, $ctx, $obj, $params); } role OpenAIAsync::Server::API::v1::Audio :strict(params) { diff --git a/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm b/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm index b77dbae..6c80eb0 100644 --- a/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm +++ b/lib/OpenAIAsync/Server/API/v1/ChatCompletion.pm @@ -32,12 +32,12 @@ role OpenAIAsync::Server::API::v1::ChatCompletion :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/chat/completions$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->chat($obj, $req, $ctx)}, + handle => "chat_completion", request_class => "OpenAIAsync::Types::Requests::ChatCompletion", result_class => "OpenAIAsync::Types::Results::ChatCompletion", decoder => 'json', # default is json, we need this for this api ); } - async method chat($obj, $http_req, $ctx); + async method chat_completion($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/Completions.pm b/lib/OpenAIAsync/Server/API/v1/Completions.pm index 8c2f066..ca7fe04 100644 --- a/lib/OpenAIAsync/Server/API/v1/Completions.pm +++ b/lib/OpenAIAsync/Server/API/v1/Completions.pm @@ -30,12 +30,12 @@ role OpenAIAsync::Server::API::v1::Completions :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/completions$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->completion($obj, $req, $ctx)}, + handle => "completion", request_class => "OpenAIAsync::Type::Request::Completion", result_class => "OpenAIAsync::Type::Result::Completion", decoder => 'www-form-urlencoded', # default is json, we need this for this api ); } - async method completion($obj, $http_req, $ctx); + async method completion($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/Embeddings.pm b/lib/OpenAIAsync/Server/API/v1/Embeddings.pm index 9511a0f..f8377b3 100644 --- a/lib/OpenAIAsync/Server/API/v1/Embeddings.pm +++ b/lib/OpenAIAsync/Server/API/v1/Embeddings.pm @@ -30,12 +30,12 @@ role OpenAIAsync::Server::API::v1::Embeddings :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/embeddings$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->embeddings($obj, $req, $ctx)}, + handle => "embeddings", request_class => "OpenAIAsync::Type::Request::Embeddings", result_class => "OpenAIAsync::Type::Result::Embeddings", decoder => 'www-form-urlencoded', # default is json, we need this for this api ); } - async method embeddings($obj, $http_req, $ctx); + async method embeddings($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/File.pm b/lib/OpenAIAsync/Server/API/v1/File.pm index 22be369..757b4f6 100644 --- a/lib/OpenAIAsync/Server/API/v1/File.pm +++ b/lib/OpenAIAsync/Server/API/v1/File.pm @@ -30,7 +30,7 @@ role OpenAIAsync::Server::API::v1::File :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/files$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->file_upload($obj, $req, $ctx)}, + handle => "file_upload", 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 @@ -38,37 +38,37 @@ role OpenAIAsync::Server::API::v1::File :strict(params) { $self->register_url( method => 'GET', url => qr{^/v1/files/(?[^/]+)/content$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->file_download($obj, $req, $ctx, $params)}, + handle => "file_download", request_class => "", # No req type here - result_class => "", # TODO this should be special, it's raw content, make it undef? leave it off? + result_class => "OpenAIAsync::Type::Results::RawFile", ); $self->register_url( method => 'GET', url => qr{^/v1/files/(?[^/]+)$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->file_info($obj, $req, $ctx, $params)}, + handle => "file_info", request_class => "", # No req type here result_class => "OpenAIAsync::Type::Shared::File", ); $self->register_url( method => 'DELETE', url => qr{^/v1/files/(?[^/]+)$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->file_delete($obj, $req, $ctx, $params)}, + handle => "file_delete", 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)}, + handle => "file_list", 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. ); } - 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($req, $future_status, $queue, $ctx, $obj, $params); + async method file_info($req, $future_status, $queue, $ctx, $obj, $params); + async method file_delete($req, $future_status, $queue, $ctx, $obj, $params); + async method file_upload($req, $future_status, $queue, $ctx, $obj, $params); + async method file_download($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/Image.pm b/lib/OpenAIAsync/Server/API/v1/Image.pm index 65fa93d..c2b167c 100644 --- a/lib/OpenAIAsync/Server/API/v1/Image.pm +++ b/lib/OpenAIAsync/Server/API/v1/Image.pm @@ -30,11 +30,11 @@ role OpenAIAsync::Server::API::v1::Image :strict(params) { $self->register_url( method => 'GET', url => qr{^/v1/files$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->create_image($obj, $req, $ctx)}, + handle => "create_image", request_class => "OpenAIAsync::Type::Requests::GenerateImage", - result_class => "", + result_class => "OpenAIAsync::Type::Results::RawFile", # TOOD image class? ); } - async method create_image($http_req, $ctx); + async method create_image($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/ModelList.pm b/lib/OpenAIAsync/Server/API/v1/ModelList.pm index c96ec44..2b99519 100644 --- a/lib/OpenAIAsync/Server/API/v1/ModelList.pm +++ b/lib/OpenAIAsync/Server/API/v1/ModelList.pm @@ -30,11 +30,11 @@ role OpenAIAsync::Server::API::v1::ModelList :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/models$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->model_list($obj, $req, $ctx)}, + handle => "model_list", request_class => "", result_class => "OpenAIAsync::Type::Result::ModelList", ); } - async method model_list($obj, $http_req, $ctx); + async method model_list($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file diff --git a/lib/OpenAIAsync/Server/API/v1/Moderations.pm b/lib/OpenAIAsync/Server/API/v1/Moderations.pm index 8a23c6f..9f64738 100644 --- a/lib/OpenAIAsync/Server/API/v1/Moderations.pm +++ b/lib/OpenAIAsync/Server/API/v1/Moderations.pm @@ -30,11 +30,11 @@ role OpenAIAsync::Server::API::v1::Moderations :strict(params) { $self->register_url( method => 'POST', url => qr{^/v1/moderations$}, - handle => async sub($req, $ctx, $obj, $params) {await $self->moderations($obj, $req, $ctx)}, + handle => "moderations", request_class => "OpenAIAsync::Type::Requests::CreateModeration", result_class => "OpenAIAsync::Type::Results::Moderations", ); } - async method moderations($obj, $http_req, $ctx); + async method moderations($req, $future_status, $queue, $ctx, $obj, $params); } \ No newline at end of file