Skip to content

Commit 25ced0d

Browse files
committed
Added workaround to make lmstudio accept all models
1 parent 18bf07b commit 25ced0d

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Services\AI;
25+
26+
use Symfony\AI\Platform\Exception\ModelNotFoundException;
27+
use Symfony\AI\Platform\Model;
28+
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
29+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
30+
31+
/**
32+
* This is a wrapper, to allow accepting all models, even if they are not contained in the decorated ModelCatalogInterface.
33+
* 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.
34+
*/
35+
#[AsDecorator('ai.platform.model_catalog.lmstudio')]
36+
final readonly class AcceptAllModelsCatalog implements ModelCatalogInterface
37+
{
38+
39+
public function __construct(private ModelCatalogInterface $decorated)
40+
{
41+
}
42+
43+
public function getModel(string $modelName): Model
44+
{
45+
//Use the actual values when its available.
46+
try {
47+
return $this->decorated->getModel($modelName);
48+
} catch (ModelNotFoundException $e) {
49+
//If the model is not found, return a generic model with the given name and no capabilities.
50+
return new Model($modelName, []);
51+
}
52+
}
53+
54+
public function getModels(): array
55+
{
56+
//Return the actual models catalog here for correct autocompletition
57+
return $this->decorated->getModels();
58+
}
59+
}

0 commit comments

Comments
 (0)