Skip to content

Commit af5fa01

Browse files
authored
Handle repeated role_colon stop delimiters gracefully (#368)
1 parent 3c58534 commit af5fa01

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tinker_cookbook/renderers/role_colon.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ def parse_response(self, response: list[int]) -> tuple[Message, bool]:
7575
before, _after = splitted
7676
return Message(role="assistant", content=before.strip()), not terminated_with_eos
7777
else:
78-
raise ValueError(
79-
f"When parsing response, expected to split into 1 or 2 pieces using stop tokens, but got {len(splitted)}. "
80-
"You probably are using the wrong stop tokens when sampling"
78+
logger.warning(
79+
"RoleColonRenderer.parse_response saw multiple stop delimiters "
80+
"(count=%d). Returning parse_success=False. Full response:\n%s",
81+
len(splitted) - 1,
82+
str_response,
8183
)
84+
return Message(role="assistant", content=splitted[0].strip()), False
8285

8386
@property
8487
def _bos_tokens(self) -> list[int]:

0 commit comments

Comments
 (0)