Skip to content

Commit

Permalink
remove hard coded input and output fields (#7008)
Browse files Browse the repository at this point in the history
* remove hard coded input and output fields

Signed-off-by: arendu <adithya.r@gmail.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: arendu <adithya.r@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: Gerald Shen <geshen@nvidia.com>
  • Loading branch information
2 people authored and gshennvm committed Jul 12, 2023
1 parent 5551858 commit c8e88fd
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,23 @@ def _process_example(self, example):
output = example[self.label_key]

if self.prompt_template is not None:
assert '{input}' in self.prompt_template
assert '{output}' in self.prompt_template
assert f'{{{self.context_key}}}' in self.prompt_template
assert f'{{{self.label_key}}}' in self.prompt_template
# Make sure that '{output}' always occurs at the end of the prompt template string
assert self.prompt_template.index('{output}') == len(self.prompt_template) - len('{output}')
assert self.prompt_template.index(f'{{{self.label_key}}}') == len(self.prompt_template) - len(
f'{{{self.label_key}}}'
)
# Get the context by replacing only the input
original_context = context
context = self.prompt_template.replace('{input}', context).replace('{output}', '').strip(' ')
context = (
self.prompt_template.replace(f'{{{self.context_key}}}', context)
.replace(f'{{{self.label_key}}}', '')
.strip(' ')
)
# Replace the input and output placeholders with the actual input and output
text = self.prompt_template.replace('{input}', original_context).replace('{output}', output)
text = self.prompt_template.replace(f'{{{self.context_key}}}', original_context).replace(
f'{{{self.label_key}}}', output
)

if self.separate_prompt_and_response_with_newline and self.prompt_template is None:
text = context + '\n' + output
Expand Down

0 comments on commit c8e88fd

Please sign in to comment.