MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / apply_chat_template

Function apply_chat_template

smallthinker/tools/run/run.cpp:920–937  ·  view source on GitHub ↗

Function to apply the chat template and resize `formatted` if needed

Source from the content-addressed store, hash-verified

918
919// Function to apply the chat template and resize `formatted` if needed
920static int apply_chat_template(const struct common_chat_templates * tmpls, LlamaData & llama_data, const bool append, bool use_jinja) {
921 common_chat_templates_inputs inputs;
922 for (const auto & msg : llama_data.messages) {
923 common_chat_msg cmsg;
924 cmsg.role = msg.role;
925 cmsg.content = msg.content;
926 inputs.messages.push_back(cmsg);
927 }
928 inputs.add_generation_prompt = append;
929 inputs.use_jinja = use_jinja;
930
931 auto chat_params = common_chat_templates_apply(tmpls, inputs);
932 // TODO: use other params for tool calls.
933 auto result = chat_params.prompt;
934 llama_data.fmtted.resize(result.size() + 1);
935 memcpy(llama_data.fmtted.data(), result.c_str(), result.size() + 1);
936 return result.size();
937}
938
939// Function to tokenize the prompt
940static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt,

Calls 6

push_backMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected