|
32 | 32 | use Cognesy\Instructor\Extraction\Data\ExtractionInput; |
33 | 33 | use Cognesy\Instructor\Extraction\Exceptions\ExtractionException; |
34 | 34 | use Cognesy\Instructor\Extraction\Extractors\DirectJsonExtractor; |
| 35 | +use Cognesy\Instructor\Extraction\ResponseExtractor; |
35 | 36 | use Cognesy\Instructor\StructuredOutput; |
36 | 37 | use Cognesy\Instructor\StructuredOutputRuntime; |
37 | 38 | use Cognesy\Polyglot\Inference\LLMProvider; |
@@ -115,10 +116,10 @@ class Person { |
115 | 116 | // DirectJson is tried first (will fail), then XmlJsonExtractor (will succeed) |
116 | 117 | $person = new StructuredOutput( |
117 | 118 | StructuredOutputRuntime::fromProvider(LLMProvider::using('openai')) |
118 | | - ->withExtractors([ |
| 119 | + ->withExtractor(ResponseExtractor::fromExtractors( |
119 | 120 | new DirectJsonExtractor(), |
120 | 121 | new XmlJsonExtractor('json'), |
121 | | - ]) |
| 122 | + )) |
122 | 123 | ) |
123 | 124 | ->withResponseClass(Person::class) |
124 | 125 | ->withMessages("Extract: Alice Johnson, 28 years old, lives in San Francisco") |
@@ -180,10 +181,10 @@ class Person { |
180 | 181 | // Custom extractors work for streaming too |
181 | 182 | $stream = new StructuredOutput( |
182 | 183 | StructuredOutputRuntime::fromProvider(LLMProvider::using('openai')) |
183 | | - ->withExtractors([ |
| 184 | + ->withExtractor(ResponseExtractor::fromExtractors( |
184 | 185 | new DirectJsonExtractor(), |
185 | 186 | new XmlJsonExtractor('json'), |
186 | | - ]) |
| 187 | + )) |
187 | 188 | ) |
188 | 189 | ->withResponseClass(Person::class) |
189 | 190 | ->withMessages("Extract person data...") |
|
0 commit comments