chml.c
chml.c - ChatML Message Wrapper
chml reads text from standard input and wraps it in a single ChatML message. It supports the system, assistant, and user roles, defaulting to user.
CLI
Examples
echo 'Hello' | ./bin/x86_64/linux/chml
echo 'You are a helpful assistant.' | ./bin/x86_64/linux/chml --role system
Output
<|im_start|>user
Hello
<|im_end|>
Parameters
| Flag | Description |
|---|---|
-r, --role ROLE | Message role: system, assistant, or user |
-h, --help | Show help and usage |
-v, --version | Show version |
Public API
#include "chml.h"
kc_chml_t *ctx = kc_chml_open();
kc_chml_set_role(ctx, KC_CHML_ROLE_SYSTEM);
char *msg = kc_chml_render(ctx, "You are a bot.");
printf("%s", msg);
free(msg);
kc_chml_close(ctx);
Role Constants
| Constant | Value | String |
|---|---|---|
KC_CHML_ROLE_SYSTEM | 0 | system |
KC_CHML_ROLE_ASSISTANT | 1 | assistant |
KC_CHML_ROLE_USER | 2 | user |
Lifecycle
kc_chml_open()- Creates a new ChatML context with default roleuser. Returns NULL on failure.kc_chml_set_role()- Sets the message role. ReturnsKC_CHML_ERRORon invalid role.kc_chml_get_role()- Returns the current role constant.kc_chml_get_role_name()- Returns the role name string.kc_chml_render()- Allocates and returns a ChatML-formatted string. Caller mustfree().kc_chml_close()- Releases the context. Safe to call with NULL.
Build
make clean && make
Compiled artifacts are generated under bin/{arch}/{platform}/.
Multiarch Builds
make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux
Beta Notice
This is a beta project tested only on Debian x86_64. It was created out of a personal need for these libraries, but no guarantees are provided regarding its stability or future support. You are free to test it, use it, and modify it as you please.
If you'd like to reach out, you can send an email to [email protected]. Please note that I do not accept pull requests; the goal is to avoid long-term dependency on platforms like GitHub, and I do not maintain fixed infrastructure to guarantee long-term stability for these projects.
Repo
You can download the repository and read the most up-to-date documentation directly from its official source.
GitHub: kaisarcode/chml.c
License
This project is distributed under the GNU General Public License version 3 (GPLv3).
