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:
67
app/Services/KnowledgeGapService.php
Normal file
67
app/Services/KnowledgeGapService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Services\Llm\LlmClientInterface;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class KnowledgeGapService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LlmClientInterface $llmClient,
|
||||
private readonly AppSettingsService $settings,
|
||||
) {}
|
||||
|
||||
public function shouldCreateDraft(Ticket $ticket, array $result): bool
|
||||
{
|
||||
$confidence = (float) ($result['confidence'] ?? 0);
|
||||
if ($confidence < 0.45) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$explanation = mb_strtolower((string) ($result['explanation'] ?? ''));
|
||||
$signals = ['does not contain', 'niet relevant', 'mismatch', 'no article', 'onvoldoende', 'server outage'];
|
||||
foreach ($signals as $signal) {
|
||||
if (str_contains($explanation, $signal)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function suggestArticleDraft(Ticket $ticket, array $result): array
|
||||
{
|
||||
$question = $ticket->normalized_message ?: $ticket->message;
|
||||
$language = (string) ($ticket->redaction_report['language'] ?? 'nl');
|
||||
$topCandidates = json_encode($result['top_3_candidates'] ?? [], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$basePrompt = $this->settings->getPrompt('knowledge_gap', 'Create a draft knowledge base article suggestion. Return JSON only with keys: title, content.');
|
||||
$prompt = $basePrompt."\n\n".
|
||||
"Klantvraag:\n{$question}\n\n".
|
||||
"Originele taal: {$language}. Schrijf titel en inhoud in deze taal.\n\n".
|
||||
"Huidige kandidaten (mogelijk onvoldoende):\n{$topCandidates}\n\n".
|
||||
'Content moet praktisch zijn met duidelijke stappen.';
|
||||
|
||||
$title = 'Concept: '.Str::limit($question, 80, '');
|
||||
$content = "Deze vraag kon nog niet goed worden beantwoord vanuit de huidige kennisbank.\n\n".
|
||||
"Klantvraag:\n".$question."\n\n".
|
||||
'Actie: supportmedewerker vult dit artikel aan met definitieve stappen en context.';
|
||||
|
||||
try {
|
||||
$raw = trim($this->llmClient->generate($prompt, ['expect_json' => true, 'task' => 'knowledge_gap']));
|
||||
$decoded = json_decode($raw, true);
|
||||
if (is_array($decoded)) {
|
||||
$title = trim((string) ($decoded['title'] ?? $title));
|
||||
$content = trim((string) ($decoded['content'] ?? $content));
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user