Skip to content

Commit

Permalink
WIP: Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Aug 22, 2023
1 parent 18bb369 commit 0cea6f2
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [FineTunes Resource](#finetunes-resource)
- [Moderations Resource](#moderations-resource)
- [Images Resource](#images-resource)
- [Meta Information](#meta-information)
- [Testing](#testing)
- [Services](#services)
- [Azure](#azure)
Expand Down Expand Up @@ -760,6 +761,67 @@ foreach ($response->data as $data) {
$response->toArray(); // ['created' => 1589478378, data => ['url' => 'https://oaidalleapiprodscus...', ...]]
```

## Meta Information

On all response objects you can access the meta information returned by the API via the `meta()` method.

```php
$response = $client->completions()->create([
'model' => 'text-davinci-003',
'prompt' => 'Say this is a test',
]);

$meta = $response->meta();

$meta->requestId; // '574a03e2faaf4e9fd703958e4ddc66f5'

$meta->openai->model; // 'text-davinci-003'
$meta->openai->organization; // 'org-jwe45798ASN82s'
$meta->openai->version; // '2020-10-01'
$meta->openai->processingMs; // 425

$meta->requestLimit->limit; // 3000
$meta->requestLimit->remaining; // 2999
$meta->requestLimit->reset; // '20ms'

$meta->tokenLimit->limit; // 250000
$meta->tokenLimit->remaining; // 249984
$meta->tokenLimit->reset; // '3ms'
```

The `toArray()` method returns the meta information in the form originally returned by the API.

```php
$meta->toArray();

// [
// 'x-request-id' => '574a03e2faaf4e9fd703958e4ddc66f5',
// 'openai-model' => 'text-davinci-003',
// 'openai-organization' => 'org-jwe45798ASN82s',
// 'openai-processing-ms' => 402,
// 'openai-version' => '2020-10-01',
// 'x-ratelimit-limit-requests' => 3000,
// 'x-ratelimit-remaining-requests' => 2999,
// 'x-ratelimit-reset-requests' => '20ms',
// 'x-ratelimit-limit-tokens' => 250000,
// 'x-ratelimit-remaining-tokens' => 249983,
// 'x-ratelimit-reset-tokens' => '3ms',
// ]
```

On streaming responses you can access the meta information on the reponse stream object.

```php
$stream = $client->completions()->createStreamed([
'model' => 'text-davinci-003',
'prompt' => 'Say this is a test',
]);

$stream->meta();
```

For further details about the rates limits and what to do if you hit them visit the [OpenAI documentation](https://platform.openai.com/docs/guides/rate-limits/rate-limits).

## Testing

The package provides a fake implementation of the `OpenAI\Client` class that allows you to fake the API responses.
Expand Down

0 comments on commit 0cea6f2

Please sign in to comment.