OpenAI::API - Perl interface to OpenAI API
use OpenAI::API; use OpenAI::API::Request::Chat; my $config = OpenAI::API->new(); # uses OPENAI_API_KEY environment variable my $request = OpenAI::API::Request::Chat->new( model => "gpt-3.5-turbo", messages => [ { "role" => "system", "content" => "You are a helpful assistant." }, { "role" => "user", "content" => "Who won the world series in 2020?" }, { "role" => "assistant", "content" => "The Los Angeles Dodgers won the World Series in 2020." }, { "role" => "user", "content" => "Where was it played?" } ], ); my $res = $request->send($config); my $message = $res->{choices}[0]{message};
OpenAI::API is a Perl module that provides an interface to the OpenAI API, which allows you to generate text, translate languages, summarize text, and perform other tasks using the language models developed by OpenAI.
To use the OpenAI::API module, you will need an API key, which you can obtain by signing up for an account on the OpenAI website.
Creates a new OpenAI::API object.
api_key [optional]
Your API key. Default: $ENV{OPENAI_API_KEY}.
$ENV{OPENAI_API_KEY}
Attention: never commit API keys to your repository. Use the OPENAI_API_KEY environment variable instead.
OPENAI_API_KEY
See: Best Practices for API Key Safety.
api_base [optional]
The api_base URL for the OpenAI API. Default: 'https://api.openai.com/v1/'.
timeout [optional]
The timeout value, in seconds. Default: 60 seconds.
OpenAI::API::Request::Chat
OpenAI::API::Request::Completion
OpenAI::API::Request::Edit
OpenAI::API::Request::Embedding
OpenAI::API::Request::File::List
OpenAI::API::Request::File::Retrieve
OpenAI::API::Request::Image::Generation
OpenAI::API::Request::Model::List
OpenAI::API::Request::Model::Retrieve
OpenAI::API::Request::Moderation
OpenAI Reference Overview
Nelson Ferraz <nferraz@gmail.com>
This module is developed on GitHub.
Send ideas, feedback, tasks, or bugs to GitHub Issues.
Copyright (C) 2022, 2023 by Nelson Ferraz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.30.2 or, at your option, any later version of Perl 5 you may have available.
To install OpenAI::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenAI::API
CPAN shell
perl -MCPAN -e shell install OpenAI::API
For more information on module installation, please visit the detailed CPAN module installation guide.