NAME
OpenAI::API - A Perl module for accessing the OpenAI API
SYNOPSIS
use OpenAI::API;
my $openai = OpenAI::API->new(); # uses OPENAI_API_KEY environment variable
my $completions = $openai->completions(
model => 'text-davinci-003',
prompt => 'What is the capital of France?',
);
my $edits = $openai->edits(
model => 'text-davinci-edit-001',
input => 'What day of the wek is it?',
instruction => 'Fix the spelling mistakes',
);
my $moderations = $openai->moderations(
model => 'text-moderation-latest',
input => 'I want to kill them.',
);
DESCRIPTION
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.
METHODS
new()
Creates a new OpenAI::API object.
api_key [optional]
Your API key. Default:
$ENV{OPENAI_API_KEY}.Attention: never commit API keys to your repository. Use the
OPENAI_API_KEYenvironment variable instead.endpoint [optional]
The endpoint URL for the OpenAI API. Default: 'https://api.openai.com/v1/'.
completions()
Given a prompt, the model will return one or more predicted completions.
Documentation: Completions
model
The name of the language model to use.
See 'https://platform.openai.com/docs/api-reference/models'.
prompt
The prompt for the text generation.
max_tokens [optional]
The maximum number of tokens to generate.
temperature [optional]
The temperature to use for sampling.
top_p [optional]
The top-p value to use for sampling.
frequency_penalty [optional]
The frequency penalty to use for sampling.
presence_penalty [optional]
The presence penalty to use for sampling.
edits()
Creates a new edit for the provided input, instruction, and parameters.
Documentation: Edits
model
ID of the model to use. You can use the text-davinci-edit-001 or code-davinci-edit-001 model with this endpoint.
input [optional]
The input text to use as a starting point for the edit.
instruction
The instruction that tells the model how to edit the prompt.
n [optional]
How many edits to generate for the input and instruction.
temperature [optional]
What sampling temperature to use, between 0 and 2.
top_p [optional]
An alternative to sampling with temperature.
embeddings()
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
Documentation: Embeddings
model
input
user [optional]
moderations()
Given a input text, outputs if the model classifies it as violating OpenAI's content policy.
Documentation: Moderations
input
model [optional]
SEE ALSO
AUTHOR
Nelson Ferraz <lt>nferraz@gmail.com>
COPYRIGHT AND LICENSE
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.