OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API.
This project is a work-in-progress. Code and documentation are currently under development and are subject to change.
Requires PHP 8.1+
First, install OpenAI via the Composer package manager:
composer require openai-php/client dev-main
Then, interact with OpenAI's API:
$client = OpenAI::client('YOUR_API_KEY');
$result = $client->completions()->create([
'model' => 'davinci',
'prompt' => 'PHP is',
]);
echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.
Lists the currently available models, and provides basic information about each one such as the owner and availability.
$client->models()->list(); // ['data' => [...], ...]
Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
$client->models()->retrieve($model); // ['id' => 'text-davinci-002', ...]
Delete a fine-tuned model.
$client->models()->delete($model); // ['id' => 'curie:ft-acmeco-2021-03-03-21-44-20', ...]
Creates a completion for the provided prompt and parameters.
$client->completions()->create($parameters); // ['choices' => [...], ...]
Creates a new edit for the provided input, instruction, and parameters.
$client->edits()->create(); // ['choices' => [...], ...]
Creates an embedding vector representing the input text.
$client->embeddings()->create(); // ['data' => [...], ...]
Returns a list of files that belong to the user's organization.
$client->files()->list(); // ['data' => [...], ...]
Delete a file.
$client->files()->delete($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]
Returns information about a specific file.
$client->files()->retrieve($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]
Upload a file that contains document(s) to be used across various endpoints/features.
$client->files()->upload([
'purpose' => 'fine-tune',
'file' => fopen('my-file.jsonl', 'r'),
]); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]
Returns the contents of the specified file.
$client->files()->download($file); // '{"prompt": "<prompt text>", ...'
Creates a job that fine-tunes a specified model from a given dataset.
$client->fineTunes()->create($parameters); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]
List your organization's fine-tuning jobs.
$client->fineTunes()->list(); // ['data' => [...], ...]
Gets info about the fine-tune job.
$client->fineTunes()->retrieve($fineTuneId); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]
Immediately cancel a fine-tune job.
$client->fineTunes()->cancel($fineTuneId); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]
Get fine-grained status updates for a fine-tune job.
$client->fineTunes()->listEvents($fineTuneId); // ['data' => [...], ...]
Classifies if text violates OpenAI's Content Policy.
$client->moderations()->create($parameters); // ['id' => 'modr-5MWoLO', ...]
OpenAI PHP is an open-sourced software licensed under the MIT license.