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

Refined prompt construction for feedback #1058

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

piotrm0
Copy link
Contributor

@piotrm0 piotrm0 commented Apr 8, 2024

Items to add to release announcement:

  • Heading: delete this list if this PR does not introduce any changes that need announcing.

Other details that are good to know but need not be announced:

  • There should be something here at least.

Work in progress. Designing prompts for feedback from several common parts and allow different sizes of such prompts depending on the allowable space:

class ScoringPromptBase(SerialModel):
        """Common parts to build a scoring prompt out of."""

        prefix_template: str = """"""
        """Text to include before all other parts."""

        interp_template:str = """You are a {purpose} scorer."""
        details_template: str = """"""

        low_score: int = 1
        high_score: int = 10

        shots_template: str = """EXAMPLES:"""
        shot_template: str = """
INPUTS:
{shot_inputs}
EXPECTED OUTPUT: {shot_output}"""

        suffix_template = """
Answer only with an integer from {low_score} ({low_interp}) to {high_score} ({high_interp}).

INPUTS:
{inputs}
SCORE: """
        """Text to include after all other parts."""

    class ScoringPrompt(ScoringPromptBase):
        """Specific parts to build a scoring prompt out of."""

        interp: str
        """Minimal interpretation of the score."""

        low_interp: str
        """Interpretation of a low score."""

        high_interp: str
        """Interpretation of a high score."""

        details: str
        """Text to include after the purpose to provide some more details about
        the purpose."""

        shots: List[Tuple[Dict[str, str], int]] = []

        def build(
            self,
            max_tokens: int = sys.maxsize,
            inputs: Optional[Dict[str, str]] = None
        ) -> str:
            """Build a prompt for the given inputs while staying under the token
            limit.
            
            The built prompt will have at least:
                - filled prefix_template,
                - filled interp_template,
                - filled suffix_template.

            If space allows, it will also include:
                - filled details_template,
                - filled shots_template (if at least one of the below is
                  included),
                - filled in shot_template for each shot.

            Args:
                max_tokens: The maximum number of tokens to use. Defaults to
                    sys.maxsize (effectively infinite).

                inputs: The inputs to fill in the prompts
                    with other than the ones defining the scoring task. Those
                    are contained in self.
            
            Returns:
                str: The built prompt.

            Raises:
                ValueError: If the prompt would be too long to fit within the
                    token limit even at its miminum size.

            """

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 8, 2024
@piotrm0 piotrm0 marked this pull request as draft April 8, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant