You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instructor provides an addon allowing to implement complex processing flows
4
+
using LLM in a modular way. This addon to Instructor has been inspired by DSPy
5
+
library for Python (https://github.com/stanfordnlp/dspy).
6
+
7
+
This example demonstrates multistep processing with LLMs:
8
+
- parse text to extract email data from text (sender, subject and content) -> result is an object containing parsed email data
9
+
- fix spelling mistakes in the subject and content fields -> result is an object containing fixed email subject and content
10
+
- translate subject into specified language -> result is an object containing translated data
11
+
12
+
All the steps are packaged into a single, reusable module, which is easy to call via:
13
+
14
+
```
15
+
(new ProcessEmail)->withArgs(
16
+
text: $text,
17
+
language: $language,
18
+
);
19
+
```
20
+
21
+
`ProcessEmail` inherits from a `Module`, which is a base class for Instructor modules. It returns a predefined object containing, in this case, the data from all steps of processing.
22
+
23
+
The outputs and flow can be arbitrarily shaped to the needs of specific use case (within the bounds of how Module & Predict components work).
24
+
25
+
```php
26
+
<?php
27
+
28
+
use Cognesy\Instructor\Extras\Module\Addons\Predict\Predict;
29
+
use Cognesy\Instructor\Extras\Module\Core\Module;
30
+
use Cognesy\Instructor\Extras\Module\Signature\Attributes\InputField;
31
+
use Cognesy\Instructor\Extras\Module\Signature\Attributes\OutputField;
32
+
use Cognesy\Instructor\Extras\Module\CallData\SignatureData;
33
+
use Cognesy\Instructor\Instructor;
34
+
use Cognesy\Instructor\Schema\Attributes\Description;
0 commit comments