Skip to content
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

llama : C++20 compatibility for u8 strings #8408

Merged
merged 1 commit into from
Jul 10, 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
12 changes: 9 additions & 3 deletions src/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
#include <io.h>
#endif

#if __cplusplus >= 202000L
#define LU8(x) (const char*)(u8##x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use a proper cast, instead of a c-style one.

Copy link
Contributor Author

@iboB iboB Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It's not like there are any "proper" casts in the file itself. All other casts are C-style.

#else
#define LU8(x) u8##x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why prefix the macro with L ? , that makes it seem like it is a wide string.

Copy link
Contributor Author

@iboB iboB Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in llama, could be T as well. I wanted three characters to minimize the risk of collisions, as simply U8 looks risky.

#endif

#include <algorithm>
#include <array>
#include <cassert>
Expand Down Expand Up @@ -21509,12 +21515,12 @@ static int32_t llama_chat_apply_template_internal(
if (add_ass) {
ss << "<|assistant|>";
}
} else if (tmpl == "minicpm" || tmpl_contains(u8"<用户>")) {
} else if (tmpl == "minicpm" || tmpl_contains(LU8("<用户>"))) {
// MiniCPM-3B-OpenHermes-2.5-v2-GGUF
for (auto message : chat) {
std::string role(message->role);
if (role == "user") {
ss << u8"<用户>";
ss << LU8("<用户>");
ss << trim(message->content);
ss << "<AI>";
} else {
Expand All @@ -21530,7 +21536,7 @@ static int32_t llama_chat_apply_template_internal(
} else if (role == "user") {
ss << "User: " << message->content << "\n\n";
} else if (role == "assistant") {
ss << "Assistant: " << message->content << u8"<|end▁of▁sentence|>";
ss << "Assistant: " << message->content << LU8("<|end▁of▁sentence|>");
}
}
if (add_ass) {
Expand Down
Loading