File tree Expand file tree Collapse file tree 4 files changed +395
-8
lines changed Expand file tree Collapse file tree 4 files changed +395
-8
lines changed Original file line number Diff line number Diff line change @@ -249,11 +249,10 @@ class chat_template {
249
249
inputs.add_generation_prompt = false ;
250
250
full = apply (inputs);
251
251
}
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);
257
256
}
258
257
if (full.find (prefix) != 0 ) {
259
258
fprintf (stderr, " Failed to infer a tool call example (possible template bug)\n " );
@@ -363,7 +362,7 @@ class chat_template {
363
362
if (polyfill_tools) {
364
363
adjusted_messages = add_system (inputs.messages ,
365
364
" 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\n Example tool call syntax:\n\n " + tool_call_example_));
365
+ (!polyfill_tool_call_example || tool_call_example_.empty () ? " " : " \n\n Example tool call syntax:\n\n " + tool_call_example_ + " \n\n " ));
367
366
} else {
368
367
adjusted_messages = inputs.messages ;
369
368
}
Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ def apply(self, context):
278
278
if has_tools and not caps .supports_tools :
279
279
add_system (context ['messages' ],
280
280
f"You can call any of the following tools to satisfy the user's requests: { json .dumps (context ['tools' ], indent = 2 )} " +
281
- ("\n \n Example tool call syntax:\n \n " + self .tool_call_example if self .tool_call_example is not None else "" ))
281
+ ("\n \n Example tool call syntax:\n \n " + self .tool_call_example + " \n \n " if self .tool_call_example is not None else "" ))
282
282
283
283
for message in context ['messages' ]:
284
284
if 'tool_calls' in message :
Original file line number Diff line number Diff line change @@ -17,8 +17,25 @@ target_link_libraries(test-syntax PRIVATE
17
17
gtest_main
18
18
gmock
19
19
)
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
+
20
36
if (NOT CMAKE_CROSSCOMPILING )
21
37
gtest_discover_tests(test -syntax)
38
+ gtest_discover_tests(test -polyfills)
22
39
endif ()
23
40
24
41
add_executable (test -capabilities test -capabilities.cpp)
@@ -54,7 +71,7 @@ set(MODEL_IDS
54
71
# minja implementation on the same template and context, and compare the output with the golden.
55
72
#
56
73
# For Gated models, you'll need to run `huggingface-cli login` (and be granted access) to download their template.
57
-
74
+
58
75
abacusai/Fewshot-Metamath-OrcaVicuna-Mistral
59
76
bofenghuang/vigogne-2-70b-chat
60
77
CohereForAI/c4ai-command -r-plus # Gated
You can’t perform that action at this time.
0 commit comments