Skip to content

Commit

Permalink
fix llama3 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayan Shaw committed Mar 6, 2025
1 parent 75aa05b commit 3043d3c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions shared/api/tokenizer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ OrtxStatus TokenizerImpl::Llama3ChatTemplate(
output->clear();

// Prepend BOS token at the start of the output
*output += bos_token + "\n"; // BOS token goes first
*output += bos_token; // BOS token goes first

// Initialize date_string with default value
std::string date_string = "26 Jul 2024"; // Default date
Expand Down Expand Up @@ -255,7 +255,6 @@ OrtxStatus TokenizerImpl::Llama3ChatTemplate(

*output += tools_json.dump(4) + "\n\n";
}
*output += "<|eot_id|>\n";
}

// Handle user message with tools in it
Expand All @@ -279,15 +278,17 @@ OrtxStatus TokenizerImpl::Llama3ChatTemplate(

// Serialize the tool call as JSON and append it to output
*output += "<|start_header_id|>assistant<|end_header_id|>\n\n";
*output += tool_call_json.dump() + "\n";
*output += "<|eot_id|>\n"; // End of tool call
*output += tool_call_json.dump();
*output += "<|eot_id|>"; // End of tool call
}

// Handle other messages (user, assistant, etc.)
else {
*output += "<|start_header_id|>" + role + "<|end_header_id|>\n\n";
*output += content + "\n";
*output += "<|eot_id|>\n";
if (role != "system") {
*output += "<|start_header_id|>" + role + "<|end_header_id|>\n\n";
}
*output += content;
*output += "<|eot_id|>";
}
}

Expand Down

0 comments on commit 3043d3c

Please sign in to comment.