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

Commit

Permalink
Readme: Use Fully Qualified Class Names for examples
Browse files Browse the repository at this point in the history
So that developers can more easily copy and paste the entire code snippet and use it in their applications.

Also adds type hinting for the $response model type.
  • Loading branch information
thejamescollins committed Jan 13, 2023
1 parent 8329e62 commit 313f51e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ Integrating OpenAI into your application is now as simple as a few lines of code
### Text Completion using GPT-3

```php
$openaiClient = Manager::build(new \GuzzleHttp\Client(), new Authentication(getenv('OPENAI_API_KEY')));
$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 CreateRequest([
new \Tectalic\OpenAi\Models\Completions\CreateRequest([
'model' => 'text-davinci-002',
'prompt' => 'Will using a third party package save time?',
])
Expand All @@ -35,10 +36,11 @@ echo $response->choices[0]->text;
### Code Completion Using Codex

```php
$openaiClient = Manager::build(new \GuzzleHttp\Client(), new Authentication(getenv('OPENAI_API_KEY')));
$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 CreateRequest([
new \Tectalic\OpenAi\Models\Completions\CreateRequest([
'model' => 'code-davinci-002',
'prompt' => "// PHP 8\n// A variable that saves the current date and time",
'max_tokens' => 256,
Expand All @@ -55,10 +57,11 @@ echo $response->choices[0]->text;
### Image Generation Using DALL·E

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

/** @var \Tectalic\OpenAi\Models\ImagesGenerations\CreateResponse $response */
$response = $openaiClient->imagesGenerations()->create(
new CreateRequest([
new \Tectalic\OpenAi\Models\ImagesGenerations\CreateRequest([
'prompt' => 'A cute baby sea otter wearing a hat',
'size' => '256x256',
'n' => 5
Expand Down

0 comments on commit 313f51e

Please sign in to comment.