in reply to Re^2: Artificial Intelligence with Perl in 2023
in thread Artificial Intelligence with Perl in 2023

$chat->prompt($prompt, $TEMP);
is returning undefined.

Have you tried checking $chat->success?

promt returns undef if no prompt parameter is supplied - or more precisely, if the prompt parameter is not a non-zero length string.

Replies are listed 'Best First'.
Re^4: Artificial Intelligence with Perl in 2023
by Danny (Chaplain) on Mar 03, 2024 at 20:07 UTC
    Yes. $chat->success() is true in the following. But $reply is undef.

    It's probably because I haven't properly set up my openai account. I got the api key but I probably need to give it my credit card or something.

    The following

    my $chat = AI::Chat->new(%h); $chat->success() or die sprintf "error 1: %s\n", $chat->error(); print "$chat\n"; my $reply = $chat->prompt($prompt, $TEMP); $chat->success() or die sprintf "error 2: %s\n", $chat->error(); defined $reply or die sprintf "error 3: %s\n", $chat->error();
    prints:
    AI::Chat=HASH(0xa0042da30) error 3:

      I've just uploaded version 0.2 to CPAN

      This new version has a new debug parameter. When this is true, the prompt method returns the full error if there is one instead of under.

        Yep, debug=>1 told me "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.".

        It looks like it did give me the $18 when I first created a chatGPT account over a year ago, but I think that had an expiration date if not used.

      I got the api key but I probably need to give it my credit card or something

      When I set up our API key, I got $18 credit. I'm not sure if you still do as it was quite a while since I got the key.

      The API calls are not costly. Most requests to the chat API come in at under $0.01.