beginning rename of things
This commit is contained in:
parent
e47e503698
commit
502433f9a1
28 changed files with 41 additions and 1 deletions
|
@ -47,7 +47,6 @@ class OpenAIAsync::Types::Requests::ChatCompletion :Struct {
|
||||||
field $function_call :JSONExclude = undef;
|
field $function_call :JSONExclude = undef;
|
||||||
field $functions :JSONExclude = undef;
|
field $functions :JSONExclude = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
class OpenAIAsync::Types::Requests::Completion :Struct {
|
class OpenAIAsync::Types::Requests::Completion :Struct {
|
||||||
apply OpenAIAsync::Types::Requests::Base;
|
apply OpenAIAsync::Types::Requests::Base;
|
||||||
|
|
|
@ -1,26 +1,48 @@
|
||||||
|
# test for OpenAIAsync perl module
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
# Use the Test2::V0 module for testing
|
||||||
use Test2::V0;
|
use Test2::V0;
|
||||||
|
|
||||||
use OpenAIAsync::Server;
|
use OpenAIAsync::Server;
|
||||||
|
# Import the OpenAIAsync::Server module
|
||||||
|
use OpenAIAsync::Server;
|
||||||
|
|
||||||
|
# Use Object::Pad for object-oriented programming
|
||||||
use Object::Pad;
|
use Object::Pad;
|
||||||
|
|
||||||
|
# Import IO::Async::Loop for managing loops and event loops
|
||||||
use IO::Async::Loop;
|
use IO::Async::Loop;
|
||||||
|
|
||||||
|
# Use Future::AsyncAwait for easier handling of asynchronous operations
|
||||||
use Future::AsyncAwait;
|
use Future::AsyncAwait;
|
||||||
|
|
||||||
|
# Import JSON::MaybeXS for encoding and decoding JSON data
|
||||||
use JSON::MaybeXS;
|
use JSON::MaybeXS;
|
||||||
|
|
||||||
|
# Import Net::Async::HTTP for asynchronous HTTP requests
|
||||||
use Net::Async::HTTP;
|
use Net::Async::HTTP;
|
||||||
|
|
||||||
|
# Use the relative path './lib' for module lookup
|
||||||
use lib::relative './lib';
|
use lib::relative './lib';
|
||||||
|
|
||||||
|
# Create an instance of IO::Async::Loop
|
||||||
my $loop = IO::Async::Loop->new();
|
my $loop = IO::Async::Loop->new();
|
||||||
|
|
||||||
|
# Set the OPENAI_API_KEY environment variable if it is not set or not equal to "12345"
|
||||||
BEGIN {
|
BEGIN {
|
||||||
no warnings 'uninitialized';
|
no warnings 'uninitialized';
|
||||||
$ENV{OPENAI_API_KEY}="12345" unless $ENV{OPENAI_API_KEY}eq"12345";
|
$ENV{OPENAI_API_KEY}="12345" unless $ENV{OPENAI_API_KEY}eq"12345";
|
||||||
|
$ENV{OPENAI_API_KEY} = "12345" unless $ENV{OPENAI_API_KEY} eq "12345";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Define a TestServer class that inherits from OpenAIAsync::Server
|
||||||
class TestServer {
|
class TestServer {
|
||||||
|
# Inherit methods and properties from OpenAIAsync::Server
|
||||||
inherit OpenAIAsync::Server;
|
inherit OpenAIAsync::Server;
|
||||||
|
|
||||||
|
# Apply methods from various OpenAIAsync::Server::API::Test modules
|
||||||
apply OpenAIAsync::Server::API::Test::ChatCompletion;
|
apply OpenAIAsync::Server::API::Test::ChatCompletion;
|
||||||
apply OpenAIAsync::Server::API::Test::Audio;
|
apply OpenAIAsync::Server::API::Test::Audio;
|
||||||
apply OpenAIAsync::Server::API::Test::Completions;
|
apply OpenAIAsync::Server::API::Test::Completions;
|
||||||
|
@ -33,12 +55,20 @@ class TestServer {
|
||||||
|
|
||||||
# Pick a random high port, TODO better scheme for this
|
# Pick a random high port, TODO better scheme for this
|
||||||
my $port = int(2048+rand(20480));
|
my $port = int(2048+rand(20480));
|
||||||
|
# Pick a random high port number between 2048 and 22528
|
||||||
|
my $port = int(2048 + rand(20480));
|
||||||
|
|
||||||
|
# Create an instance of the TestServer class that listens on localhost with the chosen port
|
||||||
my $server = TestServer->new(listen => '127.0.0.1', port => $port);
|
my $server = TestServer->new(listen => '127.0.0.1', port => $port);
|
||||||
|
|
||||||
|
# Create an instance of Net::Async::HTTP for making HTTP requests
|
||||||
my $http_client = Net::Async::HTTP->new();
|
my $http_client = Net::Async::HTTP->new();
|
||||||
|
|
||||||
|
# Add the $http_client and $server instances to the event loop
|
||||||
$loop->add($http_client);
|
$loop->add($http_client);
|
||||||
$loop->add($server);
|
$loop->add($server);
|
||||||
|
|
||||||
|
# Define a hash ref for the chat completion request data
|
||||||
my $chat_completion_input = {
|
my $chat_completion_input = {
|
||||||
"model" => "gpt-3.5-turbo",
|
"model" => "gpt-3.5-turbo",
|
||||||
"messages" => [
|
"messages" => [
|
||||||
|
@ -47,17 +77,24 @@ my $chat_completion_input = {
|
||||||
"temperature" => 0.7
|
"temperature" => 0.7
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Subroutine to make an HTTP POST request to the server
|
||||||
sub mk_req($uri, $content) {
|
sub mk_req($uri, $content) {
|
||||||
my $content_json = encode_json($content);
|
my $content_json = encode_json($content);
|
||||||
return $http_client->POST("http://127.0.0.1:$port/v1".$uri, $content_json, content_type => 'application/json');
|
return $http_client->POST("http://127.0.0.1:$port/v1".$uri, $content_json, content_type => 'application/json');
|
||||||
|
my $content_json = encode_json($content); # Encode the content data as JSON
|
||||||
|
return $http_client->POST("http://127.0.0.1:$port/v1{$uri}", $content_json, content_type => 'application/json'); # Make the POST request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make an HTTP POST request to the chat completions endpoint with the chat completion input data
|
||||||
my $res_fut = mk_req("/chat/completions", $chat_completion_input);
|
my $res_fut = mk_req("/chat/completions", $chat_completion_input);
|
||||||
|
|
||||||
|
# Delay the loop for 5 seconds to allow the request to complete
|
||||||
$loop->delay_future(after => 5)->get();
|
$loop->delay_future(after => 5)->get();
|
||||||
|
|
||||||
|
# Get the response object from the future
|
||||||
my $res = $res_fut->get();
|
my $res = $res_fut->get();
|
||||||
|
|
||||||
|
# Extract the response content
|
||||||
my $content = $res->content;
|
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");
|
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");
|
||||||
|
|
||||||
|
@ -65,3 +102,7 @@ is($content, '{"choices":[],"created":"0","id":"24601","model":"GumbyBrain-llm",
|
||||||
|
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
||||||
|
|
||||||
|
# Compare the response content to the expected content and provide a test message
|
||||||
|
is($content, '{"choices":[],"created":"0","id":"24601","model":"GumbyBrain-llm","object":"text_completion","
|
||||||
|
|
Loading…
Add table
Reference in a new issue