AI::Chat - Interact with AI Chat APIs
Version 0.2
use AI::Chat; my $chat = AI::Chat->new( key => 'your-api-key', api => 'OpenAI', model => 'gpt-3.5-turbo-0125', ); my $reply = $chat->prompt("What is the meaning of life?"); print $reply;
This module provides a simple interface for interacting with AI Chat APIs, currently supporting OpenAI.
The AI chat agent can be given a role and then passed prompts. It will reply to the prompts in natural language. Being AI, the responses are non-deterministic, that is, the same prompt will result in diferent responses on different occasions.
Further control of the creativity of the responses is possible by specifying at optional temperature parameter.
A free OpenAI API can be obtained from https://platform.openai.com/account/api-keys
Although the API Key is free, each use incurs a cost. This is dependent on the number of tokens in the prompt and the reply. Different models have different costs. The default model gpt-3.5-turbo-0125 is the lowest cost of the useful models and is a good place to start using this module.
gpt-3.5-turbo-0125
See also https://platform.openai.com/docs/models/overview
my $chat = AI::Chat->new(%params);
Creates a new AI::Chat object.
required Your API key for the chosen service.
required
The API to use (currently only 'OpenAI' is supported).
The language model to use (default: 'gpt-3.5-turbo-0125').
See https://platform.openai.com/docs/models/overview
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".
Used for testing. If set to any true value, the prompt method will return details of the error encountered instead of undef
undef
my $reply = $chat->prompt($prompt, $temperature);
Sends a prompt to the AI Chat API and returns the response.
required The prompt to send to the AI.
The creativity level of the response (default: 1.0).
Temperature ranges from 0 to 2. The higher the temperature, the more creative the bot will be in it's responses.
my $success = $chat->success();
Returns true if the last operation was successful.
my $error = $chat->error();
Returns the error message if the last operation failed.
https://openai.com - OpenAI official website
Ian Boddison <ian at boddison.com>
Please report any bugs or feature requests to bug-ai-chat at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=bug-ai-chat. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-ai-chat at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc AI::Chat
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=AI-Chat
Search CPAN
https://metacpan.org/release/AI::Chat
Copyright (C) 2024 by Ian Boddison
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install AI::Chat, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::Chat
CPAN shell
perl -MCPAN -e shell install AI::Chat
For more information on module installation, please visit the detailed CPAN module installation guide.