dspy icon indicating copy to clipboard operation
dspy copied to clipboard

Easier api for transforming modules with assertions

Open Shangyint opened this issue 6 months ago • 6 comments

Now, it is possible to write assert_transform_module(module) to transform a module to handle suggestions and assertions. The default behavior is implemented by the backtrack_handler, which automatically backtracks for failing assertions and suggestions.

Shangyint avatar Feb 08 '24 00:02 Shangyint

That’s so cool! Can we also shorten that function’s name?

Or even make it a module method?

program.activate_assertions()

okhat avatar Feb 08 '24 00:02 okhat

Great advice! Now we can do:

a = Program()
a.activate_assertions()
# now a can backtrack and self-refine

or

teleprompter.compile(student=Program().activate_assertions())

Shangyint avatar Feb 08 '24 02:02 Shangyint

Amazing! Before I merge,

will this break existing code?

is it an in-place or new-value method? either one is fine just checking

okhat avatar Feb 08 '24 02:02 okhat

Yes. And it shouldn't break any existing code! Could you double check both the old and new api works @arnavsinghvi11?

Shangyint avatar Feb 08 '24 02:02 Shangyint

Arnav’s answer implies it is NOT in place, just to be sure right?

okhat avatar Feb 08 '24 02:02 okhat

Thanks! Pushed a fix. Both should work now

Shangyint avatar Feb 08 '24 05:02 Shangyint

Looks good @Shangyint ! Just a small issue which relies on this change to be merged for activate_assertions() to work.

arnavsinghvi11 avatar Feb 11 '24 01:02 arnavsinghvi11