Skip to content

[Build] Use C++17 Constructor for tiktoken.cpp when C++20 is unavailable #5025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions extension/llm/tokenizer/tiktoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ Tiktoken::_split_with_allowed_special_token(
return std::make_pair(std::nullopt, input);
}

#if __cplusplus >= 202002L
auto start = input.begin();
#else
const char* start = input.data();
#endif
std::string special;
while (true) {
if (!re2::RE2::FindAndConsume(&input, *_special_token_regex, &special)) {
Expand All @@ -262,9 +266,15 @@ Tiktoken::_split_with_allowed_special_token(

if (allowed_special.count(special) == 1) {
// Found an allowed special token, split the text with it.
#if __cplusplus >= 202002L
return std::make_pair(
special,
re2::StringPiece(start, input.begin() - start - special.size()));
#else
return std::make_pair(
special,
re2::StringPiece(start, (input.data() - start) - special.size()));
#endif
} // else try to find the next special token
}

Expand Down
Loading