From 1e7bbf62d863f5c1b779f721a789a44d0110bf2b Mon Sep 17 00:00:00 2001 From: moe-mizrak Date: Sun, 15 Dec 2024 14:45:39 +0300 Subject: [PATCH 1/3] wrong int types in ResponseData, LimitResponseData and CostResponseData fixed --- src/DTO/CostResponseData.php | 4 ++-- src/DTO/LimitResponseData.php | 9 +++++++-- src/DTO/ResponseData.php | 8 ++++++++ src/OpenRouterRequest.php | 13 +++++++------ tests/OpenRouterAPITest.php | 9 ++++++--- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/DTO/CostResponseData.php b/src/DTO/CostResponseData.php index 818b500..40518f3 100644 --- a/src/DTO/CostResponseData.php +++ b/src/DTO/CostResponseData.php @@ -176,7 +176,7 @@ class CostResponseData extends DataTransferObject /** * Usage associated with the request * - * @var int|null + * @var float|null */ - public ?int $usage; + public ?float $usage; } diff --git a/src/DTO/LimitResponseData.php b/src/DTO/LimitResponseData.php index 4b0bdaf..9bf26d0 100644 --- a/src/DTO/LimitResponseData.php +++ b/src/DTO/LimitResponseData.php @@ -28,9 +28,14 @@ class LimitResponseData extends DataTransferObject /** * Number of credits used. * - * @var int|null + * @var float|null + */ + public ?float $usage; + + /** + * @var float|null */ - public ?int $usage; + public ?float $limit_remaining; /** * Credit limit for the key, or null if unlimited. diff --git a/src/DTO/ResponseData.php b/src/DTO/ResponseData.php index 7ecf102..8914279 100644 --- a/src/DTO/ResponseData.php +++ b/src/DTO/ResponseData.php @@ -7,6 +7,7 @@ /** * ResponseData is the general response DTO which consists of: * - id + * - provider * - model * - object * - created @@ -25,6 +26,13 @@ class ResponseData extends DataTransferObject */ public string $id; + /** + * Model provider e.g. HuggingFace + * + * @var string|null + */ + public ?string $provider; + /** * Name of the model e.g. mistralai/mistral-7b-instruct:free * diff --git a/src/OpenRouterRequest.php b/src/OpenRouterRequest.php index a32d05e..78dc1e2 100644 --- a/src/OpenRouterRequest.php +++ b/src/OpenRouterRequest.php @@ -244,12 +244,13 @@ private function formChatResponse(mixed $response = null) : ResponseData { // Map the response data to ResponseData and return it. return new ResponseData([ - 'id' => Arr::get($response, 'id'), - 'model' => Arr::get($response, 'model'), - 'object' => Arr::get($response, 'object'), - 'created' => Arr::get($response, 'created'), - 'choices' => Arr::get($response, 'choices'), - 'usage' => Arr::get($response, 'usage'), + 'id' => Arr::get($response, 'id'), + 'provider' => Arr::get($response, 'provider'), + 'model' => Arr::get($response, 'model'), + 'object' => Arr::get($response, 'object'), + 'created' => Arr::get($response, 'created'), + 'choices' => Arr::get($response, 'choices'), + 'usage' => Arr::get($response, 'usage'), ]); } diff --git a/tests/OpenRouterAPITest.php b/tests/OpenRouterAPITest.php index 64c6fc8..286d725 100644 --- a/tests/OpenRouterAPITest.php +++ b/tests/OpenRouterAPITest.php @@ -55,6 +55,7 @@ private function mockBasicBody(): array { return [ 'id' => 'gen-QcWgjEtiEDNHgomV2jjoQpCZlkRZ', + 'provider' => 'HuggingFace', 'model' => $this->model, 'object' => 'chat.completion', 'created' => 1718888436, @@ -82,7 +83,7 @@ private function mockBasicCostBody(): array 'data' => [ 'id' => "gen-QcWgjEtiEDNHgomV2jjoQpCZlkRZ", 'model' => $this->model, - 'total_cost' => 0, + 'total_cost' => 0.00492, 'streamed' => true, 'origin' => "https://github.com/moe-mizrak/laravel-openrouter", 'cancelled' => false, @@ -110,10 +111,10 @@ private function mockBasicLimitBody(): array return [ 'data' => [ 'label' => 'sk-or-v1-7a3...1f9', - 'usage' => 0, + 'usage' => 7.2E-5, 'limit' => 1, 'is_free_tier' => true, - 'limit_remaining' => 12, + 'limit_remaining' => -0.0369027621, 'rate_limit' => [ 'requests' => 10, 'interval' => '10s', @@ -808,6 +809,8 @@ public function it_makes_a_limit_open_route_api_request_and_gets_rate_limit_and_ $this->assertNotNull($response->label); $this->assertNotNull($response->usage); $this->assertNotNull($response->is_free_tier); + $this->assertNotNull($response->limit); + $this->assertNotNull($response->limit_remaining); $this->assertNotNull($response->rate_limit); $this->assertNotNull($response->rate_limit->requests); $this->assertNotNull($response->rate_limit->interval); From 768e37172df7af9daa55a2b1c45f63fab8a70fff Mon Sep 17 00:00:00 2001 From: moe-mizrak Date: Sun, 15 Dec 2024 14:52:46 +0300 Subject: [PATCH 2/3] php new versions added 8.2, 8.3, 8.4 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 91d4a82..7786911 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,8 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest ] - php: [ 8.1 ] - laravel: [ 10.* ] + php: [ 8.2, 8.3, 8.4 ] + laravel: [ 10.*, 11.* ] dependency-version: [ prefer-lowest, prefer-stable ] exclude: - php: 8.1 From 7749e88fc9682e97369f08d5d5446128e7ddc885 Mon Sep 17 00:00:00 2001 From: moe-mizrak Date: Sun, 15 Dec 2024 14:53:12 +0300 Subject: [PATCH 3/3] php new versions added 8.2, 8.3, 8.4 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7786911..703d8a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest ] - php: [ 8.2, 8.3, 8.4 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] laravel: [ 10.*, 11.* ] dependency-version: [ prefer-lowest, prefer-stable ] exclude: