Files
TicketAssistent/app/Services/EmbeddingService.php
SitiWeb f939133fe0 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.
2026-04-30 01:50:21 +02:00

63 lines
1.9 KiB
PHP

<?php
namespace App\Services;
use App\Exceptions\OllamaUnavailableException;
use App\Models\EmbeddingCache;
use App\Services\Llm\LlmClientInterface;
class EmbeddingService
{
public function __construct(
private readonly LlmClientInterface $llmClient,
private readonly AppSettingsService $settings,
) {}
public function embed(string $text): array
{
$hash = hash('sha256', $text);
$context = $this->context();
$cached = EmbeddingCache::query()
->where('provider_instance_id', $context['provider_instance_id'])
->where('embedding_model', $context['embedding_model'])
->where('text_hash', $hash)
->first();
if ($cached !== null) {
return $cached->embedding;
}
$embedding = $this->llmClient->embed($text);
if (! is_array($embedding) || $embedding === []) {
throw new OllamaUnavailableException('LLM embedding response did not include a valid embedding');
}
EmbeddingCache::query()->updateOrCreate(
[
'provider_instance_id' => $context['provider_instance_id'],
'embedding_model' => $context['embedding_model'],
'text_hash' => $hash,
],
['text' => $text, 'embedding' => $embedding]
);
return $embedding;
}
public function context(): array
{
$instance = $this->settings->activeProviderInstance();
$instanceId = (string) ($instance['id'] ?? $this->settings->activeProviderInstanceId());
$model = trim((string) $this->settings->get('llm.models.embedding', ''));
if ($model === '') {
$model = (string) ($instance['embedding_model'] ?? '');
}
return [
'provider_instance_id' => $instanceId,
'embedding_model' => $model,
];
}
}