Skip to content

karamusluk/OpenAI-GPT-3-API-Wrapper-for-PHP-8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI GPT-3 API Wrapper for PHP 8

License

PHP 8 Wrapper for OpenAI GPT-3 API.

Example usage:

<?php

require_once "../OpenAI.php";

$instance = new OpenAI(secretKey: 'Bearer <API_KEY>');

$prompt = "The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.

Human: Hello, who are you?
AI: I am an AI created by OpenAI. How can I help you today?
Human: ";

$instance->setDefaultEngine("ada"); // by default it is davinci
$res = $instance->complete(
    $prompt,
    150,
    [
        "stop"              => ["\n"],
        "temperature"       => 0.9,
        "frequency_penalty" => 0.6,
        "start_text"        => "\nAI:",
        "restart_text"      => "\nHuman: "
    ]
);

echo $res;
?>

Please check all examples.

Requirements

You need to give Open AI API key to the contructor as follows;

$instance = new OpenAI(secretKey: "Bearer <API_KEY>");

or

$instance = new OpenAI('Bearer <API_KEY>');

If you want to change the engine upon instance initialization;

$instance = new OpenAI(defaultEngine: "ada");

License

OpenAI GPT-3 API Wrapper for PHP 8 is released under the MIT License.

Releases

No releases published

Packages

No packages published

Languages