Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
faf284c
Merging all constrained decoding commits
kunal-vaishnavi May 11, 2025
3aafd99
Make constrained decoding examples more generic
kunal-vaishnavi May 11, 2025
504fd94
Rewrite C# LLM example
kunal-vaishnavi May 11, 2025
8b83ed7
Merge branch 'main' into kvaishnavi/guidance-schema
kunal-vaishnavi Dec 20, 2025
d4b840d
Undo changes after syncing with main
kunal-vaishnavi Dec 22, 2025
7b3dcb9
Remove SLM engine example
kunal-vaishnavi Dec 22, 2025
3101872
Undo change in C# file
kunal-vaishnavi Dec 22, 2025
8dbb361
Refactor Python examples
kunal-vaishnavi Dec 22, 2025
aed89b3
Add new tool definitions
kunal-vaishnavi Dec 22, 2025
6afe11f
Refactor C# examples
kunal-vaishnavi Dec 25, 2025
d6ee36d
Remove commented out code
kunal-vaishnavi Dec 25, 2025
34dd37e
Fix some typos
kunal-vaishnavi Dec 25, 2025
3f12e60
Update READMEs
kunal-vaishnavi Dec 25, 2025
c78bc3d
Rename C# examples
kunal-vaishnavi Dec 25, 2025
16e1b1d
Refactor C/C++ examples
kunal-vaishnavi Jan 7, 2026
da11f3d
Improve parity between the examples
kunal-vaishnavi Jan 7, 2026
f857338
Add C# binding for Overlay API
kunal-vaishnavi Jan 8, 2026
57de609
Add more parity between the examples
kunal-vaishnavi Jan 8, 2026
bc72a13
Add changes suggested by C++ linter
kunal-vaishnavi Jan 8, 2026
71082aa
Disable HF token
kunal-vaishnavi Jan 8, 2026
94b07af
Disable HF remote
kunal-vaishnavi Jan 8, 2026
2ec708a
Fix some CI failures
kunal-vaishnavi Jan 16, 2026
4419129
Use bytes for special tokens processing on cross-platform
kunal-vaishnavi Jan 16, 2026
cc5d988
Change number of layers used in ONNX model creation
kunal-vaishnavi Jan 16, 2026
8fca8ea
Use OS replace instead of OS rename
kunal-vaishnavi Jan 16, 2026
6c7b186
Use str instead of int in subprocess
kunal-vaishnavi Jan 16, 2026
cad80cf
Add changes suggested by C++ linter
kunal-vaishnavi Jan 16, 2026
031be13
Update name references to match examples
kunal-vaishnavi Jan 17, 2026
b7eb5ea
Use all layers for Qwen-2.5 0.5B only
kunal-vaishnavi Jan 17, 2026
45ffe03
Reduce max length to fit KV cache in CI's GPU
kunal-vaishnavi Jan 17, 2026
0d42b89
Update CLI args in Python examples
kunal-vaishnavi Jan 17, 2026
f6b26cb
Update CLI args in C# example
kunal-vaishnavi Jan 17, 2026
6926c3f
Add C/C++ and C# example testing in CIs
kunal-vaishnavi Jan 17, 2026
cb64014
Fix spacing in YAML files
kunal-vaishnavi Jan 17, 2026
66bad08
Update CLI args in C examples
kunal-vaishnavi Jan 17, 2026
8116b68
Add missing param in header
kunal-vaishnavi Jan 17, 2026
bb22936
Build C/C++ examples with CMake in CIs
kunal-vaishnavi Jan 19, 2026
f3561b2
Fix library directory path
kunal-vaishnavi Jan 19, 2026
d392772
Use building Java API to build C/C++ examples via build script
kunal-vaishnavi Jan 19, 2026
2cc85d8
Run Java build after Python dependencies are installed
kunal-vaishnavi Jan 20, 2026
5fa6caa
Remove config overlay call in C# for now
kunal-vaishnavi Jan 20, 2026
88eeb31
Downgrade GenAI version in C# examples
kunal-vaishnavi Jan 20, 2026
40358f6
Use dnf instead of apt
kunal-vaishnavi Jan 20, 2026
5cba9f4
Use superuser to update OS packages
kunal-vaishnavi Jan 20, 2026
8e7c29d
Try to fix macOS CI failure
kunal-vaishnavi Jan 21, 2026
4243683
Test only CPU build of C examples
kunal-vaishnavi Jan 21, 2026
46cab0d
Use devel instead of dev for package name
kunal-vaishnavi Jan 21, 2026
5761423
Use Python 3.11 for devel package
kunal-vaishnavi Jan 21, 2026
aa4dfcf
Add Python3 packages for Linux CUDA CI
kunal-vaishnavi Jan 21, 2026
37d604f
Try aliasing Python3 to env Python executable
kunal-vaishnavi Jan 21, 2026
42d1ee3
Provide Python executable to subprocess
kunal-vaishnavi Jan 21, 2026
e070e71
Change path to built C examples for Linux
kunal-vaishnavi Jan 21, 2026
b421a39
Use CPU model instead of CUDA in CI
kunal-vaishnavi Jan 21, 2026
5a4cdc1
Merge branch 'main' into kvaishnavi/guidance-schema
kunal-vaishnavi Jan 23, 2026
a44beae
Remove chat app example
kunal-vaishnavi Jan 23, 2026
0f9059d
Remove Genny example
kunal-vaishnavi Jan 23, 2026
d6745e2
Update Python example docs
kunal-vaishnavi Jan 23, 2026
9272d15
Merge branch 'main' into kvaishnavi/guidance-schema
kunal-vaishnavi Jan 27, 2026
2a4322b
Add changes suggested during PR review
kunal-vaishnavi Jan 30, 2026
8c636ae
Update READMEs
kunal-vaishnavi Jan 30, 2026
b74f43b
Refactor README docs for constrained decoding and tool calling
kunal-vaishnavi Jan 30, 2026
15068a3
Add TokenCount usage to examples
kunal-vaishnavi Jan 30, 2026
91a3d45
Revert "Add TokenCount usage to examples"
kunal-vaishnavi Jan 30, 2026
ffd9910
Merge branch 'main' into kvaishnavi/guidance-schema
kunal-vaishnavi Jan 30, 2026
54b7fc2
Add EP registration to examples
kunal-vaishnavi Jan 30, 2026
140c702
Remove accidental insertion in C README
kunal-vaishnavi Jan 30, 2026
adcd9bb
Refactor Python examples
kunal-vaishnavi Jan 31, 2026
a66ce4b
Refactor C examples
kunal-vaishnavi Jan 31, 2026
ccfa176
Add missing feature flag in Python example
kunal-vaishnavi Jan 31, 2026
b1df1cd
Refactor C# examples
kunal-vaishnavi Jan 31, 2026
8505917
Update csproj files
kunal-vaishnavi Jan 31, 2026
aed483f
Remove Directory.Build.Props
kunal-vaishnavi Jan 31, 2026
8930d40
Update C# README
kunal-vaishnavi Jan 31, 2026
405a71a
Use GetModelType instead of GetType
kunal-vaishnavi Jan 31, 2026
8cf1ba2
Add changes suggested by C++ linter
kunal-vaishnavi Jan 31, 2026
04a3ab8
Fix title in C# README
kunal-vaishnavi Jan 31, 2026
8447972
Fix return type of native method
kunal-vaishnavi Jan 31, 2026
0212cfa
Fix early parenthesis
kunal-vaishnavi Jan 31, 2026
832a7a4
Increase GenAI version in examples
kunal-vaishnavi Feb 2, 2026
39e82ec
Rename ModelVision as ModelMM
kunal-vaishnavi Feb 2, 2026
4fd0ed4
Clean up changes in YAML files
kunal-vaishnavi Feb 2, 2026
af5de4d
Use ORT APIs for registering EPs
kunal-vaishnavi Feb 3, 2026
a73a73a
Update CMakeLists.txt to fix CI failures
kunal-vaishnavi Feb 3, 2026
7ecbb0e
Change C# assert params order
kunal-vaishnavi Feb 3, 2026
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
1 change: 0 additions & 1 deletion .pipelines/stages/jobs/custom-nuget-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,3 @@ jobs:
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)\nuget'
artifactName: $(genai_nuget_package_name)

