From 1e8a37aa12d62aae3a6101ae105c5d1c9e7e58d1 Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:08:24 -0500 Subject: [PATCH 01/11] Provide access to responseHeaders --- src/OpenAi.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/OpenAi.php b/src/OpenAi.php index ed38d98..7087ebe 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -16,6 +16,7 @@ class OpenAi private string $customUrl = ""; private string $proxy = ""; private array $curlInfo = []; + private array $responseHeaders; public function __construct($OPENAI_API_KEY) { @@ -487,6 +488,23 @@ public function setHeader(array $header) } } + /** + * @return array + */ + public function getResponseHeaders(): array + { + return $this->responseHeaders; + } + + /** + * @param array $responseHeaders + * @return void + */ + private function setResponseHeaders(array $responseHeaders) + { + $this->responseHeaders = $responseHeaders; + } + /** * @param string $org */ @@ -524,6 +542,7 @@ private function sendRequest(string $url, string $method, array $opts = []) CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $post_fields, CURLOPT_HTTPHEADER => $this->headers, + CURLOPT_HEADER => false, ]; if ($opts == []) { @@ -540,6 +559,26 @@ private function sendRequest(string $url, string $method, array $opts = []) $curl = curl_init(); + $responseHeaders = []; + curl_setopt( + $curl, + CURLOPT_HEADERFUNCTION, + function ($curl, $header) use (&$responseHeaders) { + $len = strlen($header); + $header = explode(':', $header, 2); + if (count($header) < 2) // ignore invalid headers + return $len; + + $name = strtolower(trim($header[0])); + if (!array_key_exists($name, $responseHeaders)) + $responseHeaders[$name] = [trim($header[1])]; + else + $responseHeaders[$name][] = trim($header[1]); + + return $len; + } + ); + curl_setopt_array($curl, $curl_info); $response = curl_exec($curl); @@ -550,6 +589,9 @@ private function sendRequest(string $url, string $method, array $opts = []) if (!$response) throw new Exception(curl_error($curl)); + // Header Fetch: + $this->setResponseHeaders($responseHeaders); + return $response; } From bc6a2dcaccb982146409754ba99463df478f6a1e Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:21:33 -0500 Subject: [PATCH 02/11] Add processingMs and cleanup --- src/OpenAi.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 7087ebe..eb8ac1e 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -17,6 +17,8 @@ class OpenAi private string $proxy = ""; private array $curlInfo = []; private array $responseHeaders; + private array $rateLimitInfo; + private int $processingMs; public function __construct($OPENAI_API_KEY) { @@ -488,10 +490,20 @@ public function setHeader(array $header) } } + /** + * @param string $org + */ + public function setORG(string $org) + { + if ($org != "") { + $this->headers[] = "OpenAI-Organization: $org"; + } + } + /** * @return array */ - public function getResponseHeaders(): array + private function getResponseHeaders(): array { return $this->responseHeaders; } @@ -506,12 +518,71 @@ private function setResponseHeaders(array $responseHeaders) } /** - * @param string $org + * @return array */ - public function setORG(string $org) + public function getRateLimitInfo(): array { - if ($org != "") { - $this->headers[] = "OpenAI-Organization: $org"; + return $this->rateLimitInfo; + } + + /** + * @param array $rateLimitInfo + * @return void + */ + private function setRateLimitInfo(array $rateLimitInfo) + { + $this->rateLimitInfo = $rateLimitInfo; + } + + /** + * @return void + */ + private function hydrateRateLimitInfo(): void + { + $responseHeaders = $this->getResponseHeaders(); + if(!empty($responseHeaders)) + { + $rateLimitInfo = [ + 'ratelimit-limit-requests' => $responseHeaders['x-ratelimit-limit-requests'], + 'ratelimit-limit-tokens' => $responseHeaders['x-ratelimit-limit-tokens'], + 'ratelimit-limit-remaining-requests' => $responseHeaders['x-ratelimit-limit-remaining-requests'], + 'ratelimit-limit-remaining-tokens' => $responseHeaders['x-ratelimit-limit-remaining-tokens'], + 'ratelimit-limit-reset-requests' => $responseHeaders['x-ratelimit-limit-reset-requests'], + 'ratelimit-limit-reset-tokens' => $responseHeaders['x-ratelimit-limit-reset-tokens'], + ]; + + $this->setRateLimitInfo($rateLimitInfo); + } + } + + /** + * @return array + */ + public function getProcessingMs(): int + { + return $this->processingMs; + } + + /** + * @param int $processingMs + * @return void + */ + private function setProcessingMs(int $processingMs) + { + $this->processingMs = $processingMs; + } + + /** + * @return void + */ + private function hydrateProcessingMs(): void + { + $responseHeaders = $this->getResponseHeaders(); + if(!empty($responseHeaders)) + { + $processingMs = $responseHeaders['openai-processing-ms']; + + $this->setProcessingMs($processingMs); } } @@ -589,9 +660,11 @@ function ($curl, $header) use (&$responseHeaders) { if (!$response) throw new Exception(curl_error($curl)); - // Header Fetch: $this->setResponseHeaders($responseHeaders); + $this->hydrateRateLimitInfo(); + $this->hydrateProcessingMs(); + return $response; } From d29c067b1e19345baaf6f46ac5226f1ae07d2e94 Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:30:36 -0500 Subject: [PATCH 03/11] Cleanup sub-indexing --- src/OpenAi.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index eb8ac1e..0116ed5 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -543,12 +543,12 @@ private function hydrateRateLimitInfo(): void if(!empty($responseHeaders)) { $rateLimitInfo = [ - 'ratelimit-limit-requests' => $responseHeaders['x-ratelimit-limit-requests'], - 'ratelimit-limit-tokens' => $responseHeaders['x-ratelimit-limit-tokens'], - 'ratelimit-limit-remaining-requests' => $responseHeaders['x-ratelimit-limit-remaining-requests'], - 'ratelimit-limit-remaining-tokens' => $responseHeaders['x-ratelimit-limit-remaining-tokens'], - 'ratelimit-limit-reset-requests' => $responseHeaders['x-ratelimit-limit-reset-requests'], - 'ratelimit-limit-reset-tokens' => $responseHeaders['x-ratelimit-limit-reset-tokens'], + 'ratelimit-limit-requests' => $responseHeaders['x-ratelimit-limit-requests'][0], + 'ratelimit-limit-tokens' => $responseHeaders['x-ratelimit-limit-tokens'][0], + 'ratelimit-limit-remaining-requests' => $responseHeaders['x-ratelimit-limit-remaining-requests'][0], + 'ratelimit-limit-remaining-tokens' => $responseHeaders['x-ratelimit-limit-remaining-tokens'][0], + 'ratelimit-limit-reset-requests' => $responseHeaders['x-ratelimit-limit-reset-requests'][0], + 'ratelimit-limit-reset-tokens' => $responseHeaders['x-ratelimit-limit-reset-tokens'][0], ]; $this->setRateLimitInfo($rateLimitInfo); From 4dc172569b2bd455868d1b972afe61120133dfa5 Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:30:59 -0500 Subject: [PATCH 04/11] Cleanup sub-indexing --- src/OpenAi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 0116ed5..cb3d10b 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -580,7 +580,7 @@ private function hydrateProcessingMs(): void $responseHeaders = $this->getResponseHeaders(); if(!empty($responseHeaders)) { - $processingMs = $responseHeaders['openai-processing-ms']; + $processingMs = $responseHeaders['openai-processing-ms'][0]; $this->setProcessingMs($processingMs); } From b4b177e49f9b20f37dc6f892e15854d7f0b1038b Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:39:42 -0500 Subject: [PATCH 05/11] Implement isset --- src/OpenAi.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index cb3d10b..3ff99b3 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -18,7 +18,7 @@ class OpenAi private array $curlInfo = []; private array $responseHeaders; private array $rateLimitInfo; - private int $processingMs; + private int $processingMs = 0; public function __construct($OPENAI_API_KEY) { @@ -543,12 +543,12 @@ private function hydrateRateLimitInfo(): void if(!empty($responseHeaders)) { $rateLimitInfo = [ - 'ratelimit-limit-requests' => $responseHeaders['x-ratelimit-limit-requests'][0], - 'ratelimit-limit-tokens' => $responseHeaders['x-ratelimit-limit-tokens'][0], - 'ratelimit-limit-remaining-requests' => $responseHeaders['x-ratelimit-limit-remaining-requests'][0], - 'ratelimit-limit-remaining-tokens' => $responseHeaders['x-ratelimit-limit-remaining-tokens'][0], - 'ratelimit-limit-reset-requests' => $responseHeaders['x-ratelimit-limit-reset-requests'][0], - 'ratelimit-limit-reset-tokens' => $responseHeaders['x-ratelimit-limit-reset-tokens'][0], + 'ratelimit-limit-requests' => isset($responseHeaders['x-ratelimit-limit-requests']) ? $responseHeaders['x-ratelimit-limit-requests'][0] : 0, + 'ratelimit-limit-tokens' => isset($responseHeaders['x-ratelimit-limit-tokens']) ? $responseHeaders['x-ratelimit-limit-tokens'][0] : 0, + 'ratelimit-limit-remaining-requests' => isset($responseHeaders['x-ratelimit-limit-remaining-requests']) ? $responseHeaders['x-ratelimit-limit-remaining-requests'][0] : 0, + 'ratelimit-limit-remaining-tokens' => isset($responseHeaders['x-ratelimit-limit-remaining-tokens']) ? $responseHeaders['x-ratelimit-limit-remaining-tokens'][0] : 0, + 'ratelimit-limit-reset-requests' => isset($responseHeaders['x-ratelimit-limit-reset-requests']) ? $responseHeaders['x-ratelimit-limit-reset-requests'][0] : 0, + 'ratelimit-limit-reset-tokens' => isset($responseHeaders['x-ratelimit-limit-reset-tokens']) ? $responseHeaders['x-ratelimit-limit-reset-tokens'][0] : 0, ]; $this->setRateLimitInfo($rateLimitInfo); @@ -578,7 +578,7 @@ private function setProcessingMs(int $processingMs) private function hydrateProcessingMs(): void { $responseHeaders = $this->getResponseHeaders(); - if(!empty($responseHeaders)) + if(!empty($responseHeaders) && isset($responseHeaders['openai-processing-ms'])) { $processingMs = $responseHeaders['openai-processing-ms'][0]; From b2daeb77a0bddb5394ea6b71252afa60ac23709f Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:51:42 -0500 Subject: [PATCH 06/11] Fix indexing --- src/OpenAi.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 3ff99b3..ac2ab46 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -543,12 +543,12 @@ private function hydrateRateLimitInfo(): void if(!empty($responseHeaders)) { $rateLimitInfo = [ - 'ratelimit-limit-requests' => isset($responseHeaders['x-ratelimit-limit-requests']) ? $responseHeaders['x-ratelimit-limit-requests'][0] : 0, - 'ratelimit-limit-tokens' => isset($responseHeaders['x-ratelimit-limit-tokens']) ? $responseHeaders['x-ratelimit-limit-tokens'][0] : 0, - 'ratelimit-limit-remaining-requests' => isset($responseHeaders['x-ratelimit-limit-remaining-requests']) ? $responseHeaders['x-ratelimit-limit-remaining-requests'][0] : 0, - 'ratelimit-limit-remaining-tokens' => isset($responseHeaders['x-ratelimit-limit-remaining-tokens']) ? $responseHeaders['x-ratelimit-limit-remaining-tokens'][0] : 0, - 'ratelimit-limit-reset-requests' => isset($responseHeaders['x-ratelimit-limit-reset-requests']) ? $responseHeaders['x-ratelimit-limit-reset-requests'][0] : 0, - 'ratelimit-limit-reset-tokens' => isset($responseHeaders['x-ratelimit-limit-reset-tokens']) ? $responseHeaders['x-ratelimit-limit-reset-tokens'][0] : 0, + 'ratelimit-limit-requests' => array_key_exists('x-ratelimit-limit-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-requests'] : 0, + 'ratelimit-limit-tokens' => array_key_exists('x-ratelimit-limit-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-tokens'] : 0, + 'ratelimit-limit-remaining-requests' => array_key_exists('x-ratelimit-limit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-remaining-requests'] : 0, + 'ratelimit-limit-remaining-tokens' => array_key_exists('x-ratelimit-limit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-remaining-tokens'] : 0, + 'ratelimit-limit-reset-requests' => array_key_exists('x-ratelimit-limit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-reset-requests'] : 0, + 'ratelimit-limit-reset-tokens' => array_key_exists('x-ratelimit-limit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-reset-tokens'] : 0, ]; $this->setRateLimitInfo($rateLimitInfo); @@ -578,9 +578,9 @@ private function setProcessingMs(int $processingMs) private function hydrateProcessingMs(): void { $responseHeaders = $this->getResponseHeaders(); - if(!empty($responseHeaders) && isset($responseHeaders['openai-processing-ms'])) + if(!empty($responseHeaders) && array_key_exists('openai-processing-ms',$responseHeaders)) { - $processingMs = $responseHeaders['openai-processing-ms'][0]; + $processingMs = $responseHeaders['openai-processing-ms']; $this->setProcessingMs($processingMs); } @@ -641,10 +641,14 @@ function ($curl, $header) use (&$responseHeaders) { return $len; $name = strtolower(trim($header[0])); - if (!array_key_exists($name, $responseHeaders)) - $responseHeaders[$name] = [trim($header[1])]; - else + if (!array_key_exists($name, $responseHeaders)) { + $responseHeaders[$name] = trim($header[1]); + } else { + if (!is_array($responseHeaders[$name])) { + $responseHeaders[$name] = [$responseHeaders[$name]]; + } $responseHeaders[$name][] = trim($header[1]); + } return $len; } From 47e80456accff250d7eb06382c0445714437e634 Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:59:36 -0500 Subject: [PATCH 07/11] Refactor to setHeaderMethod and error_log for test --- src/OpenAi.php | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index ac2ab46..09946f7 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -540,6 +540,8 @@ private function setRateLimitInfo(array $rateLimitInfo) private function hydrateRateLimitInfo(): void { $responseHeaders = $this->getResponseHeaders(); + error_log('$responseHeaders: '); + error_log(print_r($responseHeaders,true)); if(!empty($responseHeaders)) { $rateLimitInfo = [ @@ -586,6 +588,32 @@ private function hydrateProcessingMs(): void } } + /** + * @param array &$responseHeaders + * @return callable + */ + private function setHeaderFunction(array &$responseHeaders): callable + { + return function ($curl, $header) use (&$responseHeaders) { + $len = strlen($header); + $header = explode(':', $header, 2); + if (count($header) < 2) // ignore invalid headers + return $len; + + $name = strtolower(trim($header[0])); + if (!array_key_exists($name, $responseHeaders)) { + $responseHeaders[$name] = trim($header[1]); + } else { + if (!is_array($responseHeaders[$name])) { + $responseHeaders[$name] = [$responseHeaders[$name]]; + } + $responseHeaders[$name][] = trim($header[1]); + } + + return $len; + }; + } + /** * @param string $url * @param string $method @@ -634,24 +662,7 @@ private function sendRequest(string $url, string $method, array $opts = []) curl_setopt( $curl, CURLOPT_HEADERFUNCTION, - function ($curl, $header) use (&$responseHeaders) { - $len = strlen($header); - $header = explode(':', $header, 2); - if (count($header) < 2) // ignore invalid headers - return $len; - - $name = strtolower(trim($header[0])); - if (!array_key_exists($name, $responseHeaders)) { - $responseHeaders[$name] = trim($header[1]); - } else { - if (!is_array($responseHeaders[$name])) { - $responseHeaders[$name] = [$responseHeaders[$name]]; - } - $responseHeaders[$name][] = trim($header[1]); - } - - return $len; - } + $this->setHeaderFunction($responseHeaders) ); curl_setopt_array($curl, $curl_info); From 836bd6a98466253f65dbe34093b5f3a59b71e8a5 Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:01:59 -0500 Subject: [PATCH 08/11] Fix key values for rate limit headers --- src/OpenAi.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 09946f7..1f2a2e8 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -548,9 +548,9 @@ private function hydrateRateLimitInfo(): void 'ratelimit-limit-requests' => array_key_exists('x-ratelimit-limit-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-requests'] : 0, 'ratelimit-limit-tokens' => array_key_exists('x-ratelimit-limit-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-tokens'] : 0, 'ratelimit-limit-remaining-requests' => array_key_exists('x-ratelimit-limit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-remaining-requests'] : 0, - 'ratelimit-limit-remaining-tokens' => array_key_exists('x-ratelimit-limit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-remaining-tokens'] : 0, - 'ratelimit-limit-reset-requests' => array_key_exists('x-ratelimit-limit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-reset-requests'] : 0, - 'ratelimit-limit-reset-tokens' => array_key_exists('x-ratelimit-limit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-reset-tokens'] : 0, + 'ratelimit-remaining-tokens' => array_key_exists('x-ratelimit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-tokens'] : 0, + 'ratelimit-reset-requests' => array_key_exists('x-ratelimit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-requests'] : 0, + 'ratelimit-reset-tokens' => array_key_exists('x-ratelimit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-tokens'] : 0, ]; $this->setRateLimitInfo($rateLimitInfo); From 8bb3d26ff506db597441140e8c86f6c34c83706b Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:02:59 -0500 Subject: [PATCH 09/11] Fix key values for rate limit headers --- src/OpenAi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 1f2a2e8..d6c542c 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -547,7 +547,7 @@ private function hydrateRateLimitInfo(): void $rateLimitInfo = [ 'ratelimit-limit-requests' => array_key_exists('x-ratelimit-limit-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-requests'] : 0, 'ratelimit-limit-tokens' => array_key_exists('x-ratelimit-limit-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-tokens'] : 0, - 'ratelimit-limit-remaining-requests' => array_key_exists('x-ratelimit-limit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-remaining-requests'] : 0, + 'ratelimit-remaining-requests' => array_key_exists('x-ratelimit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-requests'] : 0, 'ratelimit-remaining-tokens' => array_key_exists('x-ratelimit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-tokens'] : 0, 'ratelimit-reset-requests' => array_key_exists('x-ratelimit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-requests'] : 0, 'ratelimit-reset-tokens' => array_key_exists('x-ratelimit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-tokens'] : 0, From b8e1e6699d262adaf358add54578958f793b960d Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:05:14 -0500 Subject: [PATCH 10/11] Cleanup --- src/OpenAi.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index d6c542c..2b33a6a 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -540,8 +540,6 @@ private function setRateLimitInfo(array $rateLimitInfo) private function hydrateRateLimitInfo(): void { $responseHeaders = $this->getResponseHeaders(); - error_log('$responseHeaders: '); - error_log(print_r($responseHeaders,true)); if(!empty($responseHeaders)) { $rateLimitInfo = [ From f6618d014635bf43d84fadece2318ac4a8e1141b Mon Sep 17 00:00:00 2001 From: mecfletcher <45575335+mecfletcher@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:22:27 -0500 Subject: [PATCH 11/11] Fix default values to avoid confusion --- src/OpenAi.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenAi.php b/src/OpenAi.php index 2b33a6a..6958c56 100644 --- a/src/OpenAi.php +++ b/src/OpenAi.php @@ -543,12 +543,12 @@ private function hydrateRateLimitInfo(): void if(!empty($responseHeaders)) { $rateLimitInfo = [ - 'ratelimit-limit-requests' => array_key_exists('x-ratelimit-limit-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-requests'] : 0, - 'ratelimit-limit-tokens' => array_key_exists('x-ratelimit-limit-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-tokens'] : 0, - 'ratelimit-remaining-requests' => array_key_exists('x-ratelimit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-requests'] : 0, - 'ratelimit-remaining-tokens' => array_key_exists('x-ratelimit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-tokens'] : 0, - 'ratelimit-reset-requests' => array_key_exists('x-ratelimit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-requests'] : 0, - 'ratelimit-reset-tokens' => array_key_exists('x-ratelimit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-tokens'] : 0, + 'ratelimit-limit-requests' => array_key_exists('x-ratelimit-limit-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-requests'] : null, + 'ratelimit-limit-tokens' => array_key_exists('x-ratelimit-limit-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-limit-tokens'] : null, + 'ratelimit-remaining-requests' => array_key_exists('x-ratelimit-remaining-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-requests'] : null, + 'ratelimit-remaining-tokens' => array_key_exists('x-ratelimit-remaining-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-remaining-tokens'] : null, + 'ratelimit-reset-requests' => array_key_exists('x-ratelimit-reset-requests',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-requests'] : null, + 'ratelimit-reset-tokens' => array_key_exists('x-ratelimit-reset-tokens',$responseHeaders) ? $responseHeaders['x-ratelimit-reset-tokens'] : null, ]; $this->setRateLimitInfo($rateLimitInfo);