Skip to content

Commit 2efbd12

Browse files
committed
feature #712 [Platform] Support model size variants (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Platform] Support model size variants | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | yes | Issues | Fix #708 | License | MIT Another apporach to #708 Commits ------- c401326 [Platform] Support model size variants
2 parents 39c8a64 + c401326 commit 2efbd12

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/platform/doc/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ supports a specific feature, like ``Capability::INPUT_AUDIO`` or ``Capability::O
6767
**Options** are additional parameters that can be passed to the model, like ``temperature`` or ``max_tokens``, and are
6868
usually defined by the specific models and their documentation.
6969

70+
**Model Size Variants**
71+
72+
For providers like Ollama, you can specify model size variants using a colon notation (e.g., ``qwen3:32b``, ``llama3:7b``).
73+
If the exact model name with size variant is not found in the catalog, the system will automatically fall back to the base
74+
model name (``qwen3``, ``llama3``) and use its capabilities while preserving the full model name for the provider.
75+
76+
You can also combine size variants with query parameters::
77+
78+
use Symfony\AI\Platform\Bridge\Ollama\ModelCatalog;
79+
80+
$catalog = new ModelCatalog();
81+
82+
// Get model with size variant
83+
$model = $catalog->getModel('qwen3:32b');
84+
85+
// Get model with size variant and query parameters
86+
$model = $catalog->getModel('qwen3:32b?temperature=0.5&top_p=0.9');
87+
7088
**Supported Models & Platforms**
7189

7290
* **Language Models**

src/platform/src/ModelCatalog/AbstractModelCatalog.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ public function getModel(string $modelName): Model
3232
throw new InvalidArgumentException('Model name cannot be empty.');
3333
}
3434

35-
$parsed = self::parseModelName($modelName);
35+
$parsed = $this->parseModelName($modelName);
3636
$actualModelName = $parsed['name'];
37+
$catalogKey = $parsed['catalogKey'];
3738
$options = $parsed['options'];
3839

39-
if (!isset($this->models[$actualModelName])) {
40+
if (!isset($this->models[$catalogKey])) {
4041
throw new ModelNotFoundException(\sprintf('Model "%s" not found.', $actualModelName));
4142
}
4243

43-
$modelConfig = $this->models[$actualModelName];
44+
$modelConfig = $this->models[$catalogKey];
4445
$modelClass = $modelConfig['class'];
4546

4647
if (!class_exists($modelClass)) {
@@ -65,12 +66,13 @@ public function getModels(): array
6566

6667
/**
6768
* Extracts model name and options from a model name string that may contain query parameters.
69+
* Also resolves size variants (e.g., "model:23b") to their base model for catalog lookup.
6870
*
6971
* @param string $modelName The model name, potentially with query parameters (e.g., "model-name?param=value&other=123")
7072
*
71-
* @return array{name: string, options: array<string, mixed>} An array containing the model name and parsed options
73+
* @return array{name: string, catalogKey: string, options: array<string, mixed>} An array containing the model name, catalog lookup key, and parsed options
7274
*/
73-
protected static function parseModelName(string $modelName): array
75+
protected function parseModelName(string $modelName): array
7476
{
7577
$options = [];
7678
$actualModelName = $modelName;
@@ -87,8 +89,18 @@ protected static function parseModelName(string $modelName): array
8789
$options = self::convertNumericStrings($options);
8890
}
8991

92+
// Determine catalog key: try exact match first, then fall back to base model
93+
$catalogKey = $actualModelName;
94+
if (!isset($this->models[$actualModelName]) && str_contains($actualModelName, ':')) {
95+
$baseModelName = explode(':', $actualModelName, 2)[0];
96+
if (isset($this->models[$baseModelName])) {
97+
$catalogKey = $baseModelName;
98+
}
99+
}
100+
90101
return [
91102
'name' => $actualModelName,
103+
'catalogKey' => $catalogKey,
92104
'options' => $options,
93105
];
94106
}

src/platform/tests/Bridge/Ollama/ModelCatalogTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static function modelsProvider(): iterable
3030
yield 'llama3' => ['llama3', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
3131
yield 'mistral' => ['mistral', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
3232
yield 'qwen3' => ['qwen3', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
33+
yield 'qwen3:32b' => ['qwen3:32b', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
3334
yield 'qwen' => ['qwen', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
3435
yield 'qwen2' => ['qwen2', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
3536
yield 'qwen2.5' => ['qwen2.5', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::TOOL_CALLING]];
@@ -45,6 +46,7 @@ public static function modelsProvider(): iterable
4546
yield 'nomic-embed-text' => ['nomic-embed-text', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::INPUT_MULTIPLE]];
4647
yield 'bge-m3' => ['bge-m3', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::INPUT_MULTIPLE]];
4748
yield 'all-minilm' => ['all-minilm', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::INPUT_MULTIPLE]];
49+
yield 'all-minilm:33m' => ['all-minilm:33m', Ollama::class, [Capability::INPUT_MESSAGES, Capability::OUTPUT_TEXT, Capability::OUTPUT_STRUCTURED, Capability::INPUT_MULTIPLE]];
4850
}
4951

5052
protected function createModelCatalog(): ModelCatalogInterface

0 commit comments

Comments
 (0)