When I run the script below as:
gpt.pl "what is the meaning of life"
$chat->prompt($prompt, $TEMP);
is returning undefined.
what is the meaning of life Use of uninitialized value $reply in concatenation (.) or string at /h +ome/****/com/gpt.pl line 25.
#!/usr/bin/env perl my @BOOL = qw(false true); my $VERBOSE = 0; use warnings; use strict; use Getopt::Long; use AI::Chat; our $KEY = "my-key"; our $API = "OpenAI"; our $MODEL = "gpt-3.5-turbo-0125"; our $ROLE = undef; our $TEMP = 1.0; my ($prompt) = parseArgs(); my %h = (key => $KEY, api => $API, model => $MODEL); defined $ROLE and $h{role} = $ROLE; my $chat = AI::Chat->new(%h); my $reply = $chat->prompt($prompt, $TEMP); print "$prompt\n\n"; print "$reply\n"; sub parseArgs { my @args = qw(prompt); my $usage = qq{usage: $0 @args [options] prompt should be a quoted string. options ------- -key (default: $KEY) API key -role The role to use for the bot in conversations. This tells the bot + what it's purpose when answering prompts. For example: "You are a world class c +opywriter famed for creating content that is immediately engaging with a lighth +earted, storytelling style". -temperature (default: $TEMP) The creativity level of the response (de +fault: 1.0). Temperature ranges from 0 to 2. The higher the temperature, the + more creative the bot will be in it's responses. -verbose (default: $BOOL[$VERBOSE]) }; my $result = GetOptions ( 'key=s' => \$KEY, 'role=s' => \$ROLE, 'temperature=f' => \$TEMP, 'verbose!' => \$VERBOSE, ); $result or print $usage and exit; @ARGV == @args or print $usage and exit; return @ARGV; }

In reply to Re^2: Artificial Intelligence with Perl in 2023 by Danny
in thread Artificial Intelligence with Perl in 2023 by ait

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.