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::Request(3) User Contributed Perl Documentation OpenAI::API::Request(3)

OpenAI::API::Request - Base module for making requests to the OpenAI API

This module is a base module for making HTTP requests to the OpenAI API. It should not be used directly.

    package OpenAI::API::Request::NewRequest;
    use Moo;
    extends 'OpenAI::API::Request';
    sub endpoint {
        '/my_endpoint'
    }
    sub method {
        'POST'
    }
    # somewhere else...
    use OpenAI::API::Request::NewRequest;
    my $req = OpenAI::API::Request::NewRequest->new(...);
    my $res = $req->send();    # or: my $res = $req->send_async();

This module provides a base class for creating request objects for the OpenAI API. It includes methods for sending synchronous and asynchronous requests, with support for HTTP GET and POST methods.

An instance of OpenAI::API::Config that provides configuration options for the OpenAI API client. Defaults to a new instance of OpenAI::API::Config.

An instance of LWP::UserAgent that is used to make HTTP requests. Defaults to a new instance of LWP::UserAgent with a timeout set to the value of "config->timeout".

An instance of an event loop class, specified by "config->event_loop_class" option.

This method must be implemented by subclasses. It should return the API endpoint for the specific request.

This method must be implemented by subclasses. It should return the HTTP method for the specific request.

This method sends the request and returns the parsed response. If the 'http_response' key is present in the %args hash, it returns the raw HTTP::Response object instead of the parsed response.

    my $response = $request->send();
    my $response = $request->send( http_response => 1 );

This method sends the request asynchronously and returns a IO::Async::Future object. If the 'http_response' key is present in the %args hash, it resolves to the raw HTTP::Response object instead of the parsed response.

Here's an example usage:

    use IO::Async::Loop;
    my $loop = IO::Async::Loop->new();
    my $future = $request->send_async()->then(
        sub {
            my $content = shift;
            # ...
        }
    )->catch(
        sub {
            my $error = shift;
            # ...
        }
    );
    $loop->await($future);
    my $res = $future->get;

Note: if you want to use a different event loop, you must pass it via the config attribute.

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.