| 1540 | } |
| 1541 | |
| 1542 | server_tokens format_prompt_rerank( |
| 1543 | const struct llama_model * model, |
| 1544 | const struct llama_vocab * vocab, |
| 1545 | mtmd_context * mctx, |
| 1546 | const std::string & query, |
| 1547 | const std::string & doc) { |
| 1548 | server_tokens result = {}; |
| 1549 | |
| 1550 | const char * rerank_prompt = llama_model_chat_template(model, "rerank"); |
| 1551 | |
| 1552 | if (rerank_prompt != nullptr) { |
| 1553 | std::string prompt = rerank_prompt; |
| 1554 | string_replace_all(prompt, "{query}" , query); |
| 1555 | string_replace_all(prompt, "{document}", doc ); |
| 1556 | server_tokens tokens = tokenize_input_subprompt(vocab, mctx, prompt, false, true); |
| 1557 | result.push_back(tokens); |
| 1558 | } else { |
| 1559 | // Get EOS token - use SEP token as fallback if EOS is not available |
| 1560 | server_tokens query_tokens = tokenize_input_subprompt(vocab, mctx, query, false, false); |
| 1561 | server_tokens doc_tokens = tokenize_input_subprompt(vocab, mctx, doc, false, false); |
| 1562 | llama_token eos_token = llama_vocab_eos(vocab); |
| 1563 | if (eos_token == LLAMA_TOKEN_NULL) { |
| 1564 | eos_token = llama_vocab_sep(vocab); |
| 1565 | } |
| 1566 | |
| 1567 | if (llama_vocab_get_add_bos(vocab)) { |
| 1568 | result.push_back(llama_vocab_bos(vocab)); |
| 1569 | } |
| 1570 | result.push_back(query_tokens); |
| 1571 | if (llama_vocab_get_add_eos(vocab)) { |
| 1572 | result.push_back(eos_token); |
| 1573 | } |
| 1574 | if (llama_vocab_get_add_sep(vocab)) { |
| 1575 | result.push_back(llama_vocab_sep(vocab)); |
| 1576 | } |
| 1577 | result.push_back(doc_tokens); |
| 1578 | if (llama_vocab_get_add_eos(vocab)) { |
| 1579 | result.push_back(eos_token); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | return result; |
| 1584 | } |
no test coverage detected