Added an custom form type for model selection with autocompletition

This commit is contained in:
Jan Böhmer 2026-04-26 15:19:52 +02:00
parent 67cb6fb8a2
commit 9d389309fc
5 changed files with 252 additions and 1 deletions

View file

@ -23,7 +23,10 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Parameters\AbstractParameter;
use App\Services\AI\AIPlatformRegistry;
use App\Services\AI\AIPlatforms;
use App\Settings\MiscSettings\IpnSuggestSettings;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Category;
@ -54,6 +57,8 @@ use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
/**
* In this controller the endpoints for the typeaheads are collected.
@ -223,4 +228,21 @@ class TypeaheadController extends AbstractController
return new JsonResponse($ipnSuggestions);
}
#[Route(path: '/ai/{platform}/models', name: 'typeahead_ai_models', requirements: ['platform' => '.+'])]
public function aiModels(
AIPlatforms $platform,
AIPlatformRegistry $platformRegistry,
CacheInterface $cache,
): JsonResponse {
$this->denyAccessUnlessGranted('@config.change_system_settings');
$models = $cache->get('ai_models_'.$platform->value, function(ItemInterface $item) use ($platformRegistry, $platform) {
$item->expiresAfter(3600); //Cache for 1 hour
return $platformRegistry->getPlatform($platform)->getModelCatalog()->getModels();
});
return new JsonResponse($models);
}
}