Skip to content

Commit

Permalink
Fix: meta information fake data
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Feb 7, 2024
1 parent f6b47ac commit a501057
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Testing/Responses/Concerns/Fakeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ private static function buildAttributes(array $original, array $override): array
public static function fakeResponseMetaInformation(): MetaInformation
{
return MetaInformation::from([
'openai-model' => 'gpt-3.5-turbo-instruct',
'openai-organization' => 'org-1234',
'openai-processing-ms' => '410',
'openai-version' => '2020-10-01',
'x-ratelimit-limit-requests' => '3000',
'x-ratelimit-limit-tokens' => '250000',
'x-ratelimit-remaining-requests' => '2999',
'x-ratelimit-remaining-tokens' => '249989',
'x-ratelimit-reset-requests' => '20ms',
'x-ratelimit-reset-tokens' => '2ms',
'x-request-id' => '3813fa4fa3f17bdf0d7654f0f49ebab4',
'openai-model' => ['gpt-3.5-turbo-instruct'],
'openai-organization' => ['org-1234'],
'openai-processing-ms' => ['410'],
'openai-version' => ['2020-10-01'],
'x-ratelimit-limit-requests' => ['3000'],
'x-ratelimit-limit-tokens' => ['250000'],
'x-ratelimit-remaining-requests' => ['2999'],
'x-ratelimit-remaining-tokens' => ['249989'],
'x-ratelimit-reset-requests' => ['20ms'],
'x-ratelimit-reset-tokens' => ['2ms'],
'x-request-id' => ['3813fa4fa3f17bdf0d7654f0f49ebab4'],
]);
}
}
24 changes: 24 additions & 0 deletions tests/Testing/ClientFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@
expect($completion['choices'][0]['text'])->toBe('awesome!');
});

it('returns fake meta data', function () {
$fake = new ClientFake([
CreateResponse::fake(),
]);

$completion = $fake->completions()->create([
'model' => 'gpt-3.5-turbo-instruct',
'prompt' => 'PHP is ',
]);

expect($completion->meta())
->requestId->toBe('3813fa4fa3f17bdf0d7654f0f49ebab4')
->openai->model->toBe('gpt-3.5-turbo-instruct')
->openai->organization->toBe('org-1234')
->openai->processingMs->toBe(410)
->openai->version->toBe('2020-10-01')
->requestLimit->limit->toBe(3000)
->requestLimit->remaining->toBe(2999)
->requestLimit->reset->toBe('20ms')
->tokenLimit->limit->toBe(250000)
->tokenLimit->remaining->toBe(249989)
->tokenLimit->reset->toBe('2ms');
});

it('throws fake exceptions', function () {
$fake = new ClientFake([
new \OpenAI\Exceptions\ErrorException([
Expand Down

0 comments on commit a501057

Please sign in to comment.