1616use PhpLlm \LlmChain \Bridge \OpenAI \PlatformFactory as OpenAIPlatformFactory ;
1717use PhpLlm \LlmChain \Bridge \Pinecone \Store as PineconeStore ;
1818use PhpLlm \LlmChain \Bridge \Voyage \Voyage ;
19+ use PhpLlm \LlmChain \Chain ;
1920use PhpLlm \LlmChain \Chain \InputProcessor ;
2021use PhpLlm \LlmChain \Chain \OutputProcessor ;
22+ use PhpLlm \LlmChain \Chain \StructuredOutput \ChainProcessor as StructureOutputProcessor ;
2123use PhpLlm \LlmChain \Chain \ToolBox \Attribute \AsTool ;
2224use PhpLlm \LlmChain \ChainInterface ;
2325use PhpLlm \LlmChain \Embedder ;
@@ -214,12 +216,15 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
214216 $ container ->setDefinition ('llm_chain.chain. ' .$ name .'.llm ' , $ llmDefinition );
215217
216218 // 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 = [];
220225
221226 // TOOL & PROCESSOR
222- if (isset ( $ config [ ' tools ' ]) && 0 !== count ($ config ['tools ' ])) {
227+ if (0 !== count ($ config ['tools ' ])) {
223228 $ tools = array_map (static fn (string $ tool ) => new Reference ($ tool ), $ config ['tools ' ]);
224229 $ toolboxDefinition = (new ChildDefinition ('llm_chain.toolbox.abstract ' ))
225230 ->replaceArgument ('$tools ' , $ tools );
@@ -238,9 +243,18 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
238243 ->replaceArgument ('$toolBox ' , new Reference ('llm_chain.toolbox. ' .$ name ));
239244 $ container ->setDefinition ('llm_chain.tool.chain_processor. ' .$ name , $ toolProcessorDefinition );
240245
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);
243254 }
255+ $ chainDefinition
256+ ->setArgument ('$inputProcessor ' , $ inputProcessor )
257+ ->setArgument ('$outputProcessor ' , $ outputProcessor );
244258
245259 $ container ->setDefinition ('llm_chain.chain. ' .$ name , $ chainDefinition );
246260 }
0 commit comments