def generate_prompt()

in experiments/google/cloud/ml/applied/attributes/attributes.py [0:0]


def generate_prompt(desc: str, candidates: list[dict]) -> str:
    """Populate LLM prompt template.

    Args:
        desc: product description
        candidates: list of dicts with the following keys:
            attributes: attributes in dict form e.g. {'color':'green', 'pattern': 'striped'}
            description: string describing product

    Returns: prompt to feed to LLM
    """
    examples = ""
    for candidate in candidates:
        examples += "Description: " + candidate["description"] + "\n"
        examples += (
            "Attributes:\n"
            + "|".join([k + ":" + v for k, v in candidate["attributes"].items()])
            + "\n\n"
        )

    prompt = f"""
Here are examples of Product Descriptions followed by Attributes:

{examples}

INSTRUCTIONS:
Generate attributes based on the description below.
Each attribute should be a key:value pair.
Do not write any values that contain "NA" on the list. Examples "Material: NA" or "Type: NA"
Use a pipe separator "|" to separate attributes.

Description: {desc}
Attributes:
    """
    return prompt