Files
laravel-llm-gateway/laravel-app/app/Models/ModelPricing.php
wtrinkl bef36c7ca2 Rename project from any-llm to laravel-llm
- Remove old any-llm related files (Dockerfile, config.yml, web/, setup-laravel.sh)
- Update README.md with new Laravel LLM Gateway documentation
- Keep docker-compose.yml with laravel-llm container names
- Clean project structure for Laravel-only implementation
2025-11-18 22:05:05 +01:00

60 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ModelPricing extends Model
{
protected $table = 'model_pricing';
protected $fillable = [
'provider',
'model',
'input_price_per_million',
'output_price_per_million',
'context_window',
'max_output_tokens',
'is_active',
'effective_from',
'effective_until',
'notes',
];
protected $casts = [
'input_price_per_million' => 'decimal:4',
'output_price_per_million' => 'decimal:4',
'context_window' => 'integer',
'max_output_tokens' => 'integer',
'is_active' => 'boolean',
'effective_from' => 'date',
'effective_until' => 'date',
];
public function getInputPriceFormattedAttribute(): string
{
return '$' . number_format($this->input_price_per_million, 2) . '/M';
}
public function getOutputPriceFormattedAttribute(): string
{
return '$' . number_format($this->output_price_per_million, 2) . '/M';
}
public function calculateCost(int $inputTokens, int $outputTokens): float
{
$inputCost = ($inputTokens / 1_000_000) * $this->input_price_per_million;
$outputCost = ($outputTokens / 1_000_000) * $this->output_price_per_million;
return round($inputCost + $outputCost, 6);
}
public function isCurrentlyActive(): bool
{
$now = now()->toDateString();
return $this->is_active
&& $this->effective_from <= $now
&& ($this->effective_until === null || $this->effective_until >= $now);
}
}