Skip to content

Commit 1ac3431

Browse files
authored
fix: various fixes for bundle release 0.3 (#56)
1 parent ec118a0 commit 1ac3431

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/Chain.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,27 @@
1313

1414
final 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
/**

src/StructuredOutput/ChainProcessor.php

+13-2
Original file line numberDiff line numberDiff 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
}

src/ToolBox/ChainProcessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
final readonly class ChainProcessor implements InputProcessor, OutputProcessor
1515
{
1616
public function __construct(
17-
private ToolBox $toolBox,
17+
private ToolBoxInterface $toolBox,
1818
) {
1919
}
2020

0 commit comments

Comments
 (0)