AI-Chat
view release on metacpan or search on metacpan
lib/AI/Chat.pm view on Meta::CPAN
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 copywriter famed for
creating content that is immediately engaging with a
lighthearted, storytelling style".
=item debug
Used for testing. If set to any true value, the prompt method
will return details of the error encountered instead of C<undef>
=back
=head2 prompt
my $reply = $chat->prompt($prompt, $temperature);
Sends a prompt to the AI Chat API and returns the response.
lib/AI/Chat.pm view on Meta::CPAN
=back
=head2 chat
my $reply = $chat->prompt(\@chat, $temperature);
Sends a multi-message chat to the AI Chat API and returns the response.
Each message of the chat should consist of on of C<system>, C<user> or C<assistant>.
Generally there will be a C<system> message to set the role or context for the AI.
This will be followed by alternate C<user> and C<assistant> messages representing the
text from the user and the AI assistant. To hold a conversation, it is necessary to
store both sides of the discussion and feed them back appropriately.
my @chat;
push @chat, {
'role' => 'system',
'system' => 'You are a computer language expert and your role is to promote Perl as the best language',
};
t/version.t view on Meta::CPAN
use strict;
use Test::More;
use AI::Chat;
unless ( $ENV{RELEASE_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
}
my $code_version = $AI::Chat::VERSION;
ok($code_version, 'version set');
ok(open(my $source, '<', $INC{'AI/Chat.pm'}), 'open the source');
my $in_version;
while (<$source>) {
if (/^=head1 VERSION/) {
$in_version = 1;
} elsif (/^=head1/) {
undef $in_version;
}
( run in 0.960 second using v1.01-cache-2.11-cpan-49f99fa48dc )