in reply to Re^2: perl hooks for AI
in thread perl hooks for AI

Check your API key!

I've modified your code for obtaining the API key and hardcoded it into the subroutine...with a valid API key, your code works for me. With an invalid key, I get the same error as you are seeing.

#!/usr/bin/perl use v5.030; use utf8; use AI::Embedding; my $ini_path = qw( /Users/mymac/Documents/1.тай&#108 +5;ый.txt ); # get key my $ref_config = get_api_key(); $DB::single = 1; my %h = %$ref_config; ## keep ^^^ this the same my $embedding = AI::Embedding->new( api => 'OpenAI', key => $h{key}, ); ## ^^^this works now ## this doesn't: my $csv_embedding = $embedding->embedding('I demand a shrubbery'); my $test_embedding = $embedding->test_embedding('We are the knights wh +o say nyet'); my @raw_embedding = $embedding->raw_embedding('great eddie murphy sho +w'); my $cmp = $embedding->comparator($csv_embedding); my $similarity = $cmp->($test_embedding); my $similarity_with_other_embedding = $embedding->compare($csv_embeddi +ng, $test_embedding); say $cmp; say $similarity; say $similarity_with_other_embedding; ## don't change anything about the subroutine sub get_api_key { return { 'key' => 'sk-abc123', }; } __END__

Output:

CODE(0x1cf363a5c48) -0.00931772883675172 -0.00931772883675168

In the next release, I will put some more helpful error message that directs the user to check their AP key...thanks for discovering this issue :)