fix(bedrock): make llama2 BOS a string, not a 1-tuple - #2108
Open
Osamaali313 wants to merge 1 commit into
Open
Conversation
messages_to_prompt_llama2 defined `BOS = ("<s>",)` — the trailing comma makes
it a one-element tuple, so `prompt = f"{BOS}"` renders the tuple repr and every
prompt starts with the literal text `('<s>',)` instead of the `<s>`
beginning-of-sequence token. The sibling messages_to_prompt_llama3 defines
`BOS = "<|begin_of_text|>"` as a plain string and interpolates it the same way,
confirming BOS is meant to be a string. The result feeds
BaseBedrockProvider.get_request_body for Mistral/Llama-2, so every such Bedrock
request was sent a malformed prompt. Drop the trailing comma.
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.
Problem
messages_to_prompt_llama2(metagpt/provider/bedrock/utils.py) defines its beginning-of-sequence token as a one-element tuple, not a string:Because
BOSis a tuple,prompt = f"{BOS}"interpolates itsrepr, so every Llama-2 / Mistral prompt begins with the literal text('<s>',)instead of the<s>BOS token.The sibling
messages_to_prompt_llama3in the same file does the same thing correctly with a plain string, which confirms the intent:The malformed prompt flows through
BaseBedrockProvider.get_request_bodyfor the Mistral and Meta (Llama-2) providers inbedrock_provider.py, so every such Amazon Bedrock request was sent a prompt starting with('<s>',).Reproduction
BOS = ("<s>",))('<s>',)[INST] hi [/INST]—startswith("<s>")→False❌BOS = "<s>")<s>[INST] hi [/INST]—startswith("<s>")→True✅Fix
Drop the trailing comma so
BOSis the string it is used as:One character.
python -m py_compilepasses.