Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78bf4a5

Browse files
authored
Merge pull request docker#48 from google/test-polyfills
Add test-polyfills
2 parents 8dac4e1 + b9c335e commit 78bf4a5

File tree

4 files changed

+395
-8
lines changed

4 files changed

+395
-8
lines changed

include/minja/chat-template.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,10 @@ class chat_template {
249249
inputs.add_generation_prompt = false;
250250
full = apply(inputs);
251251
}
252-
253-
if (full.find(prefix) != 0) {
254-
if (prefix.rfind(eos_token_) == prefix.size() - eos_token_.size()) {
255-
prefix = prefix.substr(0, prefix.size() - eos_token_.size());
256-
}
252+
auto eos_pos_last = full.rfind(eos_token_);
253+
if (eos_pos_last == prefix.size() - eos_token_.size() ||
254+
(full[full.size() - 1] == '\n' && (eos_pos_last == full.size() - eos_token_.size() - 1))) {
255+
full = full.substr(0, eos_pos_last);
257256
}
258257
if (full.find(prefix) != 0) {
259258
fprintf(stderr, "Failed to infer a tool call example (possible template bug)\n");
@@ -363,7 +362,7 @@ class chat_template {
363362
if (polyfill_tools) {
364363
adjusted_messages = add_system(inputs.messages,
365364
"You can call any of the following tools to satisfy the user's requests: " + minja::Value(inputs.tools).dump(2, /* to_json= */ true) +
366-
(!polyfill_tool_call_example || tool_call_example_.empty() ? "" : "\n\nExample tool call syntax:\n\n" + tool_call_example_));
365+
(!polyfill_tool_call_example || tool_call_example_.empty() ? "" : "\n\nExample tool call syntax:\n\n" + tool_call_example_ + "\n\n"));
367366
} else {
368367
adjusted_messages = inputs.messages;
369368
}

scripts/fetch_templates_and_goldens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def apply(self, context):
278278
if has_tools and not caps.supports_tools:
279279
add_system(context['messages'],
280280
f"You can call any of the following tools to satisfy the user's requests: {json.dumps(context['tools'], indent=2)}" +
281-
("\n\nExample tool call syntax:\n\n" + self.tool_call_example if self.tool_call_example is not None else ""))
281+
("\n\nExample tool call syntax:\n\n" + self.tool_call_example + "\n\n" if self.tool_call_example is not None else ""))
282282

283283
for message in context['messages']:
284284
if 'tool_calls' in message:

tests/CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,25 @@ target_link_libraries(test-syntax PRIVATE
1717
gtest_main
1818
gmock
1919
)
20+
21+
add_executable(test-polyfills test-polyfills.cpp)
22+
target_compile_features(test-polyfills PUBLIC cxx_std_17)
23+
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
24+
target_compile_definitions(test-polyfills PUBLIC _CRT_SECURE_NO_WARNINGS)
25+
target_compile_options(gtest PRIVATE -Wno-language-extension-token)
26+
endif()
27+
target_link_libraries(test-polyfills PRIVATE
28+
nlohmann_json::nlohmann_json
29+
gtest_main
30+
gmock
31+
)
32+
if (NOT CMAKE_CROSSCOMPILING)
33+
gtest_discover_tests(test-syntax)
34+
endif()
35+
2036
if (NOT CMAKE_CROSSCOMPILING)
2137
gtest_discover_tests(test-syntax)
38+
gtest_discover_tests(test-polyfills)
2239
endif()
2340

2441
add_executable(test-capabilities test-capabilities.cpp)
@@ -54,7 +71,7 @@ set(MODEL_IDS
5471
# minja implementation on the same template and context, and compare the output with the golden.
5572
#
5673
# For Gated models, you'll need to run `huggingface-cli login` (and be granted access) to download their template.
57-
74+
5875
abacusai/Fewshot-Metamath-OrcaVicuna-Mistral
5976
bofenghuang/vigogne-2-70b-chat
6077
CohereForAI/c4ai-command-r-plus # Gated

0 commit comments

Comments
 (0)