Skip to content

siteorigin/openai-api

develop
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

A PHP wrapper for the OpenAI API

Latest Version on Packagist PHP Version Requirement GitHub Tests Action Status GitHub Code Style Action Status Total Downloads


GPT-3 lets you inject a little bit of AI magic into your apps, and this PHP wrapper makes it even easier to access. Covers the entire OpenAI API, in a familiar PHP way, without limiting any functionality.

use SiteOrigin\OpenAI\Client;
$client = new Client($_ENV['OPENAI_API_KEY']);
$completions = $client->completions('davinci')->complete("The most important technology for humanity is", [
    'max_tokens' => 32,
    'temperature' => 0.8,
    'n' => 4,
    'stop' => ["\n", '.']
]);
foreach($completions as $c) {
    echo $c->text . "\n";
}

Read more on the documentation wiki.

Installation

You can install the package via composer:

composer require siteorigin/openai-api

Usage

For most of the features of this wrapper, you should have an understanding of the OpenAI API.

// Set up a client with your API key.
use SiteOrigin\OpenAI\Client;
use SiteOrigin\OpenAI\Models;

$client = new Client($_ENV['OPENAI_API_KEY']);

// Create a completion call
$c = $client->completions(Models::BABBAGE)->complete('The meaning of life is: ', [ /* ... */]);

// List all the available engines
$e = $client->engines()->list();

// Classify safe/unsafe content
$f = $client->filter()->classify('ponies are fantastic!'); // 'safe'

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please email greg@siteorigin.com if you find any security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

PHP wrapper for the OpenAI API.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages