OpenAI API Wrapper

from 0$

OpenAI API Wrapper is a WP Plugin from the Software Development Kits range

For more information about a tailored WP Plugin like OpenAI API Wrapper please contact us directly.

Overview

Fully open-source and secure community-maintained, PHP SDK for accessing the OpenAI GPT-3 API.

Note: The autoloader of this wrapper is not included automatically.

Autoload

Use the following path to include the classes before your code:

require_once WP_PLUGIN_DIR . '/openai-api-wrapper/vendor/autoload.php';

Alternatively use the following action to autoload the classes:

do_action('wp2e_autoload_openai-api-wrapper');

Quick Examples

Instantiate an OpenAI client

use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi(OPEN_AI_API_KEY);

Predicted completions

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

$complete = $open_ai->completion([
    'model' => 'davinci',
    'prompt' => 'Hello',
    'temperature' => 0.9,
    'max_tokens' => 150,
    'frequency_penalty' => 0,
    'presence_penalty' => 0.6,
]);

Statement Correction

Creates a new edit for the provided input, instruction, and parameters.

   $result = $open_ai->createEdit([
       "model" => "text-davinci-edit-001",
       "input" => "What day of the wek is it?",
       "instruction" => "Fix the spelling mistakes",
   ]);

Create image (DALL-E)

Creates an image given a prompt.

$complete = $open_ai->image([
   "prompt" => "A cat drinking milk",
   "n" => 1,
   "size" => "256x256",
   "response_format" => "url",
]);

Useful Links

A Software Development Kit (SDK) is a collection of software development tools in one installable package.

This script is completely standalone and does not do anything after installing it. As such this is a light-weight module for easy inclusion into a bigger project.