NAME

OpenAI::API - A Perl module for accessing the OpenAI API

SYNOPSIS

use OpenAI::API;

my $openai = OpenAI::API->new( api_key => 'YOUR_API_KEY' );

my $response = $openai->completions(
    model             => 'text-davinci-003',
    prompt            => 'What is the capital of France?',
    max_tokens        => 2048,
    temperature       => 0.5,
    top_p             => 1,
    frequency_penalty => 0,
    presence_penalty  => 0
);

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_KEY environment variable instead.

See: Best Practices for API Key Safety.

endpoint (optional)

The endpoint URL for the OpenAI API. Default: 'https://api.openai.com/v1/'.

completions

Sends a request to the OpenAI API to generate text.

See 'https://beta.openai.com/docs/api-reference/completions/create'.

model

The name of the language model to use.

See 'https://beta.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.

SEE ALSO

OpenAI Reference Overview

AUTHOR

Nelson Ferraz <lt>nferraz@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2022 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.