Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong int types in ResponseData, LimitResponseData and CostResponseDa… #28

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.1 ]
laravel: [ 10.* ]
php: [ 8.1, 8.2, 8.3, 8.4 ]
laravel: [ 10.*, 11.* ]
dependency-version: [ prefer-lowest, prefer-stable ]
exclude:
- php: 8.1
Expand Down
4 changes: 2 additions & 2 deletions src/DTO/CostResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 7 additions & 2 deletions src/DTO/LimitResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/DTO/ResponseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* ResponseData is the general response DTO which consists of:
* - id
* - provider
* - model
* - object
* - created
Expand All @@ -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
*
Expand Down
13 changes: 7 additions & 6 deletions src/OpenRouterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]);
}

Expand Down
9 changes: 6 additions & 3 deletions tests/OpenRouterAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private function mockBasicBody(): array
{
return [
'id' => 'gen-QcWgjEtiEDNHgomV2jjoQpCZlkRZ',
'provider' => 'HuggingFace',
'model' => $this->model,
'object' => 'chat.completion',
'created' => 1718888436,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
Loading