Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e75dff5
build & test w/ sanitizers
ochafik Oct 29, 2025
a40e7e4
Fix circular context reference
ochafik Oct 29, 2025
03a6c98
fix bad patch
ochafik Oct 29, 2025
2a42ba8
Add tiny reserves in value ctor (+ use emplace to avoid some copies)
ochafik Oct 29, 2025
844eae8
drop unused enable_shared_from_this
ochafik Oct 29, 2025
dc245f5
Update minja.hpp
ochafik Oct 29, 2025
6641257
Update minja.hpp
ochafik Oct 29, 2025
bd30364
Update build.yml
ochafik Oct 29, 2025
3ca32fe
Support GLM 4.6 template (#5)
ochafik Nov 2, 2025
0c55c36
Add missing capabilities tests (tool call id & requires non null cont…
ochafik Nov 2, 2025
41f9022
fix sanitizer exclusion in github workflow matrix
ochafik Nov 2, 2025
4891676
Update README.md
ochafik Nov 2, 2025
c755506
Support MiniMax tool call format (#7)
pwilkin Nov 2, 2025
911b645
Dedupe test templates (#8)
ochafik Nov 2, 2025
9744121
Add capitalize filter and fix method (#12)
CISC Dec 20, 2025
88a7210
feat: support `| first` filter (#14)
xcpky Dec 20, 2025
aa530c2
Fix CI: Windows encoding, sanitizers, cppcheck, and test issues (#15)
ochafik Dec 20, 2025
1dc671b
Add DeepSeek V3.2 DSML format support with synthetic template (#17)
ochafik Dec 20, 2025
c5a97c1
Replace std::regex_replace when stripping leading/trailing space (#21)
aldehir Dec 25, 2025
6925b09
Add thinking/reasoning capability detection
ochafik Dec 23, 2025
c12caa0
Add ThinkingPattern polyfills, improved detection, and test infrastru…
ochafik Dec 29, 2025
dbad479
Fix Windows build: add missing collapse_blank_lines function
ochafik Dec 29, 2025
11a608f
Remove committed GLM-4.7 template (fetched via MODEL_IDS)
ochafik Dec 29, 2025
65dd745
Rename thinking → reasoning API and add behavior detection probes
ochafik Dec 30, 2025
1e39bb3
Revert supports_reasoning_visibility → supports_clear_thinking
ochafik Dec 30, 2025
d3b8220
Rename requires_typed_content → requires_typed_content_blocks and add…
ochafik Dec 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- master
- main
paths: ['.github/workflows/build.yml', '**/CMakeLists.txt', '**/*.hpp', '**/*.cpp']
pull_request:
types: [opened, synchronize, reopened]
Expand Down Expand Up @@ -44,8 +44,29 @@ jobs:
Release,
Debug,
]
sanitizer: [
none,
address,
thread,
undefined,
]
exclude:
# Sanitizers not supported on Clang targeting MSVC (llvm-arm64)
- setup: { build: 'llvm-arm64' }
sanitizer: address
- setup: { build: 'llvm-arm64' }
sanitizer: thread
- setup: { build: 'llvm-arm64' }
sanitizer: undefined
# Sanitizers not supported on MSVC ARM64
- setup: { build: 'msvc-arm64' }
sanitizer: address
- setup: { build: 'msvc-arm64' }
sanitizer: thread
- setup: { build: 'msvc-arm64' }
sanitizer: undefined
runs-on: ${{ matrix.setup.os }}
name: ${{ matrix.setup.os }}-${{ matrix.setup.build }}-${{ matrix.type }}
name: ${{ matrix.setup.os }}-${{ matrix.setup.build }}-${{ matrix.type }}-sanitizer-${{ matrix.sanitizer }}
timeout-minutes: 30

steps:
Expand All @@ -58,7 +79,7 @@ jobs:
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.11
with:
key: ${{ matrix.setup.os }}-${{ matrix.setup.build }}-${{ matrix.type }}
key: ${{ matrix.setup.os }}-${{ matrix.setup.build }}-${{ matrix.type }}-sanitizer-${{ matrix.sanitizer }}

- name: Set up CMake
uses: lukka/get-cmake@latest
Expand All @@ -75,11 +96,14 @@ jobs:
- name: Configure CMake
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: cmake -B ${{github.workspace}}/build ${{ matrix.setup.defines }} -DCMAKE_BUILD_TYPE=${{ matrix.type }}
PYTHONIOENCODING: utf-8
run: cmake -B ${{github.workspace}}/build ${{ matrix.setup.defines }} -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DMINJA_SANITIZER=${{ matrix.sanitizer }}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{ matrix.type }} --parallel

- name: Test
if: ${{ matrix.setup.test }}
env:
PYTHONIOENCODING: utf-8
run: ctest --test-dir build --output-on-failure --verbose -C ${{ matrix.type }}
33 changes: 27 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ add_library(minja INTERFACE)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Test if clang-tidy is available
# Test if clang-tidy is available (disabled for address sanitizer due to GCC false positives)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if (CLANG_TIDY_EXE)
if (CLANG_TIDY_EXE AND NOT MINJA_SANITIZER STREQUAL "address")
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
Expand All @@ -27,6 +27,8 @@ if (CLANG_TIDY_EXE)
-checks=-*,clang-analyzer-*,clang-diagnostic-*,cppcoreguideline-*,bugprone-*,-bugprone-suspicious-include,-bugprone-assignment-in-if-condition,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,-bugprone-inc-dec-in-conditions,-bugprone-exception-escape,-clang-analyzer-cplusplus.StringChecker;
-warnings-as-errors=*;
)
elseif(MINJA_SANITIZER STREQUAL "address")
message(STATUS "clang-tidy disabled for address sanitizer builds")
else()
message(STATUS "clang-tidy not found")
endif()
Expand All @@ -43,13 +45,27 @@ option(MINJA_EXAMPLE_ENABLED "minja: Build with example"
option(MINJA_FUZZTEST_ENABLED "minja: fuzztests enabled" MINJA_FUZZTEST_ENABLED_DEFAULT)
option(MINJA_FUZZTEST_FUZZING_MODE "minja: run fuzztests (if enabled) in fuzzing mode" OFF)
option(MINJA_USE_VENV "minja: use Python venv for build" MINJA_USE_VENV_DEFAULT)
set(MINJA_SANITIZERS thread address undefined none)
set(MINJA_SANITIZER none CACHE STRING "minja: sanitizer to use")
set_property(CACHE MINJA_SANITIZER PROPERTY STRINGS ${MINJA_SANITIZERS})

if (NOT MSVC AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" AND NOT MINJA_SANITIZER STREQUAL "none")
message(STATUS "Using -fsanitize=${MINJA_SANITIZER}")
add_compile_options("-fsanitize=${MINJA_SANITIZER}")
link_libraries ("-fsanitize=${MINJA_SANITIZER}")
endif()

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
if (NOT MSVC)
add_compile_options(-Wall -Wextra -pedantic -Werror)
# GCC 13+ has false-positive maybe-uninitialized warnings with address sanitizer
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND MINJA_SANITIZER STREQUAL "address")
add_compile_options(-Wno-maybe-uninitialized)
endif()
endif()

include(FetchContent)
Expand Down Expand Up @@ -108,10 +124,13 @@ if(MINJA_TEST_ENABLED)
message(STATUS "Python executable: ${Python_EXECUTABLE}")
endif()

find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK "${CPPCHECK}" -i ${json_SOURCE_DIR}/include/nlohmann/json.hpp)
message(STATUS "cppcheck found: ${CPPCHECK}")
# cppcheck has issues on Windows (missing std.cfg), so we only enable it on non-Windows
if(NOT WIN32)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK "${CPPCHECK}" -i ${json_SOURCE_DIR}/include/nlohmann/json.hpp)
message(STATUS "cppcheck found: ${CPPCHECK}")
endif()
endif()

include(GNUInstallDirs)
Expand All @@ -135,6 +154,8 @@ if(MINJA_EXAMPLE_ENABLED)
add_subdirectory(examples)
endif()

add_subdirectory(tools)

if(MINJA_TEST_ENABLED)
enable_testing()
include(GoogleTest)
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# minja.hpp - A minimalistic C++ Jinja templating engine for LLM chat templates

_**This is not an official Google product**_
_**Used to be at https://github.com/google/minja, but I've left Google and I'll only maintain my fork from now on**_

Minja is a minimalistic reimplementation of the [Jinja](https://github.com/pallets/jinja/) templating engine to integrate in/with C++ LLM projects (it's used in [llama.cpp](https://github.com/ggerganov/llama.cpp/pull/11016), [Jan](https://jan.ai/) (through [cortex.cpp](https://github.com/menloresearch/cortex.cpp/pull/1814)), [GPT4All](https://github.com/nomic-ai/gpt4all/pull/3433) and [Docker Model Runner](https://github.com/docker/model-runner)).

Expand Down Expand Up @@ -212,6 +212,26 @@ Main limitations (non-exhaustive list):
./scripts/fuzzing_tests.sh
```

- Sanitizer tests:

```bash
for sanitizer in ADDRESS THREAD UNDEFINED ; do
docker run --rm \
-v "$PWD":/src:ro \
-v "$PWD/build-sanitizer-${sanitizer}":/src/build \
-w /src \
"$(echo "
FROM ghcr.io/astral-sh/uv:debian-slim
RUN apt-get update && apt-get install -y build-essential libcurl4-openssl-dev cmake clang-tidy
" | docker build . -q -f - )" \
bash -c "
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DMINJA_SANITIZER=${sanitizer} && \
cmake --build build -j --config Debug && \
ctest --test-dir build -j -C Debug --output-on-failure
"
done
```

- If your model's template doesn't run fine, please consider the following before [opening a bug](https://github.com/googlestaging/minja/issues/new):

- Is the template using any unsupported filter / test / method / global function, and which one(s)?
Expand Down
Loading
Loading