Function to apply the chat template and resize `formatted` if needed
| 918 | |
| 919 | // Function to apply the chat template and resize `formatted` if needed |
| 920 | static 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 |
| 940 | static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt, |
no test coverage detected