Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Closed
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
19 changes: 14 additions & 5 deletions controllers/llamaCPP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ void llamaCPP::chatCompletion(
data["frequency_penalty"] =
(*jsonBody).get("frequency_penalty", 0).asFloat();
data["presence_penalty"] = (*jsonBody).get("presence_penalty", 0).asFloat();
std::string tools = (*jsonBody).get("tools", "").asString();
LOG_INFO << tools;
const Json::Value &messages = (*jsonBody)["messages"];
std::string grammar_file = (*jsonBody).get("grammar_file", "").asString();
std::ifstream file(grammar_file);
Expand All @@ -204,7 +206,7 @@ void llamaCPP::chatCompletion(
data["grammar"] = grammarBuf.str();
}
if (!llama.multimodal) {

bool systemPromptProcessed = false;
for (const auto &message : messages) {
std::string input_role = message["role"].asString();
std::string role;
Expand All @@ -217,10 +219,17 @@ void llamaCPP::chatCompletion(
std::string content = message["content"].asString();
formatted_output += role + content;
} else if (input_role == "system") {
role = system_prompt;
std::string content = message["content"].asString();
formatted_output = role + content + formatted_output;

if (systemPromptProcessed) {
LOG_ERROR << "System prompt already processed";
} else {
role = system_prompt;
std::string content = message["content"].asString();
if (tools != "") {
content += "\n" + tools;
}
formatted_output = role + content + formatted_output;
systemPromptProcessed = true;
}
} else {
role = input_role;
std::string content = message["content"].asString();
Expand Down