dneustadt / openai-client
Client for OpenAI API
0.2.2
2022-11-05 20:03 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.12
- phpunit/phpunit: ^8.0 || ^9.0
- symfony/dotenv: ^6.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
OpenAI is an AI research and deployment company. Our mission is to ensure that artificial general intelligence benefits all of humanity.
Installation & Usage
Requirements
PHP 7.2 and later.
Composer
To install via Composer:
composer require dneustadt/openai-client
Getting Started
Please follow the installation procedure and then run the following:
<?php require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: api_key $config = OpenAI\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY'); $apiInstance = new OpenAI\Client\Api\AnswerApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $open_ai_organization = 'open_ai_organization_example'; // optional $answer_payload = new \OpenAI\Client\Model\AnswerPayload(); // \OpenAI\Client\Model\AnswerPayload try { $result = $apiInstance->postAnswer($open_ai_organization, $answer_payload); print_r($result); } catch (Exception $e) { echo 'Exception when calling AnswerApi->postAnswer: ', $e->getMessage(), PHP_EOL; }
API Endpoints
All URIs are relative to https://api.openai.com/v1
| Class | Method | HTTP request | Description |
|---|---|---|---|
| AnswerApi | postAnswer | POST /answers | Answers the specified question using the provided documents and examples. |
| ClassificationApi | postClassification | POST /classifications | The endpoint first searches over the labeled examples to select the ones most relevant for the particular query. Then, the relevant examples are combined with the query to construct a prompt to produce the final label via the completions endpoint. |
| CompletionsApi | postCompletions | POST /engines/{engine_id}/completions | Creates a new completion for the provided prompt and parameters |
| EmbeddingsApi | postEmbeddings | POST /embeddings | Creates an embedding vector representing the input text. |
| EnginesApi | getEngineById | GET /engines/{engine_id} | Retrieves an engine instance, providing basic information about the engine such as the owner and availability. |
| EnginesApi | getEngines | GET /engines | Lists the currently available engines, and provides basic information about each one such as the owner and availability. |
| FilesApi | deleteFile | DELETE /files/{file_id} | Delete a file. |
| FilesApi | getFileById | GET /files/{file_id} | Returns information about a specific file. |
| FilesApi | getFiles | GET /files | Returns a list of files that belong to the user's organization. |
| FilesApi | postFile | POST /files | Upload a file that contains document(s) to be used across various endpoints/features. |
| FineTunesApi | getFineTune | GET /fine-tunes/{fine_tune_id} | Gets info about the fine-tune job. |
| FineTunesApi | getFineTuneEvents | GET /fine-tunes/{fine_tune_id}/events | Get fine-grained status updates for a fine-tune job. |
| FineTunesApi | getFineTunes | GET /fine-tunes | List your organization's fine-tuning jobs |
| FineTunesApi | postFineTuneCancel | POST /fine-tunes/{fine_tune_id}/cancel | Immediately cancel a fine-tune job. |
| FineTunesApi | postFineTunes | POST /fine-tunes | Creates a job that fine-tunes a specified model from a given dataset. |
| ImagesApi | postImagesEdits | POST /images/edits | Creates an edited or extended image given an original image and a prompt. |
| ImagesApi | postImagesGenerations | POST /images/generations | Given a prompt and/or an input image, the model will generate a new image. |
| ImagesApi | postImagesVariations | POST /images/variations | Creates a variation of a given image. |
| ModelsApi | deleteModel | DELETE /models/{model} | Delete a fine-tuned model. You must have the Owner role in your organization. |
| ModelsApi | getModel | GET /models/{model} | Retrieves a model instance, providing basic information about the model such as the owner and permissioning. |
| ModelsApi | getModels | GET /models | Lists the currently available models, and provides basic information about each one such as the owner and availability. |
| ModerationsApi | postModerations | POST /moderations | Classifies if text violates OpenAI's Content Policy |
| SearchApi | postSearch | POST /search | The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. |
Models
Request Payloads
- AnswerPayload
- ClassificationPayload
- CompletionPayload
- ImagesGenerationsPayload
- SearchPayload
- EmbeddingsPayload
- FineTunesPayload
- ModerationsPayload