An API would be much more helpful :)
Hey stevie, how's tricks? Did you get stomped by winter storms? (They went north of me.)
I thought I was closing in on this:
#!/usr/bin/perl
use v5.030;
use utf8;
use LWP::UserAgent;
use JSON;
## get credentials
my $ini_path = qw( /Users/mymac/Documents/1.тайl
+5;ый.txt );
# get key
my $ref_config = get_тайный($ini_p
+ath);
$DB::single = 1;
my %h = %$ref_config;
## dial up server
# Your OpenAI API endpoint and token
my $api_url = 'https://api.openai.com/v1/engines/davinci-codex/complet
+ions'; # Replace with the correct API endpoint if needed
my $auth_token = $h{key};
# The prompt you want to send
my $prompt = "How many units are there in a mole?";
my $ua = LWP::UserAgent->new;
$ua->ssl_opts(
verify_hostname => 1,
SSL_ca_file => '/Users/mymac/Documents/cacert-2023-12-12.pem',
);
# Set up Request
my $req = HTTP::Request->new(POST => $api_url);
$req->header('Content-Type' => 'application/json');
$req->header('Authorization' => "Bearer $auth_token");
# Add the JSON-encoded data to the request
my $json_data = encode_json({ prompt => $prompt, max_tokens => 150 });
+ # Adjust the number of tokens as needed
$req->content($json_data);
# Perform the request
my $res = $ua->request($req);
# Check the outcome
if ($res->is_success) {
print $res->decoded_content;
} else {
print "Error: " . $res->status_line . "\n";
}
## don't change anything about this subroutine
sub get_тайный {
use Config::Tiny;
use Data::Dump;
my %h; #creating here and exporting reference to caller
my $ini_path = shift; #caller provides inipath
my $sub_hash1 = "openai";
my $Config = Config::Tiny->new;
$Config = Config::Tiny->read( $ini_path, 'utf8' );
# -> is optional between brackets
$h{email} = $Config->{$sub_hash1}{'email'};
$h{key} = $Config->{$sub_hash1}{'key'};
my $ref_config = \%h;
dd $ref_config;
$DB::single = 1;
return ($ref_config);
}
__END__
It comes back as a 404, and looks like this in the debugger:
main::(3.openai.pl:26): my $ua = LWP::UserAgent->new;
>> n
main::(3.openai.pl:27): $ua->ssl_opts(
main::(3.openai.pl:28): verify_hostname => 1,
main::(3.openai.pl:29): SSL_ca_file => '/Users/mymac/Docume
+nts/cacert-2023-12-12.pem',
>> s
LWP::UserAgent::ssl_opts(/System/Library/Perl/Extras/5.30/LWP/UserAgen
+t.pm:713):
713: my $self = shift;
>> r
void context return from LWP::UserAgent::ssl_opts
...
main::(3.openai.pl:46): if ($res->is_success) {
>> y
$api_url = 'https://api.openai.com/v1/engines/davinci-codex/completion
+s'
$auth_token = 'redacted but correct'
$json_data = '{"max_tokens":150,"prompt":"How many units are there in
+a mole?"}'
$prompt = 'How many units are there in a mole?'
...
$req = HTTP::Request=HASH(0x14103e258)
'_content' => '{"max_tokens":150,"prompt":"How many units are there
+ in a mole?"}'
'_headers' => HTTP::Headers=HASH(0x14105a110)
'::std_case' => HASH(0x131958040)
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
'authorization' => 'Bearer sk-...'
'content-type' => 'application/json'
'user-agent' => 'libwww-perl/6.44'
'_method' => 'POST'
'_uri' => URI::https=SCALAR(0x140444dc8)
-> 'https://api.openai.com/v1/engines/davinci-codex/completions'
'_uri_canonical' => URI::https=SCALAR(0x140444dc8)
-> REUSED_ADDRESS
$res = HTTP::Response=HASH(0x140698518)
'_content' => '{
"error": {
"message": "The model `davinci-codex` does not exist or you do
+ not have access to it.",
"type": "invalid_request_error",
"param": null,
"code": "model_not_found"
}
Fishing for tips,
|