Skip to content

Commit 780e030

Browse files
committed
[BUGFIX] Adjust smart routing / model switching
1 parent 42dc8d0 commit 780e030

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

Classes/Domain/Model/AiProviderManifest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,23 @@ private function getSpecializedCapabilities(): array
9797
if ($this->modelCapabilities === []) {
9898
return [];
9999
}
100-
// Collect capabilities that ONLY appear in models with a reduced set
101-
$allProviderCapabilities = count($this->capabilities);
100+
// Use the maximum capability count of any listed model as the threshold.
101+
// Comparing against count($this->capabilities) (ALL_CAPABILITIES) breaks
102+
// when provider-level capabilities include interfaces no model in the
103+
// catalog supports (e.g. TranslationCapableInterface), because then every
104+
// model is considered "reduced" and every capability becomes specialized.
105+
$maxModelCapabilities = max(array_map('count', $this->modelCapabilities));
102106
$specialized = [];
103107
foreach ($this->modelCapabilities as $caps) {
104-
if (count($caps) < $allProviderCapabilities) {
108+
if (count($caps) < $maxModelCapabilities) {
105109
foreach ($caps as $cap) {
106110
$specialized[$cap] = true;
107111
}
108112
}
109113
}
110114
// Remove capabilities that also appear in models with the full set
111115
foreach ($this->modelCapabilities as $caps) {
112-
if (count($caps) >= $allProviderCapabilities) {
116+
if (count($caps) >= $maxModelCapabilities) {
113117
foreach ($caps as $cap) {
114118
unset($specialized[$cap]);
115119
}

Classes/Provider/ProviderResolver.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,18 @@ public function resolveAllForCapability(string $capabilityFqcn): array
330330
}
331331
}
332332

333-
$result = array_merge($defaults, $others);
334-
335-
// If no direct matches, try auto model switch
336-
if ($result === []) {
333+
// If no default directly supports the capability, try auto model switch first.
334+
// This ensures a default provider's alternative model (e.g. OpenAI → text-embedding-ada-002)
335+
// takes priority over a non-default that only claims support via empty modelCapabilities
336+
// (e.g. Ollama with a dynamic catalog where every model appears capable of everything).
337+
if ($defaults === []) {
337338
$switched = $this->tryAutoModelSwitch($capabilityFqcn, $configurations);
338339
if ($switched !== null) {
339-
$result[] = $switched;
340+
array_unshift($others, $switched);
340341
}
341342
}
342343

343-
return $result;
344+
return array_merge($defaults, $others);
344345
}
345346

346347
/**

0 commit comments

Comments
 (0)