init project
This commit is contained in:
38
app/Actions/Embeddings/RecordEmbeddingUsageEvent.php
Normal file
38
app/Actions/Embeddings/RecordEmbeddingUsageEvent.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Embeddings;
|
||||
|
||||
use App\Models\EmbeddingUsageEvent;
|
||||
use App\Models\User;
|
||||
use App\Services\EmbeddingWorkbench;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class RecordEmbeddingUsageEvent
|
||||
{
|
||||
public function handle(
|
||||
?Authenticatable $user,
|
||||
EmbeddingWorkbench $workbench,
|
||||
?string $selectedModel,
|
||||
string $tool,
|
||||
int $inputCount,
|
||||
int $resultCount,
|
||||
?int $tokens = null,
|
||||
): ?EmbeddingUsageEvent {
|
||||
if (! $user instanceof User) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$model = $workbench->modelName($selectedModel);
|
||||
|
||||
return EmbeddingUsageEvent::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'tool' => $tool,
|
||||
'provider' => $workbench->providerName(),
|
||||
'model' => $model,
|
||||
'embedding_dimensions' => $workbench->dimensions($model),
|
||||
'input_count' => max(0, $inputCount),
|
||||
'result_count' => max(0, $resultCount),
|
||||
'tokens' => $tokens,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user