|
| 1 | +<p align="center"> |
| 2 | + <img src="https://raw.githubusercontent.com/openai-php/art/master/editor-without-bg.png" width="600" alt="OpenAI PHP"> |
| 3 | + <p align="center"> |
| 4 | + <a href="https://github.com/openai-php/openAI/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/openai-php/openAI/Tests/master"></a> |
| 5 | + <a href="https://packagist.org/packages/openai-php/openAI"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/openai-php/openAI"></a> |
| 6 | + <a href="https://packagist.org/packages/openai-php/openAI"><img alt="Latest Version" src="https://img.shields.io/packagist/v/openai-php/openAI"></a> |
| 7 | + <a href="https://packagist.org/packages/openai-php/openAI"><img alt="License" src="https://img.shields.io/packagist/l/openai-php/openAI"></a> |
| 8 | + </p> |
| 9 | +</p> |
| 10 | + |
| 11 | +------ |
| 12 | +**OpenAI PHP** is a supercharged PHP API client that allows you to interact with the [Open AI API](https://beta.openai.com/docs/api-reference/introduction). |
| 13 | + |
| 14 | +> This project is a work-in-progress. Code and documentation are currently under development and are subject to change. |
| 15 | +
|
| 16 | +## Get Started |
| 17 | + |
| 18 | +> **Requires [PHP 8.1+](https://php.net/releases/)** |
| 19 | +
|
| 20 | +First, install OpenAI via the [Composer](https://getcomposer.org/) package manager: |
| 21 | + |
| 22 | +```bash |
| 23 | +composer require openai-php/client dev-master |
| 24 | +``` |
| 25 | + |
| 26 | +Then, interact with OpenAI's API: |
| 27 | + |
| 28 | +```php |
| 29 | +$client = OpenAI::client('YOUR_API_KEY'); |
| 30 | + |
| 31 | +$result = $client->completions()->create([ |
| 32 | + 'model' => 'davinci', |
| 33 | + 'prompt' => 'PHP is', |
| 34 | +]); |
| 35 | + |
| 36 | +echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language. |
| 37 | +``` |
| 38 | + |
| 39 | +## TODO |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +- [x] Models |
| 44 | +- [x] Completions |
| 45 | +- [x] Edits |
| 46 | +- [x] Embeddings |
| 47 | +- [ ] Files |
| 48 | +- [ ] FineTunes |
| 49 | +- [ ] Moderations |
| 50 | +- [ ] Classifications |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +### `Models` Resource |
| 55 | + |
| 56 | +#### `list` |
| 57 | + |
| 58 | +Lists the currently available models, and provides basic information about each one such as the owner and availability. |
| 59 | + |
| 60 | +```php |
| 61 | +$client->models()->list(); // ['data' => [...], ...] |
| 62 | +``` |
| 63 | + |
| 64 | +#### `retrieve` |
| 65 | + |
| 66 | +Retrieves a model instance, providing basic information about the model such as the owner and permissioning. |
| 67 | + |
| 68 | +```php |
| 69 | +$client->models()->retrieve($model); // ['id' => 'text-davinci-002', ...] |
| 70 | +``` |
| 71 | + |
| 72 | +### `Completions` Resource |
| 73 | + |
| 74 | +#### `create` |
| 75 | + |
| 76 | +Creates a completion for the provided prompt and parameters. |
| 77 | + |
| 78 | +```php |
| 79 | +$client->completions()->create($parameters); // ['choices' => [...], ...] |
| 80 | +``` |
| 81 | + |
| 82 | +### `Edits` Resource |
| 83 | + |
| 84 | +#### `create` |
| 85 | + |
| 86 | +Creates a new edit for the provided input, instruction, and parameters. |
| 87 | + |
| 88 | +```php |
| 89 | +$client->edits()->create(); // ['choices' => [...], ...] |
| 90 | +``` |
| 91 | + |
| 92 | +### `Embeddings` Resource |
| 93 | + |
| 94 | +#### `create` |
| 95 | + |
| 96 | +Creates an embedding vector representing the input text. |
| 97 | + |
| 98 | +```php |
| 99 | +$client->embeddings()->create(); // ['data' => [...], ...] |
| 100 | +``` |
| 101 | + |
| 102 | +### `Files` Resource |
| 103 | + |
| 104 | +#### `list` |
| 105 | + |
| 106 | +Returns a list of files that belong to the user's organization. |
| 107 | + |
| 108 | +```php |
| 109 | +$client->files()->list(); // ['data' => [...], ...] |
| 110 | +``` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +OpenAI PHP is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**. |
0 commit comments