Skip to content

Commit

Permalink
Merge pull request #398 from janhq/397-grammar-file-not-found-llamacp…
Browse files Browse the repository at this point in the history
…pcc201

bug: correct way of handle grammar file
  • Loading branch information
tikikun authored Jan 31, 2024
2 parents 5ce716b + ef16ba7 commit 626c753
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions controllers/llamaCPP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,19 @@ void llamaCPP::chatCompletion(
(*jsonBody).get("frequency_penalty", 0).asFloat();
data["presence_penalty"] = (*jsonBody).get("presence_penalty", 0).asFloat();
const Json::Value &messages = (*jsonBody)["messages"];
std::string grammar_file = (*jsonBody).get("grammar_file", "").asString();
std::ifstream file(grammar_file);
if (!file) {
LOG_ERROR << "Grammar file not found";
} else {
std::stringstream grammarBuf;
grammarBuf << file.rdbuf();
data["grammar"] = grammarBuf.str();
}

if (!(*jsonBody)["grammar_file"].isNull()) {
std::string grammar_file = (*jsonBody)["grammar_file"].asString();
std::ifstream file(grammar_file);
if (!file) {
LOG_ERROR << "Grammar file not found";
} else {
std::stringstream grammarBuf;
grammarBuf << file.rdbuf();
data["grammar"] = grammarBuf.str();
}
};

if (!llama.multimodal) {

for (const auto &message : messages) {
Expand Down

0 comments on commit 626c753

Please sign in to comment.