From ce84f541fe8a2869de7f48030d5757be1fd604c9 Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Fri, 22 Dec 2023 16:18:26 +0100 Subject: [PATCH] Add test case for headers with different cases --- src/Responses/Meta/MetaInformation.php | 1 + tests/Fixtures/Meta.php | 11 +++++++++++ tests/Responses/Meta/MetaInformation.php | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/Responses/Meta/MetaInformation.php b/src/Responses/Meta/MetaInformation.php index 2e616976..1665e633 100644 --- a/src/Responses/Meta/MetaInformation.php +++ b/src/Responses/Meta/MetaInformation.php @@ -29,6 +29,7 @@ private function __construct( public static function from(array $headers): self { $headers = array_change_key_case($headers, CASE_LOWER); + $requestId = $headers['x-request-id'][0] ?? null; $openai = MetaInformationOpenAI::from([ diff --git a/tests/Fixtures/Meta.php b/tests/Fixtures/Meta.php index e91ffd97..469faa54 100644 --- a/tests/Fixtures/Meta.php +++ b/tests/Fixtures/Meta.php @@ -30,6 +30,17 @@ function metaHeadersFromAzure(): array ]; } +function metaHeadersWithDifferentCases(): array +{ + return [ + 'Openai-Model' => ['gpt-3.5-turbo-instruct'], + 'OPENAI-ORGANIZATION' => ['org-1234'], + 'openai-processing-ms' => [410], + 'openai-version' => ['2020-10-01'], + 'x-request-id' => ['3813fa4fa3f17bdf0d7654f0f49ebab4'], + ]; +} + function meta(): MetaInformation { return MetaInformation::from(metaHeaders()); diff --git a/tests/Responses/Meta/MetaInformation.php b/tests/Responses/Meta/MetaInformation.php index d7299fb8..2aa0138b 100644 --- a/tests/Responses/Meta/MetaInformation.php +++ b/tests/Responses/Meta/MetaInformation.php @@ -82,6 +82,21 @@ ->openai->processingMs->toBeNull(); }); +test('from response headers in different cases', function () { + $meta = MetaInformation::from((new \GuzzleHttp\Psr7\Response(headers: metaHeadersWithDifferentCases()))->getHeaders()); + + expect($meta) + ->toBeInstanceOf(MetaInformation::class) + ->requestId->toBe('3813fa4fa3f17bdf0d7654f0f49ebab4') + ->openai->toBeInstanceOf(MetaInformationOpenAI::class) + ->openai->model->toBe('gpt-3.5-turbo-instruct') + ->openai->organization->toBe('org-1234') + ->openai->version->toBe('2020-10-01') + ->openai->processingMs->toBe(410) + ->requestLimit->toBeNull() + ->tokenLimit->toBeNull(); +}); + test('as array accessible', function () { $meta = MetaInformation::from(metaHeaders());