9
9
use PhpLlm \LlmChain \Bridge \Azure \OpenAI \PlatformFactory as AzureOpenAIPlatformFactory ;
10
10
use PhpLlm \LlmChain \Bridge \Azure \Store \SearchStore as AzureSearchStore ;
11
11
use PhpLlm \LlmChain \Bridge \ChromaDB \Store as ChromaDBStore ;
12
+ use PhpLlm \LlmChain \Bridge \Google \Gemini ;
13
+ use PhpLlm \LlmChain \Bridge \Google \PlatformFactory as GooglePlatformFactory ;
12
14
use PhpLlm \LlmChain \Bridge \Meta \Llama ;
13
15
use PhpLlm \LlmChain \Bridge \MongoDB \Store as MongoDBStore ;
14
16
use PhpLlm \LlmChain \Bridge \OpenAI \Embeddings ;
23
25
use PhpLlm \LlmChain \Chain \StructuredOutput \ChainProcessor as StructureOutputProcessor ;
24
26
use PhpLlm \LlmChain \Chain \ToolBox \Attribute \AsTool ;
25
27
use PhpLlm \LlmChain \Chain \ToolBox \ChainProcessor as ToolProcessor ;
28
+ use PhpLlm \LlmChain \Chain \ToolBox \FaultTolerantToolBox ;
26
29
use PhpLlm \LlmChain \ChainInterface ;
27
30
use PhpLlm \LlmChain \Embedder ;
28
31
use PhpLlm \LlmChain \Model \EmbeddingsModel ;
@@ -132,16 +135,22 @@ public function load(array $configs, ContainerBuilder $container): void
132
135
*/
133
136
private function processPlatformConfig (string $ type , array $ platform , ContainerBuilder $ container ): void
134
137
{
135
- if ('openai ' === $ type ) {
136
- $ platformId = 'llm_chain.platform.openai ' ;
138
+ if ('anthropic ' === $ type ) {
139
+ $ platformId = 'llm_chain.platform.anthropic ' ;
137
140
$ definition = (new Definition (Platform::class))
138
- ->setFactory (OpenAIPlatformFactory ::class.'::create ' )
141
+ ->setFactory (AnthropicPlatformFactory ::class.'::create ' )
139
142
->setAutowired (true )
140
143
->setLazy (true )
141
144
->addTag ('proxy ' , ['interface ' => PlatformInterface::class])
142
- ->setArguments (['$apiKey ' => $ platform ['api_key ' ]])
145
+ ->setArguments ([
146
+ '$apiKey ' => $ platform ['api_key ' ],
147
+ ])
143
148
->addTag ('llm_chain.platform ' );
144
149
150
+ if (isset ($ platform ['version ' ])) {
151
+ $ definition ->replaceArgument ('$version ' , $ platform ['version ' ]);
152
+ }
153
+
145
154
$ container ->setDefinition ($ platformId , $ definition );
146
155
147
156
return ;
@@ -169,21 +178,30 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
169
178
return ;
170
179
}
171
180
172
- if ('anthropic ' === $ type ) {
173
- $ platformId = 'llm_chain.platform.anthropic ' ;
181
+ if ('google ' === $ type ) {
182
+ $ platformId = 'llm_chain.platform.google ' ;
174
183
$ definition = (new Definition (Platform::class))
175
- ->setFactory (AnthropicPlatformFactory ::class.'::create ' )
184
+ ->setFactory (GooglePlatformFactory ::class.'::create ' )
176
185
->setAutowired (true )
177
186
->setLazy (true )
178
187
->addTag ('proxy ' , ['interface ' => PlatformInterface::class])
179
- ->setArguments ([
180
- '$apiKey ' => $ platform ['api_key ' ],
181
- ])
188
+ ->setArguments (['$apiKey ' => $ platform ['api_key ' ]])
182
189
->addTag ('llm_chain.platform ' );
183
190
184
- if (isset ($ platform ['version ' ])) {
185
- $ definition ->replaceArgument ('$version ' , $ platform ['version ' ]);
186
- }
191
+ $ container ->setDefinition ($ platformId , $ definition );
192
+
193
+ return ;
194
+ }
195
+
196
+ if ('openai ' === $ type ) {
197
+ $ platformId = 'llm_chain.platform.openai ' ;
198
+ $ definition = (new Definition (Platform::class))
199
+ ->setFactory (OpenAIPlatformFactory::class.'::create ' )
200
+ ->setAutowired (true )
201
+ ->setLazy (true )
202
+ ->addTag ('proxy ' , ['interface ' => PlatformInterface::class])
203
+ ->setArguments (['$apiKey ' => $ platform ['api_key ' ]])
204
+ ->addTag ('llm_chain.platform ' );
187
205
188
206
$ container ->setDefinition ($ platformId , $ definition );
189
207
@@ -205,6 +223,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
205
223
'gpt ' => GPT ::class,
206
224
'claude ' => Claude::class,
207
225
'llama ' => Llama::class,
226
+ 'gemini ' => Gemini::class,
208
227
default => throw new \InvalidArgumentException (sprintf ('Model "%s" is not supported. ' , $ modelName )),
209
228
};
210
229
$ llmDefinition = new Definition ($ llmClass );
@@ -235,6 +254,14 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
235
254
->replaceArgument ('$tools ' , $ tools );
236
255
$ container ->setDefinition ('llm_chain.toolbox. ' .$ name , $ toolboxDefinition );
237
256
257
+ if ($ config ['fault_tolerant_toolbox ' ]) {
258
+ $ faultTolerantToolboxDefinition = (new Definition ('llm_chain.fault_tolerant_toolbox. ' .$ name ))
259
+ ->setClass (FaultTolerantToolBox::class)
260
+ ->setAutowired (true )
261
+ ->setDecoratedService ('llm_chain.toolbox. ' .$ name );
262
+ $ container ->setDefinition ('llm_chain.fault_tolerant_toolbox. ' .$ name , $ faultTolerantToolboxDefinition );
263
+ }
264
+
238
265
if ($ container ->getParameter ('kernel.debug ' )) {
239
266
$ traceableToolboxDefinition = (new Definition ('llm_chain.traceable_toolbox. ' .$ name ))
240
267
->setClass (TraceableToolBox::class)
0 commit comments