Add admin views for quick replies, settings, and ticket details
- Created `quick-replies.blade.php` for managing quick replies. - Added `settings.blade.php` for admin settings management. - Implemented `ticket-show.blade.php` to display ticket details. - Introduced `timeline-card.blade.php` component for displaying timeline information. Enhance quick reply management functionality - Developed `quick-reply-manager.blade.php` for creating and editing quick replies. - Integrated Livewire for dynamic interaction and validation. Implement settings page for AI configuration - Created `settings-page.blade.php` for managing AI settings, including prompts and provider instances. - Added functionality for managing models and embeddings. Add ticket show functionality with real-time updates - Implemented ticket details view with processing status and tool call logs. - Added support for displaying article suggestions and error messages. Create unit tests for AI classifier and domain info tool - Added `AIClassifierServiceTest.php` to validate AI classifier functionality. - Implemented `DomainInfoToolTest.php` for domain parameter validation. - Created `OxxaClientTest.php` to test API interactions and password hashing.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\DTOs\ClassificationResultDTO;
|
||||
use App\Models\AIDecision;
|
||||
use App\Models\Article;
|
||||
use App\Models\Ticket;
|
||||
@@ -18,14 +17,26 @@ class SemanticSearchService
|
||||
|
||||
public function findBestArticle(Ticket $ticket): array
|
||||
{
|
||||
$embedding = $ticket->embedding ?? $this->embeddingService->embed($ticket->message);
|
||||
if ($ticket->embedding === null) {
|
||||
$queryText = $ticket->normalized_message ?: $ticket->message;
|
||||
$language = (string) ($ticket->redaction_report['language'] ?? 'nl');
|
||||
$embeddingContext = $this->embeddingService->context();
|
||||
|
||||
$ticketEmbeddingIsCurrent = $ticket->embedding !== null
|
||||
&& $ticket->embedding_provider_instance_id === $embeddingContext['provider_instance_id']
|
||||
&& $ticket->embedding_model === $embeddingContext['embedding_model'];
|
||||
|
||||
$embedding = $ticketEmbeddingIsCurrent ? $ticket->embedding : $this->embeddingService->embed($queryText);
|
||||
if (! $ticketEmbeddingIsCurrent) {
|
||||
$ticket->embedding = $embedding;
|
||||
$ticket->embedding_provider_instance_id = $embeddingContext['provider_instance_id'];
|
||||
$ticket->embedding_model = $embeddingContext['embedding_model'];
|
||||
$ticket->embedded_at = now();
|
||||
$ticket->save();
|
||||
}
|
||||
|
||||
$candidates = $this->articleRepository->findSimilarByEmbedding($embedding, 5);
|
||||
$classification = $this->classifierService->rank($ticket->message, $candidates);
|
||||
$rawCandidates = $this->articleRepository->findSimilarByEmbedding($embedding, 12, $embeddingContext);
|
||||
$candidates = $this->prepareCandidates($queryText, $rawCandidates, 5);
|
||||
$classification = $this->classifierService->rank($queryText, $candidates, $language);
|
||||
|
||||
$bestArticle = $classification->articleId ? Article::find($classification->articleId) : null;
|
||||
|
||||
@@ -42,6 +53,61 @@ class SemanticSearchService
|
||||
'confidence' => $classification->confidence,
|
||||
'explanation' => $classification->explanation,
|
||||
'top_3_candidates' => collect($candidates)->take(3)->map(fn ($c) => $c->toArray())->values()->all(),
|
||||
'top_5_candidates' => collect($candidates)->map(fn ($c) => $c->toArray())->values()->all(),
|
||||
'retrieval_meta' => [
|
||||
'raw_candidates_count' => count($rawCandidates),
|
||||
'deduped_candidates_count' => count($candidates),
|
||||
],
|
||||
'requested_tool_call' => $classification->toolCall,
|
||||
'classifier_raw_response' => $classification->rawResponse,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareCandidates(string $queryText, array $candidates, int $limit): array
|
||||
{
|
||||
$seen = [];
|
||||
$unique = [];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
$dedupeKey = $candidate->sourceArticleId
|
||||
? 'source_id:'.$candidate->sourceArticleId
|
||||
: ($candidate->sourceUrl ? 'source_url:'.$candidate->sourceUrl : 'article:'.$candidate->articleId);
|
||||
|
||||
if (isset($seen[$dedupeKey])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[$dedupeKey] = true;
|
||||
$unique[] = $candidate;
|
||||
}
|
||||
|
||||
$query = mb_strtolower($queryText);
|
||||
$isHowTo = str_contains($query, 'hoe') || str_contains($query, 'instel') || str_contains($query, 'stap');
|
||||
|
||||
usort($unique, function ($a, $b) use ($isHowTo) {
|
||||
$scoreA = $this->candidateScore($a->title.' '.$a->content, $a->distance, $isHowTo);
|
||||
$scoreB = $this->candidateScore($b->title.' '.$b->content, $b->distance, $isHowTo);
|
||||
|
||||
return $scoreB <=> $scoreA;
|
||||
});
|
||||
|
||||
return array_values(array_slice($unique, 0, $limit));
|
||||
}
|
||||
|
||||
private function candidateScore(string $text, float $distance, bool $isHowTo): float
|
||||
{
|
||||
$score = 1.0 - $distance;
|
||||
$haystack = mb_strtolower($text);
|
||||
|
||||
if ($isHowTo) {
|
||||
$proceduralKeywords = ['hoe', 'stap', 'instellen', 'aanmaken', 'wijzigen', 'klik', 'menu', 'beheren', 'dns'];
|
||||
foreach ($proceduralKeywords as $keyword) {
|
||||
if (str_contains($haystack, $keyword)) {
|
||||
$score += 0.03;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user