This repository was archived by the owner on Jul 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed
Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 1313
1414final readonly class Chain
1515{
16+ /**
17+ * @var InputProcessor[]
18+ */
19+ private array $ inputProcessor ;
20+
21+ /**
22+ * @var OutputProcessor[]
23+ */
24+ private array $ outputProcessor ;
25+
1626 /**
1727 * @param InputProcessor[] $inputProcessor
1828 * @param OutputProcessor[] $outputProcessor
1929 */
2030 public function __construct (
2131 private LanguageModel $ llm ,
22- private array $ inputProcessor = [],
23- private array $ outputProcessor = [],
32+ iterable $ inputProcessor = [],
33+ iterable $ outputProcessor = [],
2434 ) {
35+ $ this ->inputProcessor = $ inputProcessor instanceof \Traversable ? iterator_to_array ($ inputProcessor ) : $ inputProcessor ;
36+ $ this ->outputProcessor = $ outputProcessor instanceof \Traversable ? iterator_to_array ($ outputProcessor ) : $ outputProcessor ;
2537 }
2638
2739 /**
Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ public function __construct(
2323
2424 public function processInput (Input $ input ): void
2525 {
26+ $ options = $ input ->getOptions ();
27+
28+ if (!isset ($ options ['output_structure ' ])) {
29+ return ;
30+ }
31+
2632 if (!$ input ->llm ->supportsStructuredOutput ()) {
2733 throw MissingModelSupport::forStructuredOutput ($ input ->llm ::class);
2834 }
2935
30- $ options = $ input ->getOptions ();
3136 $ options ['response_format ' ] = $ this ->responseFormatFactory ->create ($ options ['output_structure ' ]);
3237
3338 $ this ->outputStructure = $ options ['output_structure ' ];
@@ -36,8 +41,14 @@ public function processInput(Input $input): void
3641 $ input ->setOptions ($ options );
3742 }
3843
39- public function processOutput (Output $ output ): object
44+ public function processOutput (Output $ output ): ? object
4045 {
46+ $ options = $ output ->options ;
47+
48+ if (!isset ($ options ['output_structure ' ])) {
49+ return null ;
50+ }
51+
4152 return $ this ->serializer ->deserialize ($ output ->response ->getContent (), $ this ->outputStructure , 'json ' );
4253 }
4354}
Original file line number Diff line number Diff line change 1414final readonly class ChainProcessor implements InputProcessor, OutputProcessor
1515{
1616 public function __construct (
17- private ToolBox $ toolBox ,
17+ private ToolBoxInterface $ toolBox ,
1818 ) {
1919 }
2020
You can’t perform that action at this time.
0 commit comments