Skip to content

Commit b0a40c9

Browse files
authored
feat: add support for OpenRouter in configuration (#93)
Resolves #88
1 parent a23b2d2 commit b0a40c9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public function getConfigTreeBuilder(): TreeBuilder
5353
->scalarNode('api_key')->isRequired()->end()
5454
->end()
5555
->end()
56+
->arrayNode('openrouter')
57+
->children()
58+
->scalarNode('api_key')->isRequired()->end()
59+
->end()
60+
->end()
5661
->end()
5762
->end()
5863
->arrayNode('chain')

src/DependencyInjection/LlmChainExtension.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
2929
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
3030
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory as OpenAIPlatformFactory;
31+
use PhpLlm\LlmChain\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
3132
use PhpLlm\LlmChain\Platform\Bridge\Voyage\Voyage;
33+
use PhpLlm\LlmChain\Platform\Model;
3234
use PhpLlm\LlmChain\Platform\ModelClientInterface;
3335
use PhpLlm\LlmChain\Platform\Platform;
3436
use PhpLlm\LlmChain\Platform\PlatformInterface;
@@ -204,6 +206,21 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
204206
return;
205207
}
206208

209+
if ('openrouter' === $type) {
210+
$platformId = 'llm_chain.platform.openrouter';
211+
$definition = (new Definition(Platform::class))
212+
->setFactory(OpenRouterPlatformFactory::class.'::create')
213+
->setAutowired(true)
214+
->setLazy(true)
215+
->addTag('proxy', ['interface' => PlatformInterface::class])
216+
->setArguments(['$apiKey' => $platform['api_key']])
217+
->addTag('llm_chain.platform');
218+
219+
$container->setDefinition($platformId, $definition);
220+
221+
return;
222+
}
223+
207224
if ('mistral' === $type) {
208225
$platformId = 'llm_chain.platform.mistral';
209226
$definition = (new Definition(Platform::class))
@@ -236,6 +253,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
236253
'llama' => Llama::class,
237254
'gemini' => Gemini::class,
238255
'mistral' => Mistral::class,
256+
'openrouter' => Model::class,
239257
default => throw new \InvalidArgumentException(sprintf('Model "%s" is not supported.', $modelName)),
240258
};
241259
$modelDefinition = new Definition($modelClass);

0 commit comments

Comments
 (0)