stanfordnlp / dspy

DSPy: The framework for programming—not prompting—language models
https://dspy.ai
MIT License
19.07k stars 1.46k forks source link

feat(dspy): extend incomplete generations #1613

Open mikeedjones opened 1 month ago

mikeedjones commented 1 month ago

If the output parsed by ChatAdapter.parse does not include all the fields required by the signature, the lm will be called again up to max_extensions times, with the thus-far completed output added to the input fields for the next generation.

Logic is wrapped up as a decorator to allow the logic to be reused by future Adapers.

Added tests for extended generation.

max_extensions defaults to 1 to maintain current behaviour.

Linting and formatting changes from ruff.