Ok so it now runs, but doesnt exit the test
This commit is contained in:
parent
a6fd7dc043
commit
4811272f5e
3 changed files with 25 additions and 11 deletions
|
@ -361,7 +361,7 @@ 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
|
||||
my $route_method = $route->{handle};
|
||||
await $self->$route_method($future_status, $queue, $ctx, $obj, $params);
|
||||
$self->$route_method($future_status, $queue, $ctx, $obj, $params);
|
||||
|
||||
my $status = await $future_status;
|
||||
my $is_streaming = $status->{is_streaming};
|
||||
|
@ -372,16 +372,26 @@ class OpenAIAsync::Server :repr(HASH) :strict(params) {
|
|||
# TODO others?
|
||||
);
|
||||
my $response = HTTP::Response->new($status->{status_code}, $status->{status_message}, $headers);
|
||||
$response->protocol("HTTP/1.1");
|
||||
|
||||
$req->write($response->as_string("\r\n"));
|
||||
$req->write("\r\n"); # extra to end headers
|
||||
my $resp_string = $response->as_string("\r\n");
|
||||
print STDERR "resp_string: $resp_string\n";
|
||||
|
||||
$req->write(async sub {
|
||||
my $body_obj = await $queue->pull();
|
||||
$req->write($resp_string);
|
||||
# $req->write("\r\n"); # extra to end headers
|
||||
|
||||
$req->write(sub {
|
||||
print STDERR "About to shift\n";
|
||||
my $body_obj = $queue->shift()->get();
|
||||
|
||||
use Data::Dumper;
|
||||
print STDERR Dumper($body_obj);
|
||||
|
||||
if (defined $body_obj) {
|
||||
my $body = $body_obj->serialize();
|
||||
my $event_name = $body_obj->event_name();
|
||||
my $body = $body_obj->_serialize();
|
||||
my $event_name = $body_obj->_event_name();
|
||||
|
||||
print STDERR Dumper($body);
|
||||
|
||||
if ($is_streaming) {
|
||||
return sprintf "event: %s\ndata: %s\n\n", $event_name, $body;
|
||||
|
@ -390,6 +400,7 @@ class OpenAIAsync::Server :repr(HASH) :strict(params) {
|
|||
}
|
||||
} else {
|
||||
# Finished
|
||||
print STDERR "Finished!\n";
|
||||
$req->done();
|
||||
return undef;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ role OpenAIAsync::Types::Results::Encoder::JSON {
|
|||
}
|
||||
|
||||
method _content_type() {"application/json"}
|
||||
method _event_name() {"event"}
|
||||
}
|
||||
|
||||
role OpenAIAsync::Types::Results::Encoder::Raw {
|
||||
|
|
|
@ -32,8 +32,8 @@ role OpenAIAsync::Server::API::Test::ChatCompletion :strict(params) {
|
|||
use builtin qw/false/;
|
||||
|
||||
async method chat_completion ($future_status, $queue, $ctx, $obj, $params) {
|
||||
my $chained_future = $future_status->then(sub {
|
||||
return OpenAIAsync::Types::Results::ChatCompletion->new(
|
||||
my $chained_future = $future_status->then(async sub {
|
||||
await $queue->push(OpenAIAsync::Types::Results::ChatCompletion->new(
|
||||
id => "24601",
|
||||
choices => [],
|
||||
model => "GumbyBrain-llm",
|
||||
|
@ -45,7 +45,9 @@ role OpenAIAsync::Server::API::Test::ChatCompletion :strict(params) {
|
|||
},
|
||||
object => "text_completion",
|
||||
created => 0,
|
||||
)
|
||||
));
|
||||
|
||||
$queue->finish();
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue