Skip to content
8 changes: 6 additions & 2 deletions promptsource/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,19 @@ def apply(self, example, truncate=True, highlight_variables=False) -> Tuple[str,

# Splits on the separator, and then replaces back any occurrences of the
# separator in the original example
parts = [self._unescape_pipe(part).strip() for part in rendered_example.split("|||")]
parts = [self._unescape_pipe(part) for part in rendered_example.split("|||")]
if parts == [""]:
# Handles the case of blank results
# Example: `tydiqa` where prompts are conditionned on the language and thus most of the time will return a blank result
return parts
if len(parts) < 2:
raise ValueError("Prompt did not produce an input and at least one target.")

return parts[0], parts[1:]
# Remove double whitespace
if parts[0][-1] == " " and all(p[0] == " " for p in parts[1:]):
parts[0] = parts[0][:-1]

return parts[0].lstrip(), [p.rstrip() for p in parts[1:]]

pipe_protector = "3ed2dface8203c4c9dfb1a5dc58e41e0"

Expand Down
8 changes: 3 additions & 5 deletions promptsource/templates/great_code/templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ templates:
\ + fixed_token + ns.result_lines[ns.buggy_line][ns.bug_location + ns.bug_len:])\
\ | trim | replace(\" . \", \".\") | replace(\" , \", \", \") | replace(\"\
( \", \"(\") | replace(\" )\", \")\") | replace(\"[ \", \"[\") | replace(\"\
\ ]\", \"]\")%}\n\n Fix the buggy line: {{buggy_line_content}}\n |||\n\
\ {{fixed_buggy_line_content}}\n{% endif %}"
\ ]\", \"]\")%}\n\n Fix the buggy line: {{buggy_line_content}}\n|||\n{{fixed_buggy_line_content}}\n{% endif %}"
metadata: !TemplateMetadata
choices_in_prompt: false
languages:
Expand Down Expand Up @@ -91,7 +90,7 @@ templates:
\ %}\n {% endfor %}\n {{ns.result | join(\"\") | replace(\" . \", \".\"\
) | replace(\" , \", \", \") | replace(\"( \", \"(\") | replace(\" )\", \"\
)\") | replace(\"[ \", \"[\") | replace(\" ]\", \"]\")}}\n \n Given the\
\ code above, what is a proper replacement for {{mask}}?\n |||\n {{source_tokens[repair_targets[0]]}}\n\
\ code above, what is a proper replacement for {{mask}}?\n|||{{source_tokens[repair_targets[0]]}}\n\
{% endif %}"
metadata: !TemplateMetadata
choices_in_prompt: false
Expand Down Expand Up @@ -150,8 +149,7 @@ templates:
) | replace(\" , \", \", \") | replace(\"( \", \"(\") | replace(\" )\", \"\
)\") | replace(\"[ \", \"[\") | replace(\" ]\", \"]\")}}\n \n Given the\
\ code above, what is a proper replacement for {{mask}}? Choose among: {{answer_choices\
\ | join(\", \")}}\n |||\n {{source_tokens[repair_targets[0]]}}\n{% endif\
\ %}"
\ | join(\", \")}}\n\n|||{{source_tokens[repair_targets[0]]}}\n{% endif %}"
metadata: !TemplateMetadata
choices_in_prompt: true
languages:
Expand Down
72 changes: 72 additions & 0 deletions promptsource/templates/teven/code_contests/templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,75 @@ templates:
original_task: true
name: abovesol
reference: ''
9dcd29d1-cad0-4d2f-a7cc-120df233571c: !Template
id: 9dcd29d1-cad0-4d2f-a7cc-120df233571c
answer_choices: null
jinja: '{{description}}

Solve the task in {{language}}.

|||

{{solution}}'
metadata: !TemplateMetadata
choices_in_prompt: true
languages:
- en
metrics:
- Accuracy
original_task: true
name: soltask
reference: ''
3dcf99d1-cad0-4d2f-a7cc-120df233571c: !Template
id: 3dcf99d1-cad0-4d2f-a7cc-120df233571c
answer_choices: null
jinja: '{{description}}

Using {{language | lower}} can you solve the prior task?

|||

{{solution}}'
metadata: !TemplateMetadata
choices_in_prompt: true
languages:
- en
metrics:
- Accuracy
original_task: true
name: priortask
reference: ''
2dcf99d1-cad0-4d2f-a7cc-120df233571c: !Template
id: 2dcf99d1-cad0-4d2f-a7cc-120df233571c
answer_choices: null
jinja: '{{description}}

{{solution[:5]}}|||{{solution[5:]}}'
metadata: !TemplateMetadata
choices_in_prompt: true
languages:
- en
metrics:
- Accuracy
original_task: true
name: contsol
reference: ''
9dcf99d5-cad0-4d2f-a7cc-120df233571c: !Template
id: 9dcf99d5-cad0-4d2f-a7cc-120df233571c
answer_choices: null
jinja: '{{language}} solution for "{{description}}":




|||
{{solution}}'
metadata: !TemplateMetadata
choices_in_prompt: true
languages:
- en
metrics:
- Accuracy
original_task: true
name: solfor
reference: ''