ember.cpp 0.1.0
C++ inference engine for Llama-family and paperkiln models (CPU, CUDA, WebAssembly)
Loading...
Searching...
No Matches
chat_template.h File Reference
#include <array>
#include <cstdint>
#include <cstdio>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include <nlohmann/json.hpp>
Include dependency graph for chat_template.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  microtorch::chat::Error
 
struct  microtorch::chat::Template
 
struct  microtorch::chat::ToolCall
 
struct  microtorch::chat::Message
 
struct  microtorch::chat::Piece
 
struct  microtorch::chat::ParsedReply
 
struct  microtorch::chat::Resolution
 

Namespaces

namespace  microtorch
 
namespace  microtorch::chat
 
namespace  microtorch::chat::detail
 

Typedefs

using microtorch::chat::json = nlohmann::ordered_json
 

Functions

Template microtorch::chat::v1 ()
 
Template microtorch::chat::v2 ()
 
Template microtorch::chat::legacy_word ()
 
Template microtorch::chat::chatml (const std::string &name, bool qwen25)
 
Template microtorch::chat::gemma3 ()
 
std::vector< Template > microtorch::chat::registry ()
 
Template microtorch::chat::get (const std::string &id)
 
template<class J >
std::vector< Message > microtorch::chat::messages_from_json (const J &a)
 
std::vector< Message > microtorch::chat::from_pairs (const std::vector< std::pair< std::string, std::string > > &turns, const std::string *user=nullptr, const std::string *system=nullptr)
 
size_t microtorch::chat::check_structure (const std::vector< Message > &m, bool prompt, bool tools_ok=false)
 
bool microtorch::chat::py_space (uint32_t c)
 
std::string microtorch::chat::strip_py_ws (const std::string &s)
 
std::string microtorch::chat::detail::dump_py (const json &x)
 
std::string microtorch::chat::tool_json (const json &d)
 
std::vector< Piece > microtorch::chat::render_pieces (const std::vector< Message > &m, const Template &t, bool generation_prompt, int thinking=-1, const std::vector< json > &tools={})
 
std::string microtorch::chat::render (const std::vector< Message > &m, const Template &t, bool generation_prompt, int thinking=-1, const std::vector< json > &tools={})
 
std::vector< std::pair< size_t, size_t > > microtorch::chat::exchanges (const std::vector< Message > &m)
 
template<class Decode >
ParsedReply microtorch::chat::parse_reply (const std::vector< int > &ids, int call_id, Decode decode)
 
void microtorch::chat::check_control_tokens (const Template &t, const std::vector< std::string > &tokens, const std::vector< int32_t > &types)
 
std::string microtorch::chat::detail::jstr (const std::string &s)
 
std::string microtorch::chat::detail::go (const std::string &s)
 
void microtorch::chat::detail::paperkiln_only (const Template &t, const char *what)
 
std::string microtorch::chat::detail::jinja_tools (const Template &t)
 
std::string microtorch::chat::detail::modelfile_tools (const std::string &gguf_name, const Template &t)
 
std::string microtorch::chat::jinja (const Template &t)
 
std::string microtorch::chat::modelfile (const std::string &gguf_name, const Template &t)
 
std::string microtorch::chat::detail::sha256_hex (const std::string &msg)
 
Resolution microtorch::chat::resolve (const std::string &declared, const std::vector< std::string > &tokens, const std::string &model, const std::string &chat_template, const std::string &arch)
 

Variables

constexpr const char * microtorch::chat::kSystemModeV1 = "fold"
 
constexpr const char * microtorch::chat::kDefaultSftTurns = "all"
 
constexpr const char * microtorch::chat::kGGUFKey = "paperkiln.chat_template"
 
constexpr const char * microtorch::chat::kV1 = "paperkiln/1"
 
constexpr const char * microtorch::chat::kLegacyWord = "paperkiln/legacy-word"
 
constexpr const char * microtorch::chat::kV2 = "paperkiln/2"
 
const std::array< const char *, 4 > microtorch::chat::kV1Specials = {"<unk>", "<|endoftext|>", "<|user|>", "<|assistant|>"}
 
const std::array< const char *, 8 > microtorch::chat::kV2Control