Skip to content

⚡️ OpenAI PHP is a supercharged PHP API client that allows you to interact with OpenAI API.

License

Notifications You must be signed in to change notification settings

MohammadAlhallaq/client

 
 

Repository files navigation

OpenAI PHP

GitHub Workflow Status (master) Total Downloads Latest Version License


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.

Get Started

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.

TODO

  • Models
  • Completions
  • Edits
  • Embeddings
  • Files
  • FineTunes
  • Moderations
  • Classifications

Usage

Models Resource

list

Lists the currently available models, and provides basic information about each one such as the owner and availability.

$client->models()->list(); // ['data' => [...], ...]

retrieve

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

$client->models()->retrieve($model); // ['id' => 'text-davinci-002', ...]

Completions Resource

create

Creates a completion for the provided prompt and parameters.

$client->completions()->create($parameters); // ['choices' => [...], ...]

Edits Resource

create

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

$client->edits()->create(); // ['choices' => [...], ...]

Embeddings Resource

create

Creates an embedding vector representing the input text.

$client->embeddings()->create(); // ['data' => [...], ...]

Files Resource

list

Returns a list of files that belong to the user's organization.

$client->files()->list(); // ['data' => [...], ...]

delete

Delete a file.

$client->files()->delete($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]

retrieve

Returns information about a specific file.

$client->files()->retrieve($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]

download

Returns the contents of the specified file.

$client->files()->download($file); // '{"prompt": "<prompt text>", ...'

OpenAI PHP is an open-sourced software licensed under the MIT license.

About

⚡️ OpenAI PHP is a supercharged PHP API client that allows you to interact with OpenAI API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%