Skip to content

Commit 07d0ebe

Browse files
committed
fix: Use correct calculation for input tokens
1 parent d7f8bba commit 07d0ebe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Providers/XAIModelInfoProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ protected static function getCostPerToken(int $pricePerMillionTokens): float
128128
*/
129129
protected static function getMaxInputTokens(array $body): ?int
130130
{
131-
return str_starts_with($body['id'], 'grok-2-vision')
131+
$tokens = str_starts_with($body['id'], 'grok-2-vision')
132132
? 32768
133133
: 131072;
134+
135+
return (int) ($tokens * 0.9765625);
134136
}
135137

136138
/**

tests/Unit/Providers/XAIModelInfoProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
expect($modelInfo->name)->toBe('grok-3-beta');
6060
expect($modelInfo->provider)->toBe(ModelProvider::XAI);
6161
expect($modelInfo->type)->toBe(ModelType::Chat);
62-
expect($modelInfo->maxInputTokens)->toBe(131072);
62+
expect($modelInfo->maxInputTokens)->toBe(128000);
6363
expect($modelInfo->maxOutputTokens)->toBeNull();
6464
expect($modelInfo->inputCostPerToken)->toBe(0.0002);
6565
expect($modelInfo->outputCostPerToken)->toBe(0.001);
@@ -104,7 +104,7 @@
104104
expect($modelInfo->name)->toBe('grok-2-vision-1212');
105105
expect($modelInfo->provider)->toBe(ModelProvider::XAI);
106106
expect($modelInfo->type)->toBe(ModelType::Chat);
107-
expect($modelInfo->maxInputTokens)->toBe(32768);
107+
expect($modelInfo->maxInputTokens)->toBe(32000);
108108
expect($modelInfo->maxOutputTokens)->toBeNull();
109109
expect($modelInfo->inputCostPerToken)->toBe(0.0002);
110110
expect($modelInfo->outputCostPerToken)->toBe(0.001);

0 commit comments

Comments
 (0)