New API design works!
This commit is contained in:
parent
4811272f5e
commit
e47e503698
3 changed files with 12 additions and 13 deletions
|
@ -375,24 +375,17 @@ class OpenAIAsync::Server :repr(HASH) :strict(params) {
|
|||
$response->protocol("HTTP/1.1");
|
||||
|
||||
my $resp_string = $response->as_string("\r\n");
|
||||
print STDERR "resp_string: $resp_string\n";
|
||||
|
||||
$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();
|
||||
|
||||
print STDERR Dumper($body);
|
||||
|
||||
if ($is_streaming) {
|
||||
return sprintf "event: %s\ndata: %s\n\n", $event_name, $body;
|
||||
} else {
|
||||
|
@ -400,8 +393,9 @@ class OpenAIAsync::Server :repr(HASH) :strict(params) {
|
|||
}
|
||||
} else {
|
||||
# Finished
|
||||
print STDERR "Finished!\n";
|
||||
|
||||
$req->done();
|
||||
$req->{conn}->close(); #TODO why is this needed?
|
||||
return undef;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -52,11 +52,15 @@ sub mk_req($uri, $content) {
|
|||
return $http_client->POST("http://127.0.0.1:$port/v1".$uri, $content_json, content_type => 'application/json');
|
||||
}
|
||||
|
||||
my $res = await mk_req("/chat/completions", $chat_completion_input);
|
||||
my $res_fut = mk_req("/chat/completions", $chat_completion_input);
|
||||
|
||||
$loop->delay_future(after => 5)->get();
|
||||
|
||||
my $res = $res_fut->get();
|
||||
|
||||
my $content = $res->content;
|
||||
is($content, '{"choices":[],"created":"0","id":"24601","model":"GumbyBrain-llm","object":"text_completion","system_fingerprint":"SHODAN node 12 of 16 tertiary adjunct of unimatrix 42","usage":{"completion_tokens":9,"prompt_tokens":6,"total_tokens":42}}', "check marshalling of data directly");
|
||||
#$loop->delay_future(after => 120)->get();
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,11 +29,12 @@ role OpenAIAsync::Server::API::Test::ChatCompletion :strict(params) {
|
|||
apply OpenAIAsync::Server::API::v1::ChatCompletion;
|
||||
use OpenAIAsync::Types::Results;
|
||||
use Future::AsyncAwait;
|
||||
no warnings 'experimental::builtin';
|
||||
use builtin qw/false/;
|
||||
|
||||
async method chat_completion ($future_status, $queue, $ctx, $obj, $params) {
|
||||
my $chained_future = $future_status->then(async sub {
|
||||
await $queue->push(OpenAIAsync::Types::Results::ChatCompletion->new(
|
||||
my $chained_future = $future_status->then(sub {
|
||||
$queue->push(OpenAIAsync::Types::Results::ChatCompletion->new(
|
||||
id => "24601",
|
||||
choices => [],
|
||||
model => "GumbyBrain-llm",
|
||||
|
@ -45,7 +46,7 @@ role OpenAIAsync::Server::API::Test::ChatCompletion :strict(params) {
|
|||
},
|
||||
object => "text_completion",
|
||||
created => 0,
|
||||
));
|
||||
))->get();
|
||||
|
||||
$queue->finish();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue