This issue proposes the addition of a MultiStepRewrite mutator, which allows a single content segment to be rewritten using multiple templated generation calls. This class can be used as a basis for subsequent library mutators or used directly from application code to support a specific mutation scenario.
This mutator will support more sophisticated, deep mutations by allowing successive generation calls that "thread" the prior prompt texts and results into the next template. This allows for a larger context to be accumulated before a final call to generate rewritten text.
usage example:
step1_template = """
Given a set of instructions and a critical style, produce a set of notes detailing how the instructions fall short of the critical style.
Instructions: {{{content}}}
Critical Style: {{{critical_style}}}
Notes about Critical Style:
"""
step2_template = """
{{{last_prompt}}}
{{{last_result}}}
Using your notes about the critical style, generate an updated set of instructions that addresses the shortcomings.
Updated Instructions:
"""
mutator = MultiStepRewrite(
path_descriptor={ "id": "instructions" },
templates=[ step1_template, step2_template ],
critical_style="Instructions should be precise and explicit, and proceed step by step"
)
The mutation specified above will be executed as follows:
The segment content is resolved from the node at id=instructions for the content variable
A Template is instantiated from the contents of step1_template and the content and critical_style variables will be passed to the template render function
Text is generated using the rendered template
A Template is instantiated from step2_template and will receive the content and critical_style variables in addition to last_prompt and last_result which contains the rendered prompt and generated text from the prior step
Text is generated using the rendered template and mutation proceeds as per normal, with the instructions node updated with the new contents
In addition to the special variables last_prompt and last_result, which are populated for all template renders after the first one, the caller can specify arbitrary additional template variables that will be passed to all template renders including the first one. critical_style is an example of such a variable.
This issue proposes the addition of a
MultiStepRewrite
mutator, which allows a single content segment to be rewritten using multiple templated generation calls. This class can be used as a basis for subsequent library mutators or used directly from application code to support a specific mutation scenario.This mutator will support more sophisticated, deep mutations by allowing successive generation calls that "thread" the prior prompt texts and results into the next template. This allows for a larger context to be accumulated before a final call to generate rewritten text.
usage example:
The mutation specified above will be executed as follows:
content
variablestep1_template
and thecontent
andcritical_style
variables will be passed to the template render functionstep2_template
and will receive thecontent
andcritical_style
variables in addition tolast_prompt
andlast_result
which contains the rendered prompt and generated text from the prior stepinstructions
node updated with the new contentsIn addition to the special variables
last_prompt
andlast_result
, which are populated for all template renders after the first one, the caller can specify arbitrary additional template variables that will be passed to all template renders including the first one.critical_style
is an example of such a variable.