Skip to content

Commit

Permalink
Parameterize open_question to allow the user to change the labels `…
Browse files Browse the repository at this point in the history
…Question` and `Answer`.

PiperOrigin-RevId: 657531076
Change-Id: I90e7f40bf63b51db07a6e4aa0acd61ed28edeb74
  • Loading branch information
jzleibo authored and copybara-github committed Jul 30, 2024
1 parent adf8136 commit 87d53dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions concordia/components/agent/v2/concat_act_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def get_action_attempt(
# after the end of a directly spoken response, since it normally
# puts a space after a quotation mark only in these cases.
terminators=('" ', '\n'),
question_label='Exercise',
)
self._log(output, prompt)
return output
Expand Down
1 change: 1 addition & 0 deletions concordia/components/agent/v2/legacy_act_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def get_action_attempt(
# after the end of a directly spoken response, since it normally
# puts a space after a quotation mark only in these cases.
terminators=('" ', '\n'),
question_label='Exercise',
)
self._log(output, prompt)
return output
Expand Down
8 changes: 6 additions & 2 deletions concordia/document/interactive_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def open_question(
answer_suffix: str = '',
max_tokens: int = DEFAULT_MAX_TOKENS,
terminators: Collection[str] = ('\n',),
question_label: str = 'Question',
answer_label: str = 'Answer',
) -> str:
"""Asks the agent an open question and appends it to the document.
Expand All @@ -160,12 +162,14 @@ def open_question(
max_tokens: the maximum number of tokens to sample from the model.
terminators: strings that must not be present in the model's response. If
emitted by the model the response will be truncated before them.
question_label: the label to use for the question, typically "Question".
answer_label: the label to use for the answer, typically "Answer".
Returns:
The agents truncated response (or `forced_response` is provided).
"""
self._question(f'Question: {question}\n')
self._response(f'Answer: {answer_prefix}')
self._question(f'{question_label}: {question}\n')
self._response(f'{answer_label}: {answer_prefix}')
if forced_response is None:
response = self._model.sample_text(
prompt=self._model_view.text(),
Expand Down

0 comments on commit 87d53dd

Please sign in to comment.