Function to tokenize the prompt
| 938 | |
| 939 | // Function to tokenize the prompt |
| 940 | static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt, |
| 941 | std::vector<llama_token> & prompt_tokens, const LlamaData & llama_data) { |
| 942 | const bool is_first = llama_kv_self_seq_pos_max(llama_data.context.get(), 0) == 0; |
| 943 | |
| 944 | const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, is_first, true); |
| 945 | prompt_tokens.resize(n_prompt_tokens); |
| 946 | if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), is_first, |
| 947 | true) < 0) { |
| 948 | printe("failed to tokenize the prompt\n"); |
| 949 | return -1; |
| 950 | } |
| 951 | |
| 952 | return n_prompt_tokens; |
| 953 | } |
| 954 | |
| 955 | // Check if we have enough space in the context to evaluate this batch |
| 956 | static int check_context_size(const llama_context_ptr & ctx, const llama_batch & batch) { |
no test coverage detected