feat: add --raw-prompt flag to skip chat template wrapping#3
Open
Krigsexe wants to merge 1 commit into
Open
Conversation
Some models (e.g. PleIAs/Pleias-RAG-1B) use custom special tokens for structured input/output and do not define a chat_template in their tokenizer config. The default ChatML wrapping (<|im_start|>user...) breaks these models because their special tokens get nested inside the chat template instead of being parsed directly. --raw-prompt passes the prompt text directly to the tokenizer without any chat template wrapping, enabling models with custom token protocols to work correctly. Tested with PleIAs/Pleias-RAG-1B (Q4 backend) on Ryzen 5 3600 (AVX2): the model correctly processes <|query_start|>, <|source_start|>, <|source_analysis_start|> tokens and generates structured RAG output with language detection, query analysis, and source grounding.
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
Add a
--raw-promptCLI flag that passes the prompt directly to the tokenizer without ChatML or Mistral instruct template wrapping.Motivation
Models like PleIAs/Pleias-RAG-1B use custom special tokens (
<|query_start|>,<|source_start|>,<|source_analysis_start|>, etc.) for structured RAG input/output. They do not define achat_templatein their tokenizer config.Without
--raw-prompt, herbert-rs wraps the prompt in ChatML (<|im_start|>user...), which nests the model's special tokens inside the chat template. The model cannot parse its own tokens and either refuses to answer or generates garbage.With
--raw-prompt, the special tokens are passed directly and the model processes them correctly: language detection, query analysis, source analysis, and grounded answers with citations.Changes
crates/cli/src/main.rs: +15/-3 lines--raw-promptbool flag toClistructbuild_prompt()wrapping in single-shot mode when flag is setbuild_prompt()wrapping in reserve hint calculation when flag is setTesting
Tested with PleIAs/Pleias-RAG-1B (Q4 backend, llama model_type via PR #2) on Ryzen 5 3600 (AVX2):
--raw-prompt: model wraps in ChatML, refuses to process sources ("insufficient information")--raw-prompt: model correctly generates<|language_start|>French<|language_end|>,<|query_analysis_start|>,<|source_analysis_start|>,<|query_report_start|>Answerable<|query_report_end|>structured output