Skip to content

Commit 5928ead

Browse files
[tools][wip] Add fix for tool-calling
1 parent a35e87b commit 5928ead

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/org/beehive/gpullama3/model/format/LlamaChatFormat.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)