Build Laravel 13 ticket assistant with Docker, Livewire admin, and helpdesk scraper command

This commit is contained in:
SitiWeb
2026-04-29 13:11:39 +02:00
parent 141a1a3c9b
commit 3c4572bb12
58 changed files with 9377 additions and 455 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Services;
use App\DTOs\ClassificationResultDTO;
use App\Models\AIDecision;
use App\Models\Article;
use App\Models\Ticket;
use App\Repositories\Contracts\ArticleRepositoryInterface;
class SemanticSearchService
{
public function __construct(
private readonly EmbeddingService $embeddingService,
private readonly ArticleRepositoryInterface $articleRepository,
private readonly AIClassifierService $classifierService,
) {}
public function findBestArticle(Ticket $ticket): array
{
$embedding = $ticket->embedding ?? $this->embeddingService->embed($ticket->message);
if ($ticket->embedding === null) {
$ticket->embedding = $embedding;
$ticket->save();
}
$candidates = $this->articleRepository->findSimilarByEmbedding($embedding, 5);
$classification = $this->classifierService->rank($ticket->message, $candidates);
$bestArticle = $classification->articleId ? Article::find($classification->articleId) : null;
AIDecision::query()->create([
'ticket_id' => $ticket->id,
'article_id' => $bestArticle?->id,
'confidence' => $classification->confidence,
'explanation' => $classification->explanation,
'raw_response' => $classification->rawResponse,
]);
return [
'best_article' => $bestArticle,
'confidence' => $classification->confidence,
'explanation' => $classification->explanation,
'top_3_candidates' => collect($candidates)->take(3)->map(fn ($c) => $c->toArray())->values()->all(),
];
}
}