Skip to content

Commit 30fbe63

Browse files
committed
fix(embedder): Use FQCN for embedder model config, to allow any Model child class
1 parent 50c2bf3 commit 30fbe63

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function getConfigTreeBuilder(): TreeBuilder
197197
->end()
198198
->arrayNode('model')
199199
->children()
200-
->scalarNode('name')->isRequired()->end()
200+
->scalarNode('className')->isRequired()->end()
201201
->scalarNode('version')->defaultNull()->end()
202202
->arrayNode('options')
203203
->scalarPrototype()->end()

src/DependencyInjection/LlmChainExtension.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
use PhpLlm\LlmChain\Platform\Bridge\Meta\Llama;
2626
use PhpLlm\LlmChain\Platform\Bridge\Mistral\Mistral;
2727
use PhpLlm\LlmChain\Platform\Bridge\Mistral\PlatformFactory as MistralPlatformFactory;
28-
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
2928
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
3029
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory as OpenAIPlatformFactory;
3130
use PhpLlm\LlmChain\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
32-
use PhpLlm\LlmChain\Platform\Bridge\Voyage\Voyage;
3331
use PhpLlm\LlmChain\Platform\Model;
3432
use PhpLlm\LlmChain\Platform\ModelClientInterface;
3533
use PhpLlm\LlmChain\Platform\Platform;
@@ -457,14 +455,13 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
457455
*/
458456
private function processEmbedderConfig(int|string $name, array $config, ContainerBuilder $container): void
459457
{
460-
['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model'];
458+
['className' => $modelClassName, 'version' => $version, 'options' => $options] = $config['model'];
461459

462-
$modelClass = match (strtolower((string) $modelName)) {
463-
'embeddings' => Embeddings::class,
464-
'voyage' => Voyage::class,
465-
default => throw new \InvalidArgumentException(sprintf('Model "%s" is not supported.', $modelName)),
466-
};
467-
$modelDefinition = (new Definition($modelClass));
460+
if (!is_a($modelClassName, Model::class, true)) {
461+
throw new \InvalidArgumentException(sprintf('"%s" class is not extending PhpLlm\LlmChain\Platform\Model.', $modelClassName));
462+
}
463+
464+
$modelDefinition = (new Definition((string) $modelClassName));
468465
if (null !== $version) {
469466
$modelDefinition->setArgument('$name', $version);
470467
}

0 commit comments

Comments
 (0)