Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mellea/stdlib/instruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Instructions."""

from __future__ import annotations

from copy import deepcopy

import jinja2
Expand Down Expand Up @@ -106,6 +108,7 @@ def __init__(
self._output_prefix = (
blockify(output_prefix) if output_prefix is not None else None
)
self._repair_string: str | None = None

def parts(self):
"""Returns all of the constituent parts of an Instruction."""
Expand All @@ -132,6 +135,7 @@ def format_for_llm(self) -> TemplateRepresentation:
"output_prefix": (
self._output_prefix if self._output_prefix is not None else None
),
"repair": self._repair_string,
},
tools=None,
template_order=["*", "Instruction"],
Expand All @@ -147,3 +151,9 @@ def apply_user_dict_from_jinja(user_dict: dict[str, str], s: str) -> str:
def requirements(self) -> list[Requirement]:
"""Returns a list of Requirement instances."""
return self._requirements

def copy_and_repair(self, repair_string: str) -> Instruction:
"""Creates a copy of the instruction and adds/overwrites the repair string."""
res = deepcopy(self)
res._repair_string = repair_string
return res
Comment on lines +155 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you end up utilizing this copy_and_repair function anywhere? It looks like you opted for communicating the failed requirements as messages instead. If so, can you please remove the _repair changes to instructions and their templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably have to add an example of using this during a repair. Right now we only have "try again" without alteration and the agentic way..

Loading