Would transforming be possible as well? #17
-
Hi, I just stumbled across this library by chance and I was wondering if transformation from structured to structured while applying context would also be possible? This would be super useful for translating or transforming existing models. class Project {
public string $title;
public string $description;
} Then you have an existing project like so: $project = new Project('A wonderful project', 'This is a superbe description meant for amateurs in the field of wonderful projects.'); Now what I would like to do is something like this: $translatedProject = (new Instructor())->respond(
messages: [['role' => 'user', 'content' => 'Translate the project description into German and make sure it is translated so that an amateur would understand it. Leave the project title as is.']],
requestModel: $project,
responseModel: Project::class,
);
var_dump($translatedProject->title); // A wonderful project
var_dump($translatedProject->description); // Something smart in German :-) Do you think that's at all possible? And would it fit this library? It's kind of also instructing and working with structured data.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Apologies for late response, I've missed this question. It is possible to achieve 'structure to structure' processing. I'm currently working on more documentation for the "language programs", the new capability that is already present in the codebase on GitHub and will be formally announced and documented in the next release. Language programs are the way to use Instructor capabilities to execute multiple steps of LLM inference and conventional processing with structured data, also transforming the data to different structures between the steps. The idea is inspired by DSPy for Python (although initially DSPy has been focused on processing text based content with LLMs and avoiding manual prompting). As Instructor natively works with structured data, I felt it would be good to have a modular, controllable way to process and transform data structures, but also intertwine LLM processing steps with more controllable conventional processing with regular code. This way data can be taken from external sources, transformed with (and without) LLM support, validated and finally pushed out to target destinations. You can check the early preview here: It may not be very clear what is happening in the example just looking at the code, but should give you a general feeling what's possible. The documentation is going to be available soon and it will clarify how to use the new capabilities and what might be the applications. |
Beta Was this translation helpful? Give feedback.
-
Another example showing multi-step LLM based processing: |
Beta Was this translation helpful? Give feedback.
Apologies for late response, I've missed this question. It is possible to achieve 'structure to structure' processing.
I'm currently working on more documentation for the "language programs", the new capability that is already present in the codebase on GitHub and will be formally announced and documented in the next release.
Language programs are the way to use Instructor capabilities to execute multiple steps of LLM inference and conventional processing with structured data, also transforming the data to different structures between the steps. The idea is inspired by DSPy for Python (although initially DSPy has been focused on processing text based content with LLMs and avoiding manual …