. */ declare(strict_types=1); namespace App\Services\AI; use Symfony\AI\Platform\Exception\ModelNotFoundException; use Symfony\AI\Platform\Model; use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface; use Symfony\Component\DependencyInjection\Attribute\AsDecorator; /** * This is a wrapper, to allow accepting all models, even if they are not contained in the decorated ModelCatalogInterface. * This is a workaround for outdated/incomplete model catalogs provided by AI platforms, which do not contain all available models, or do not update their catalogs frequently enough. */ #[AsDecorator('ai.platform.model_catalog.lmstudio')] final readonly class AcceptAllModelsCatalog implements ModelCatalogInterface { public function __construct(private ModelCatalogInterface $decorated) { } public function getModel(string $modelName): Model { //Use the actual values when its available. try { return $this->decorated->getModel($modelName); } catch (ModelNotFoundException $e) { //If the model is not found, return a generic model with the given name and no capabilities. return new Model($modelName, []); } } public function getModels(): array { //Return the actual models catalog here for correct autocompletition return $this->decorated->getModels(); } }