File tree Expand file tree Collapse file tree
src/main/java/org/beehive/gpullama3/model/format Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,9 +129,15 @@ public String toolFirstUserMessagePrefix(String toolsJson) {
129129 @ Override
130130 public List <Integer > encodeToolCallAssistantTurn (ToolCallExtract toolCall ) {
131131 List <Integer > tokens = new ArrayList <>(encodeHeader (new Message (Role .ASSISTANT , "" )));
132+ // Preserve the <|python_tag|> prefix used by LLaMA 3.1/3.2 for tool calls so that
133+ // replayed history looks identical to what the model originally generated.
134+ if (pythonTag != -1 ) {
135+ tokens .add (pythonTag );
136+ }
132137 String json = "{\" name\" : \" " + toolCall .name () + "\" , \" parameters\" : " + toolCall .argumentsJson () + "}" ;
133138 tokens .addAll (tokenizer .encodeAsList (json ));
134- tokens .add (endOfTurn );
139+ // LLaMA 3.1 ends tool-call turns with <|eom_id|>; fall back to <|eot_id|> for 3.2.
140+ tokens .add (endOfMessage != -1 ? endOfMessage : endOfTurn );
135141 return tokens ;
136142 }
137143
You can’t perform that action at this time.
0 commit comments