| 80 | } |
| 81 | |
| 82 | AceStepTokenizedText AceStepTextTokenizer::tokenize_text(const std::string & text, int64_t max_length) const { |
| 83 | if (max_length <= 0) { |
| 84 | throw std::runtime_error("ACE-Step tokenizer max_length must be positive"); |
| 85 | } |
| 86 | AceStepTokenizedText tokenized; |
| 87 | tokenized.text = text; |
| 88 | tokenized.input_ids = impl_->tokenizer->encode(text); |
| 89 | if (resources_ == ResourceSet::TextEncoder) { |
| 90 | tokenized.input_ids.push_back(impl_->pad_token_id); |
| 91 | } |
| 92 | if (static_cast<int64_t>(tokenized.input_ids.size()) > max_length) { |
| 93 | tokenized.input_ids.resize(static_cast<size_t>(max_length)); |
| 94 | } |
| 95 | tokenized.attention_mask.assign(tokenized.input_ids.size(), 1); |
| 96 | const size_t padded = static_cast<size_t>(max_length); |
| 97 | tokenized.input_ids.resize(padded, impl_->pad_token_id); |
| 98 | tokenized.attention_mask.resize(padded, 0); |
| 99 | return tokenized; |
| 100 | } |
| 101 | |
| 102 | std::string AceStepTextTokenizer::apply_chat_template( |
| 103 | const std::string & system_content, |
no test coverage detected