16 changes: 15 additions & 1 deletion examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ cmake_minimum_required(VERSION 3.18.1)
project(ortgenaiapp)
set(CMAKE_CXX_STANDARD 20)

# Download and make available nlohmann/json
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0 # Or update to latest release
)
FetchContent_MakeAvailable(nlohmann_json)

option(USE_CXX "Invoke the C++ example" ON)
option(MODEL_CHAT "Build the Model Chat example" OFF)
option(MODEL_QA "Build the Model Q&A example without multi-turn prompting" OFF)
option(MODEL_QA "Build the Model Q&A example" OFF)
option(MODEL_VISION "Build the Model Vision example" OFF)
option(PHI4-MM "Build the Phi-4 mm example" OFF)
Comment thread
kunal-vaishnavi marked this conversation as resolved.
Outdated
option(WHISPER "Build the Whisper example" OFF)
Expand Down Expand Up @@ -60,24 +69,29 @@ set(EXAMPLES_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
if(MODEL_CHAT)
add_executable(model_chat ${EXAMPLES_SOURCE_DIR}/model_chat.cpp ${EXAMPLES_SOURCE_DIR}/common.cpp)
prepare_executable(model_chat)
target_link_libraries(model_chat PRIVATE nlohmann_json::nlohmann_json)
endif()

if(MODEL_QA)
add_executable(model_qa ${EXAMPLES_SOURCE_DIR}/model_qa.cpp ${EXAMPLES_SOURCE_DIR}/common.cpp)
prepare_executable(model_qa)
target_link_libraries(model_qa PRIVATE nlohmann_json::nlohmann_json)
endif()

if(MODEL_VISION)
add_executable(model_vision ${EXAMPLES_SOURCE_DIR}/model_vision.cpp ${EXAMPLES_SOURCE_DIR}/common.cpp)
prepare_executable(model_vision)
target_link_libraries(model_vision PRIVATE nlohmann_json::nlohmann_json)
endif()

if(PHI4-MM)
add_executable(phi4-mm ${CMAKE_SOURCE_DIR}/src/phi4-mm.cpp ${EXAMPLES_SOURCE_DIR}/common.cpp)
prepare_executable(phi4-mm)
target_link_libraries(phi4-mm PRIVATE nlohmann_json::nlohmann_json)
endif()

if(WHISPER)
add_executable(whisper ${CMAKE_SOURCE_DIR}/src/whisper.cpp ${EXAMPLES_SOURCE_DIR}/common.cpp)
prepare_executable(whisper)
target_link_libraries(whisper PRIVATE nlohmann_json::nlohmann_json)
endif()
26 changes: 24 additions & 2 deletions examples/c/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ONNX Runtime GenAI C Example

> 📝 **Note:** The examples from the main branch of this repository are compatible with the binaries build from the same commit. Therefore, if using the example from `main`, ONNX Runtime GenAI needs to be built from source. If this is your scenario, just build the library and the examples will be auto built along with the library.
If this is not your scenario, please use prebuilt binaries from the release you're interested in and use the examples from the same version tag and follow the steps below.
> 📝 **Note:** The examples from the main branch of this repository are compatible with the binaries built from the same commit. Therefore, if using the example from `main`, ONNX Runtime GenAI needs to be built from source. If this is your scenario, just build the library and the examples will be auto built along with the library. If this is not your scenario, please use prebuilt binaries from the release you're interested in and use the examples from the same version tag and follow the steps below.

## Download the model

Expand Down Expand Up @@ -67,3 +66,26 @@ For other options to download models, read through [our download options](https:
2. On Linux and macOS:
- cd build
- ./model_qa <path/to/model/from/above> <execution_provider>

## Use constrained decoding
Comment thread
kunal-vaishnavi marked this conversation as resolved.
Outdated

Constrained Decoding is useful when using function/tool calling as it helps in ensuring the output is in the correct format.

We have integrated [LLGuidance](https://github.com/guidance-ai/llguidance) for constrained decoding. There are three types of constrained decoding enabled right now:
1. Lark Grammar (Recommended): This option allows you to have an option for a regular output as well as function/tool output in JSON format.
2. JSON Schema: Output will be JSON schema and it will be one of the function/tools provided.
3. Regex: If a particular regular expression is desired.

To ensure that the function/tool call works correctly with constrained decoding, you need to modify your tokenizer.json file. For each model that has its own tool calling token, the tool calling token's `special` attribute needs to be set to true. For example, Phi-4 mini uses the <|tool_call|> and <|/tool_call|> tokens so you should set the `special` attribute for them as `true` inside `tokenizer.json`.

To run the C examples with function/tool calling:
```
# Using JSON Schema with only tool call output
.\model_chat -m={path to model folder} -e={execution provider} --response_format=json_schema --tools_file={path to json file} --tool_output --tool_call_start="{starting tool call token}" --tool_call_end="{ending tool call token}"

# Using Lark Grammar with only tool call output
.\model_chat -m={path to model folder} -e={execution provider} --response_format=lark_grammar --tools_file={path to json file} --tool_output --tool_call_start="{starting tool call token}" --tool_call_end="{ending tool call token}"

# Using Lark Grammar with text or tool call output
.\model_chat -m={path to model folder} -e={execution provider} --response_format=lark_grammar --tools_file={path to json file} --text_output --tool_output --tool_call_start="{starting tool call token}" --tool_call_end="{ending tool call token}"
```
Loading
Loading