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

Commit

Permalink
Clarify GPT-4 compatibility
Browse files Browse the repository at this point in the history
Also explain which models are supported by which handlers, and update examples to use the latest models.
  • Loading branch information
om4james committed Mar 17, 2023
1 parent ca37c48 commit 906d100
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The **Tectalic OpenAI REST API Client** is a package that provides a convenient and straightforward way to interact with the **OpenAI API** from your PHP application.

Supports **ChatGPT**, **GPT-3**, **Codex**, **DALL·E** and **Whisper** based models, fully typed Data Transfer Objects (DTOs) for all requests and responses and IDE autocomplete support.
Supports **ChatGPT**, **GPT-4**, **GPT-3.5**, **GPT-3**, **Codex**, **DALL·E**, **Whisper**, **Embeddings** and **Moderation** models, with fully typed Data Transfer Objects (DTOs) for all requests and responses and IDE autocomplete support.

More information is available from [https://tectalic.com/apis/openai](https://tectalic.com/apis/openai).

Expand All @@ -14,36 +14,50 @@ More information is available from [https://tectalic.com/apis/openai](https://te

Integrating OpenAI into your application is now as simple as a few lines of code.

### Text Completion using ChatGPT
### Chat Completion using ChatGPT (GPT-3.5 & GPT-4)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));

/** @var \Tectalic\OpenAi\Models\ChatCompletions\CreateResponse $response */
$response = $openaiClient->chatCompletions()->create(
new \Tectalic\OpenAi\Models\ChatCompletions\CreateRequest([
'model' => 'gpt-3.5-turbo',
'model' => 'gpt-4',
'messages' => [
['role' => 'user', 'content' => 'Tell the world about the ChatGPT API in the style of a pirate'],
['role' => 'user', 'content' => 'Tell the world about GPT-4 in the style of a pirate'],
],
])
)->toModel();

echo $response->choices[0]->message->content;
// Ahoy there, me hearty! Gather round and listen well, for I'll be tellin' ye about the treasure trove known as ChatGPT API! ...
Ahoy there, ye landlubbers and sea dogs! Gather 'round for a tale of a treasure like no other - the mystical, the enigmatic, GPT-4. ...
```

[Learn more about chat completion](https://platform.openai.com/docs/guides/chat).

### Text Completion using GPT-3
This handler supports both the *GPT-3.5* and *GPT-4* models:

#### GPT-3.5

Supported [GPT-3.5 models](https://platform.openai.com/docs/models/gpt-3-5) include `gpt-3.5-turbo`, `text-davinci-003`, `text-davinci-002` and more.

#### GPT-4

Supported [GPT-4 models](https://platform.openai.com/docs/models/gpt-4) include `gpt-4` and more.

Note: GPT-4 is currently in a limited beta and only accessible to those who have been granted access. [Please see here](https://platform.openai.com/docs/models/gpt-4) for details and instructions on how to join the waitlist.

If you receive a 404 error when attempting to use GPT-4, then your OpenAI account has not been granted access.

### Text Completion (GPT-3)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));

/** @var \Tectalic\OpenAi\Models\Completions\CreateResponse $response */
$response = $openaiClient->completions()->create(
new \Tectalic\OpenAi\Models\Completions\CreateRequest([
'model' => 'text-davinci-002',
'model' => 'text-davinci-003',
'prompt' => 'Will using a third party package save time?',
])
)->toModel();
Expand All @@ -52,9 +66,11 @@ echo $response->choices[0]->text;
// Using a third party package can save time because you don't have to write the code yourself.
```

This handler supports all [GPT-3 models](https://platform.openai.com/docs/models/gpt-3), including `text-davinci-003`, `text-davinci-002` and more.

[Learn more about text completion](https://platform.openai.com/docs/guides/completion).

### Code Completion Using Codex
### Code Completion (Codex)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));
Expand All @@ -73,9 +89,11 @@ echo $response->choices[0]->text;
// $now = date("Y-m-d G:i:s")
```

Supported [Codex models](https://platform.openai.com/docs/models/codex) include `code-davinci-002` and `code-cushman-001`.

[Learn more about code completion](https://platform.openai.com/docs/guides/code).

### Image Generation Using DALL·E
### Image Generation (DALL·E)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));
Expand All @@ -96,7 +114,7 @@ foreach ($response->data as $item) {

[Learn more about image generation](https://platform.openai.com/docs/guides/images).

### Audio Transcription (Speech to text) using Whisper
### Speech to Text Audio Transcription (Whisper)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));
Expand All @@ -113,9 +131,11 @@ echo $response->text;
// Your audio transcript in your source language...
```

Supported [Whisper models](https://platform.openai.com/docs/models/whisper) include `whisper-1`.

[Learn more about speech to text](https://platform.openai.com/docs/guides/speech-to-text).

### Audio Translation (Speech to text) using Whisper
### Speech to Text Audio Translation (Whisper)

```php
$openaiClient = \Tectalic\OpenAi\Manager::build(new \GuzzleHttp\Client(), new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY')));
Expand All @@ -132,6 +152,8 @@ echo $response->text;
// Your audio transcript in english...
```

Supported [Whisper models](https://platform.openai.com/docs/models/whisper) include `whisper-1`.

[Learn more about speech to text](https://platform.openai.com/docs/guides/speech-to-text).

## Installation
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tectalic/openai",
"description": "An OpenAI REST API Client with ChatGPT, GPT-3, Codex, DALL·E and Whisper support. Includes fully typed Data Transfer Objects (DTOs) for all requests and responses and IDE autocomplete support.",
"description": "An OpenAI REST API Client with support for ChatGPT, GPT-4, GPT-3.5, GPT-3, Codex, DALL·E, Whisper, Embeddings and Moderation models. Includes fully typed Data Transfer Objects (DTOs) for all requests and responses and IDE autocomplete support.",
"type": "library",
"license": "MIT",
"keywords": [
Expand All @@ -10,7 +10,11 @@
"dalle",
"dall-e",
"gpt-3",
"gpt-3.5",
"gpt-4",
"gpt3",
"gpt3.5",
"gpt4",
"openai",
"rest",
"tectalic",
Expand Down

0 comments on commit 906d100

Please sign in to comment.