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
This commit is contained in:
@@ -7,45 +7,53 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class ModelPricing extends Model
|
||||
{
|
||||
protected $table = 'model_pricing';
|
||||
protected $primaryKey = 'model_key';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'model_key',
|
||||
'provider',
|
||||
'model',
|
||||
'input_price_per_million',
|
||||
'output_price_per_million',
|
||||
'context_window',
|
||||
'max_output_tokens',
|
||||
'is_active',
|
||||
'effective_from',
|
||||
'effective_until',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'input_price_per_million' => 'double',
|
||||
'output_price_per_million' => 'double',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
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',
|
||||
];
|
||||
|
||||
// Accessors
|
||||
public function getInputPriceFormattedAttribute()
|
||||
public function getInputPriceFormattedAttribute(): string
|
||||
{
|
||||
return '$' . number_format($this->input_price_per_million, 2) . '/M';
|
||||
}
|
||||
|
||||
public function getOutputPriceFormattedAttribute()
|
||||
public function getOutputPriceFormattedAttribute(): string
|
||||
{
|
||||
return '$' . number_format($this->output_price_per_million, 2) . '/M';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate cost for given token counts
|
||||
*/
|
||||
public function calculateCost($inputTokens, $outputTokens)
|
||||
public function calculateCost(int $inputTokens, int $outputTokens): float
|
||||
{
|
||||
$inputCost = ($inputTokens / 1000000) * $this->input_price_per_million;
|
||||
$outputCost = ($outputTokens / 1000000) * $this->output_price_per_million;
|
||||
$inputCost = ($inputTokens / 1_000_000) * $this->input_price_per_million;
|
||||
$outputCost = ($outputTokens / 1_000_000) * $this->output_price_per_million;
|
||||
|
||||
return $inputCost + $outputCost;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user