From 25ced0d660a9871c3803271900f88e1c58f20d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 26 Apr 2026 01:19:25 +0200 Subject: [PATCH] Added workaround to make lmstudio accept all models --- src/Services/AI/AcceptAllModelsCatalog.php | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Services/AI/AcceptAllModelsCatalog.php diff --git a/src/Services/AI/AcceptAllModelsCatalog.php b/src/Services/AI/AcceptAllModelsCatalog.php new file mode 100644 index 00000000..b3b68135 --- /dev/null +++ b/src/Services/AI/AcceptAllModelsCatalog.php @@ -0,0 +1,59 @@ +. + */ + +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(); + } +}