File tree 3 files changed +28
-5
lines changed
3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 13
13
14
14
final readonly class Chain
15
15
{
16
+ /**
17
+ * @var InputProcessor[]
18
+ */
19
+ private array $ inputProcessor ;
20
+
21
+ /**
22
+ * @var OutputProcessor[]
23
+ */
24
+ private array $ outputProcessor ;
25
+
16
26
/**
17
27
* @param InputProcessor[] $inputProcessor
18
28
* @param OutputProcessor[] $outputProcessor
19
29
*/
20
30
public function __construct (
21
31
private LanguageModel $ llm ,
22
- private array $ inputProcessor = [],
23
- private array $ outputProcessor = [],
32
+ iterable $ inputProcessor = [],
33
+ iterable $ outputProcessor = [],
24
34
) {
35
+ $ this ->inputProcessor = $ inputProcessor instanceof \Traversable ? iterator_to_array ($ inputProcessor ) : $ inputProcessor ;
36
+ $ this ->outputProcessor = $ outputProcessor instanceof \Traversable ? iterator_to_array ($ outputProcessor ) : $ outputProcessor ;
25
37
}
26
38
27
39
/**
Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ public function __construct(
23
23
24
24
public function processInput (Input $ input ): void
25
25
{
26
+ $ options = $ input ->getOptions ();
27
+
28
+ if (!isset ($ options ['output_structure ' ])) {
29
+ return ;
30
+ }
31
+
26
32
if (!$ input ->llm ->supportsStructuredOutput ()) {
27
33
throw MissingModelSupport::forStructuredOutput ($ input ->llm ::class);
28
34
}
29
35
30
- $ options = $ input ->getOptions ();
31
36
$ options ['response_format ' ] = $ this ->responseFormatFactory ->create ($ options ['output_structure ' ]);
32
37
33
38
$ this ->outputStructure = $ options ['output_structure ' ];
@@ -36,8 +41,14 @@ public function processInput(Input $input): void
36
41
$ input ->setOptions ($ options );
37
42
}
38
43
39
- public function processOutput (Output $ output ): object
44
+ public function processOutput (Output $ output ): ? object
40
45
{
46
+ $ options = $ output ->options ;
47
+
48
+ if (!isset ($ options ['output_structure ' ])) {
49
+ return null ;
50
+ }
51
+
41
52
return $ this ->serializer ->deserialize ($ output ->response ->getContent (), $ this ->outputStructure , 'json ' );
42
53
}
43
54
}
Original file line number Diff line number Diff line change 14
14
final readonly class ChainProcessor implements InputProcessor, OutputProcessor
15
15
{
16
16
public function __construct (
17
- private ToolBox $ toolBox ,
17
+ private ToolBoxInterface $ toolBox ,
18
18
) {
19
19
}
20
20
You can’t perform that action at this time.
0 commit comments