16
16
use PhpLlm \LlmChain \Bridge \OpenAI \PlatformFactory as OpenAIPlatformFactory ;
17
17
use PhpLlm \LlmChain \Bridge \Pinecone \Store as PineconeStore ;
18
18
use PhpLlm \LlmChain \Bridge \Voyage \Voyage ;
19
+ use PhpLlm \LlmChain \Chain ;
19
20
use PhpLlm \LlmChain \Chain \InputProcessor ;
20
21
use PhpLlm \LlmChain \Chain \OutputProcessor ;
22
+ use PhpLlm \LlmChain \Chain \StructuredOutput \ChainProcessor as StructureOutputProcessor ;
21
23
use PhpLlm \LlmChain \Chain \ToolBox \Attribute \AsTool ;
22
24
use PhpLlm \LlmChain \ChainInterface ;
23
25
use PhpLlm \LlmChain \Embedder ;
@@ -214,12 +216,15 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
214
216
$ container ->setDefinition ('llm_chain.chain. ' .$ name .'.llm ' , $ llmDefinition );
215
217
216
218
// CHAIN
217
- $ chainDefinition = (new ChildDefinition ('llm_chain.chain.abstract ' ))
218
- ->replaceArgument ('$platform ' , new Reference ($ config ['platform ' ]))
219
- ->replaceArgument ('$llm ' , new Reference ('llm_chain.chain. ' .$ name .'.llm ' ));
219
+ $ chainDefinition = (new Definition (Chain::class))
220
+ ->setArgument ('$platform ' , new Reference ($ config ['platform ' ]))
221
+ ->setArgument ('$llm ' , new Reference ('llm_chain.chain. ' .$ name .'.llm ' ));
222
+
223
+ $ inputProcessor = [];
224
+ $ outputProcessor = [];
220
225
221
226
// TOOL & PROCESSOR
222
- if (isset ( $ config [ ' tools ' ]) && 0 !== count ($ config ['tools ' ])) {
227
+ if (0 !== count ($ config ['tools ' ])) {
223
228
$ tools = array_map (static fn (string $ tool ) => new Reference ($ tool ), $ config ['tools ' ]);
224
229
$ toolboxDefinition = (new ChildDefinition ('llm_chain.toolbox.abstract ' ))
225
230
->replaceArgument ('$tools ' , $ tools );
@@ -238,9 +243,18 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
238
243
->replaceArgument ('$toolBox ' , new Reference ('llm_chain.toolbox. ' .$ name ));
239
244
$ container ->setDefinition ('llm_chain.tool.chain_processor. ' .$ name , $ toolProcessorDefinition );
240
245
241
- $ chainDefinition ->replaceArgument ('$inputProcessor ' , [new Reference ('llm_chain.tool.chain_processor. ' .$ name )]);
242
- $ chainDefinition ->replaceArgument ('$outputProcessor ' , [new Reference ('llm_chain.tool.chain_processor. ' .$ name )]);
246
+ $ inputProcessor [] = new Reference ('llm_chain.tool.chain_processor. ' .$ name );
247
+ $ outputProcessor [] = new Reference ('llm_chain.tool.chain_processor. ' .$ name );
248
+ }
249
+
250
+ // STRUCTURED OUTPUT
251
+ if ($ config ['structured_output ' ]) {
252
+ $ inputProcessor [] = new Reference (StructureOutputProcessor::class);
253
+ $ outputProcessor [] = new Reference (StructureOutputProcessor::class);
243
254
}
255
+ $ chainDefinition
256
+ ->setArgument ('$inputProcessor ' , $ inputProcessor )
257
+ ->setArgument ('$outputProcessor ' , $ outputProcessor );
244
258
245
259
$ container ->setDefinition ('llm_chain.chain. ' .$ name , $ chainDefinition );
246
260
}
0 commit comments