Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('api_key')->isRequired()->end()
->end()
->end()
->arrayNode('openrouter')
->children()
->scalarNode('api_key')->isRequired()->end()
->end()
->end()
->end()
->end()
->arrayNode('chain')
Expand Down
18 changes: 18 additions & 0 deletions src/DependencyInjection/LlmChainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory as OpenAIPlatformFactory;
use PhpLlm\LlmChain\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
use PhpLlm\LlmChain\Platform\Bridge\Voyage\Voyage;
use PhpLlm\LlmChain\Platform\Model;
use PhpLlm\LlmChain\Platform\ModelClientInterface;
use PhpLlm\LlmChain\Platform\Platform;
use PhpLlm\LlmChain\Platform\PlatformInterface;
Expand Down Expand Up @@ -204,6 +206,21 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
return;
}

if ('openrouter' === $type) {
$platformId = 'llm_chain.platform.openrouter';
$definition = (new Definition(Platform::class))
->setFactory(OpenRouterPlatformFactory::class.'::create')
->setAutowired(true)
->setLazy(true)
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments(['$apiKey' => $platform['api_key']])
->addTag('llm_chain.platform');

$container->setDefinition($platformId, $definition);

return;
}

if ('mistral' === $type) {
$platformId = 'llm_chain.platform.mistral';
$definition = (new Definition(Platform::class))
Expand Down Expand Up @@ -236,6 +253,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
'llama' => Llama::class,
'gemini' => Gemini::class,
'mistral' => Mistral::class,
'openrouter' => Model::class,
default => throw new \InvalidArgumentException(sprintf('Model "%s" is not supported.', $modelName)),
};
$modelDefinition = new Definition($modelClass);
Expand Down
Loading