feat: add stop sequences support for both endpoints#991
Open
eloe wants to merge 3 commits intoBlaizzy:mainfrom
Open
feat: add stop sequences support for both endpoints#991eloe wants to merge 3 commits intoBlaizzy:mainfrom
eloe wants to merge 3 commits intoBlaizzy:mainfrom
Conversation
Accept `stop` parameter (string or list of up to 4 strings) in both /v1/responses and /v1/chat/completions. Stop strings are tokenized and passed as `eos_tokens` to the generation pipeline. New helper: resolve_stop_tokens() converts stop strings to token IDs using the model's tokenizer. Adds 7 tests: endpoint integration (responses + chat/completions), unit tests for resolve_stop_tokens (single, list, None, limit to 4). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
add_eos_token_ids() accepts strings and tokenizes internally. Renamed resolve_stop_tokens → resolve_stop_sequences, returns string list directly. Fixes "can only concatenate str (not int)" error when stop sequences were used. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix comment "token IDs" → "strings" (eos_tokens takes strings) - Tighten resolve_stop_sequences type hints to List[str] - Remove unused fake_processor/fake_encode from tests - Rename misleading test names to drop "string" from name Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
stopparameter support to/v1/chat/completionsand/responses, per the OpenAI API spec. Up to 4 stop sequences can be specified as strings; they are passed directly to the generation pipeline aseos_tokens.stopas a single string or list of stringseos_tokenskwarg ingenerate()/stream_generate()Example
{ "model": "...", "messages": [{"role": "user", "content": "List 3 items"}], "stop": ["\n\n", "4."] }Tests
test_chat_completions_stop_passed_as_eos_tokenstest_chat_completions_no_stop_no_eos_tokenstest_responses_stop_passed_as_eos_tokenstest_resolve_stop_sequences_single_stringtest_resolve_stop_sequences_listtest_resolve_stop_sequences_nonetest_resolve_stop_sequences_limits_to_four