Skip to content

Commit 76eafab

Browse files
authored
Merge pull request #28 from moe-mizrak/fix/wrong-int-types-to-float
wrong int types in ResponseData, LimitResponseData and CostResponseDa…
2 parents 1fe7833 + 7749e88 commit 76eafab

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ ubuntu-latest ]
16-
php: [ 8.1 ]
17-
laravel: [ 10.* ]
16+
php: [ 8.1, 8.2, 8.3, 8.4 ]
17+
laravel: [ 10.*, 11.* ]
1818
dependency-version: [ prefer-lowest, prefer-stable ]
1919
exclude:
2020
- php: 8.1

src/DTO/CostResponseData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class CostResponseData extends DataTransferObject
176176
/**
177177
* Usage associated with the request
178178
*
179-
* @var int|null
179+
* @var float|null
180180
*/
181-
public ?int $usage;
181+
public ?float $usage;
182182
}

src/DTO/LimitResponseData.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ class LimitResponseData extends DataTransferObject
2828
/**
2929
* Number of credits used.
3030
*
31-
* @var int|null
31+
* @var float|null
32+
*/
33+
public ?float $usage;
34+
35+
/**
36+
* @var float|null
3237
*/
33-
public ?int $usage;
38+
public ?float $limit_remaining;
3439

3540
/**
3641
* Credit limit for the key, or null if unlimited.

src/DTO/ResponseData.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* ResponseData is the general response DTO which consists of:
99
* - id
10+
* - provider
1011
* - model
1112
* - object
1213
* - created
@@ -25,6 +26,13 @@ class ResponseData extends DataTransferObject
2526
*/
2627
public string $id;
2728

29+
/**
30+
* Model provider e.g. HuggingFace
31+
*
32+
* @var string|null
33+
*/
34+
public ?string $provider;
35+
2836
/**
2937
* Name of the model e.g. mistralai/mistral-7b-instruct:free
3038
*

src/OpenRouterRequest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,13 @@ private function formChatResponse(mixed $response = null) : ResponseData
244244
{
245245
// Map the response data to ResponseData and return it.
246246
return new ResponseData([
247-
'id' => Arr::get($response, 'id'),
248-
'model' => Arr::get($response, 'model'),
249-
'object' => Arr::get($response, 'object'),
250-
'created' => Arr::get($response, 'created'),
251-
'choices' => Arr::get($response, 'choices'),
252-
'usage' => Arr::get($response, 'usage'),
247+
'id' => Arr::get($response, 'id'),
248+
'provider' => Arr::get($response, 'provider'),
249+
'model' => Arr::get($response, 'model'),
250+
'object' => Arr::get($response, 'object'),
251+
'created' => Arr::get($response, 'created'),
252+
'choices' => Arr::get($response, 'choices'),
253+
'usage' => Arr::get($response, 'usage'),
253254
]);
254255
}
255256

tests/OpenRouterAPITest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private function mockBasicBody(): array
5555
{
5656
return [
5757
'id' => 'gen-QcWgjEtiEDNHgomV2jjoQpCZlkRZ',
58+
'provider' => 'HuggingFace',
5859
'model' => $this->model,
5960
'object' => 'chat.completion',
6061
'created' => 1718888436,
@@ -82,7 +83,7 @@ private function mockBasicCostBody(): array
8283
'data' => [
8384
'id' => "gen-QcWgjEtiEDNHgomV2jjoQpCZlkRZ",
8485
'model' => $this->model,
85-
'total_cost' => 0,
86+
'total_cost' => 0.00492,
8687
'streamed' => true,
8788
'origin' => "https://github.com/moe-mizrak/laravel-openrouter",
8889
'cancelled' => false,
@@ -110,10 +111,10 @@ private function mockBasicLimitBody(): array
110111
return [
111112
'data' => [
112113
'label' => 'sk-or-v1-7a3...1f9',
113-
'usage' => 0,
114+
'usage' => 7.2E-5,
114115
'limit' => 1,
115116
'is_free_tier' => true,
116-
'limit_remaining' => 12,
117+
'limit_remaining' => -0.0369027621,
117118
'rate_limit' => [
118119
'requests' => 10,
119120
'interval' => '10s',
@@ -808,6 +809,8 @@ public function it_makes_a_limit_open_route_api_request_and_gets_rate_limit_and_
808809
$this->assertNotNull($response->label);
809810
$this->assertNotNull($response->usage);
810811
$this->assertNotNull($response->is_free_tier);
812+
$this->assertNotNull($response->limit);
813+
$this->assertNotNull($response->limit_remaining);
811814
$this->assertNotNull($response->rate_limit);
812815
$this->assertNotNull($response->rate_limit->requests);
813816
$this->assertNotNull($response->rate_limit->interval);

0 commit comments

Comments
 (0)