Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 25cc98c

Browse files
committed
Initial commit
0 parents  commit 25cc98c

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# OpenAI REST API Client
2+
3+
## Introduction
4+
5+
The **OpenAI REST API Client** is a package that provides a simple and convenient way to interact with the **OpenAI API** from your PHP application.
6+
7+
This package can be purchased from [https://tectalic.com/apis/openai](https://tectalic.com/apis/openai).
8+
9+
## License
10+
11+
This software is copyright (c) [Tectalic](https://tectalic.com).
12+
13+
For the full copyright and license information, please view the *LICENSE* file that was distributed with the source code.
14+
15+
## System Requirements
16+
17+
- PHP version 7.2.5 or newer.
18+
- [PHP JSON extension](https://www.php.net/manual/en/json.installation.php) installed.
19+
- A PSR-18 compatible HTTP client such as Guzzle or the Symfony HttpClient.
20+
21+
## Installation
22+
23+
To install this package into your PHP project, we recommend using [Composer](http://getcomposer.org/).
24+
25+
Please [see here for detailed instructions on how to configure your project to access the Tectalic Composer repository](https://tectalic.com/products/openai#composer-integration). You will need to log into the Tectalic account that purchased the **OpenAI REST API Client** package in order to access these instructions.
26+
27+
Once you have authenticated composer using the above instructions, run the following command:
28+
29+
`composer require tectalic/openai ^TODO`
30+
31+
Then run the following command to install the *OpenAI REST API Client* into your project:
32+
33+
`composer install`
34+
35+
Ensure you have also installed into your project a [compatible PSR-18 HTTP Client](https://packagist.org/providers/psr/http-client-implementation) such as Guzzle or the Symfony HttpClient.
36+
37+
### Manual Installation
38+
39+
TODO: Finalise instructions for manual installation. How does it work as the downloaded zip file does not include the product's dependencies?
40+
41+
[Download the latest release from here](https://tectalic.com/products/openai) and extract it into your PHP project.
42+
43+
Then include the OpenAI REST API Client `autoload.php` file:
44+
45+
```php
46+
require_once('/path/to/your-project/openai/autoload.php');
47+
```
48+
49+
## Getting Started
50+
51+
After installing the package into your project, you can use the following code sample and customize it to suit your application.
52+
53+
```php
54+
// Load your project's composer autoloader (if you aren't already doing so).
55+
require_once(__DIR__ . '/vendor/autoload.php');
56+
```
57+
58+
```php
59+
use Tectalic\OpenAI\Authentication;
60+
use Tectalic\OpenAI\Client;
61+
use Tectalic\OpenAI\Manager;
62+
63+
// Fluent interface
64+
$auth = new Authentication(TODO: auth params);
65+
$client = Manager::build($httpClient, $auth);
66+
// TODO: method parameters, use only a get() method?
67+
$client->answers()->create()->toModel();
68+
```
69+
70+
## Authentication
71+
To authenticate your API requests, you will need to provide an `Authentication` (`$auth`) object when calling `Manager::build()`.
72+
73+
Authentication to the **OpenAI API** is by TODO auth type.
74+
75+
In the **Getting Started** code above, customize the `Authentication` constructor to your needs. For example, you may wish to define your API key in an environment variable, and pass it to the constructor.
76+
77+
## Client Class
78+
79+
The primary class that you will interact with is the `Client` class (`Tectalic\OpenAI\Client`).
80+
81+
This `Client` class also contains the helper methods that lets you easily access the 6 handler(s).
82+
83+
Please see below for a full list of supported handlers and methods.
84+
85+
## Supported Handlers and Methods
86+
87+
This package supports 6 handlers(s) and a total of 10 method(s). See the following table for details.
88+
89+
TODO: add parameter(s) to Method Name column
90+
91+
| Handler Class Name | Handler URL | HTTP Verb | Method Name | Description | PHP Code |
92+
| ------------------- | ------------ | --------- | ----------- | ----------- | -------- |
93+
|`Tectalic\OpenAI\Handler\Answers`|`/answers`|`post`|`create()`|Create answer<br /><br />Answers the specified question using the provided documents and examples.<br /><br />The endpoint first [searches](https://beta.openai.com/docs/api-reference/searches) over provided documents or files to find relevant context.<br />The relevant context is combined with the provided examples and question to create the prompt for [completion](https://beta.openai.com/docs/api-reference/completions).<br /><br />[See More](https://beta.openai.com/docs/api-reference/classifications/create)|`$client->answers()->create()->toModel()`|
94+
|`Tectalic\OpenAI\Handler\Classifications`|`/classifications`|`post`|`create()`|Create classification<br /><br />Classifies the specified query using provided examples.<br /><br />The endpoint first [searches](https://beta.openai.com/docs/api-reference/searches) over the labeled examples to select the ones most relevant for the particular query.<br />Then, the relevant examples are combined with the query to construct a prompt to produce the final label via the [completions](https://beta.openai.com/docs/api-reference/completions) endpoint.<br /><br />Labeled examples can be provided via an uploaded file, or explicitly listed in the request using the examples parameter for quick tests and small scale use cases.<br /><br />[See More](https://beta.openai.com/docs/api-reference/classifications/create)|`$client->classifications()->create()->toModel()`|
95+
|`Tectalic\OpenAI\Handler\Engines`|`/engines`|`get`|`list()`|List engines<br /><br />Lists the currently available engines, and provides basic information about each one such as the owner and availability.<br /><br />[See More](https://beta.openai.com/docs/api-reference/engines/list)|`$client->engines()->list()->toModel()`|
96+
|`Tectalic\OpenAI\Handler\Engines`|`/engines/{engineId}`|`get`|`get()`|Retrieve engine<br /><br />Retrieves an engine instance, providing basic information about the engine such as the owner and availability.<br /><br />[See More](https://beta.openai.com/docs/api-reference/engines/retrieve)|`$client->engines()->get()->toModel()`|
97+
|`Tectalic\OpenAI\Handler\EnginesCompletions`|`/engines/{engineId}/completions`|`post`|`create()`|Create completion<br /><br />Creates a new completion for the provided prompt and parameters.<br /><br />[See More](https://beta.openai.com/docs/api-reference/completions/create)|`$client->enginesCompletions()->create()->toModel()`|
98+
|`Tectalic\OpenAI\Handler\EnginesSearch`|`/engines/{engineId}/search`|`post`|`esCreate()`|Create search<br /><br />The search endpoint computes similarity scores between provided query and documents.<br />Documents can be passed directly to the API if there are no more than 200 of them.<br /><br />To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time.<br />When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents.<br />These documents will be returned along with their search scores.<br /><br />The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query.<br /><br />[See More](https://beta.openai.com/docs/api-reference/searches/create)|`$client->enginesSearch()->esCreate()->toModel()`|
99+
|`Tectalic\OpenAI\Handler\Files`|`/files`|`get`|`list()`|List files<br /><br />Returns a list of files that belong to the user's organization.<br /><br />[See More](https://beta.openai.com/docs/api-reference/files/list)|`$client->files()->list()->toModel()`|
100+
|`Tectalic\OpenAI\Handler\Files`|`/files`|`post`|`upload()`|Upload file<br /><br />Upload a file that contains document(s) to be used across various endpoints/features.<br />Currently, the size of all the files uploaded by one organization can be up to 1 GB.<br />Please contact us if you need to increase the storage limit.<br /><br />[See More](https://beta.openai.com/docs/api-reference/files/upload)|`$client->files()->upload()->toModel()`|
101+
|`Tectalic\OpenAI\Handler\Files`|`/files/{fileId}`|`get`|`get()`|Retrieve file<br /><br />Returns information about a specific file.<br /><br />[See More](https://beta.openai.com/docs/api-reference/files/retrieve)|`$client->files()->get()->toModel()`|
102+
|`Tectalic\OpenAI\Handler\Files`|`/files/{fileId}`|`delete`|`remove()`|Delete file<br /><br />Delete a file.<br /><br />[See More](https://beta.openai.com/docs/api-reference/files/delete)|`$client->files()->remove()->toModel()`|
103+
104+
105+
## Models (if DTO enabled)
106+
TODO: Add models if they are part of MVP
107+
```
108+
Tectalic\OpenAI\Model\User (primary for the `get()` method)
109+
Tectalic\OpenAI\Model\UserList (Collection, ArrayAccess)
110+
Tectalic\OpenAI\Model\UserCreate (if different from User)
111+
Tectalic\OpenAI\Model\UserUpdate (if different from User)
112+
Tectalic\OpenAI\Model\UserDelete (if different from User)
113+
Tectalic\OpenAI\Model\UserTrace (only if exotic HTTP method defined and different from User)
114+
```
115+
116+
## Errors
117+
118+
When using **OpenAI REST API Client**, certain types of errors will cause an `Tectalic\OpenAI\Exception\ClientException` to be thrown. For example, if the request cannot be encoded into valid JSON.
119+
120+
Your HTTP client of choice may also throw various exceptions, such as `GuzzleHttp\Exception\ClientException`. Consult your HTTP client's documentation for more details.

0 commit comments

Comments
 (0)