31 lines
814 B
PHP
31 lines
814 B
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Article;
|
|
use App\Services\EmbeddingService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class GenerateArticleEmbeddingJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public function __construct(public readonly int $articleId)
|
|
{
|
|
}
|
|
|
|
public function handle(EmbeddingService $embeddingService): void
|
|
{
|
|
$article = Article::find($this->articleId);
|
|
if ($article === null) {
|
|
return;
|
|
}
|
|
|
|
$article->embedding = $embeddingService->embed($article->title."\n".$article->content);
|
|
$article->save();
|
|
}
|
|
} |