GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
OpenAI::API(3) User Contributed Perl Documentation OpenAI::API(3)

OpenAI::API - Perl interface to OpenAI API

    use OpenAI::API;
    my $openai = OpenAI::API->new();    # uses OPENAI_API_KEY environment variable
    my $res = $openai->chat(
        messages => [
            { "role" => "system",    "content" => "You are a helpful assistant." },
            { "role" => "user",      "content" => "How can I access OpenAI's APIs in Perl?" },
            { "role" => "assistant", "content" => "You can use the OpenAI::API module." },
            { "role" => "user",      "content" => "Where can I find this module?" },
        ],
        max_tokens  => 20,
        temperature => 0,
    );
    my $message = $res->{choices}[0]{message};    # or simply: my $message = "$res";

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 <https://platform.openai.com>.

OpenAI::API acts as a high-level interface for the OpenAI API, handling different actions while utilizing the configuration class.

new()

Creates a new OpenAI::API object.

config [optional]

An OpenAI::API::Config object including the following properties:

  • 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 <https://help.openai.com/en/articles/5112595-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.

chat()

Chat request.

completions()

Completion request.

edits()

Edit request.

embeddings()

Embedding request.

files()

File List request.

file_retrieve()

File Retrieve request.

image_create()

Image Generation request.

models()

Model List request.

model_retrieve()

Model Retrieve request.

moderations()

Moderation request.

  • 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 <https://platform.openai.com/docs/api-reference/overview>

Nelson Ferraz <nferraz@gmail.com>

This module is developed on GitHub <https://github.com/nferraz/perl-openai-api>.

Send ideas, feedback, tasks, or bugs to GitHub Issues <https://github.com/nferraz/perl-openai-api/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.

2023-04-09 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.