fix: Correct reasoning-end detection for prompt history (#44551)

Signed-off-by: jwzheng96 <jianweizheng@pku.edu.cn>
Signed-off-by: JianweiZheng <32029023+jwzheng96@users.noreply.github.com>
Signed-off-by: Jason Ozuzu <jasonozuzu@cohere.com>
Signed-off-by: walterbm <walter.beller.morales@gmail.com>
Co-authored-by: JianweiZheng <32029023+jwzheng96@users.noreply.github.com>
Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com>
Co-authored-by: walterbm <walter.beller.morales@gmail.com>
Co-authored-by: Walter Beller-Morales <walterbm@users.noreply.github.com>
Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
JasonCohere
2026-06-26 22:15:06 -07:00
committed by GitHub
co-authored by JianweiZheng Wentao Ye walterbm Walter Beller-Morales Flora Feng
parent 68ee8300a0
commit d706dec904
4 changed files with 645 additions and 1 deletions
@@ -414,7 +414,9 @@ class BaseCohereCommandReasoningParser(ReasoningParser):
**kwargs,
):
super().__init__(tokenizer, *args, **kwargs)
self.start_token_id = tokenizer.convert_tokens_to_ids("<|START_THINKING|>")
self.end_token_id = tokenizer.convert_tokens_to_ids("<|END_THINKING|>")
self.chatbot_token_id = tokenizer.convert_tokens_to_ids("<|CHATBOT_TOKEN|>")
self.unary_opts = unary_opts
self.melody_unary = PyFilter(unary_opts)
self.melody_streaming = PyFilter(streaming_opts)
@@ -478,7 +480,21 @@ class BaseCohereCommandReasoningParser(ReasoningParser):
return content_ids
def is_reasoning_end(self, input_ids: Sequence[int]) -> bool:
return any(tid == self.end_token_id for tid in reversed(input_ids))
chatbot = self.chatbot_token_id
start = self.start_token_id
end = self.end_token_id
has_end_token = False
for i in reversed(range(len(input_ids))):
tid = input_ids[i]
if tid == start:
return has_end_token
if tid == chatbot:
return False
if tid == end:
has_end_token = True
return has_end_token
def adjust_request(
self, request: ChatCompletionRequest | ResponsesRequest