Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.6.x] Add access to meta / header information #195

Merged
merged 15 commits into from
Aug 22, 2023

Conversation

gehrisandro
Copy link
Collaborator

The API does return some meta information in the response header. This PR makes them available on the response object.

Here the relevant part from the update README:

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

$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.

$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.

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

@nunomaduro nunomaduro merged commit a0bfba8 into main Aug 22, 2023
12 checks passed
@nunomaduro
Copy link
Contributor

You probably should want to make this 7.x?

@nunomaduro nunomaduro deleted the add-header-information branch August 22, 2023 12:49
@gehrisandro
Copy link
Collaborator Author

You probably should want to make this 7.x?

Technically it is a non-breaking change. But we can make a 0.7 to make it more clear that it has a bigger new feature.

By the way I will not do the release today, as I first want to fix / change some other stuff.

@nunomaduro
Copy link
Contributor

@gehrisandro Yeah - it's fine to do 7.x cuz marketing wise that feature looks sexy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants