#!/usr/bin/perl use v5.030; use utf8; use LWP::UserAgent; use JSON; ## get credentials my $ini_path = qw( /Users/mymac/Documents/1.тайный.txt ); # get key my $ref_config = get_тайный($ini_path); $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/completions'; # 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__