Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MultiStepRewrite Mutator #47

Open
pbourke opened this issue Aug 21, 2024 · 0 comments · May be fixed by #50
Open

Add MultiStepRewrite Mutator #47

pbourke opened this issue Aug 21, 2024 · 0 comments · May be fixed by #50
Assignees

Comments

@pbourke
Copy link
Collaborator

pbourke commented Aug 21, 2024

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:

  1. The segment content is resolved from the node at id=instructions for the content variable
  2. 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
  3. Text is generated using the rendered template
  4. 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
  5. 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.

@pbourke pbourke self-assigned this Aug 21, 2024
@pbourke pbourke linked a pull request Sep 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant