Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
25 changes: 15 additions & 10 deletions controllers/llamaCPP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,8 @@ void llamaCPP::chatCompletion(
data["presence_penalty"] = (*jsonBody).get("presence_penalty", 0).asFloat();
const Json::Value &messages = (*jsonBody)["messages"];

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 (!grammar_file_content.empty()) {
data["grammar"] = grammar_file_content;
};

if (!llama.multimodal) {
Expand Down Expand Up @@ -514,6 +506,19 @@ bool llamaCPP::loadModelImpl(const Json::Value &jsonBody) {
if (!jsonBody["mlock"].isNull()) {
params.use_mlock = jsonBody["mlock"].asBool();
}

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();
grammar_file_content = grammarBuf.str();
}
};

params.model = jsonBody["llama_model_path"].asString();
params.n_gpu_layers = jsonBody.get("ngl", 100).asInt();
params.n_ctx = jsonBody.get("ctx_len", 2048).asInt();
Expand Down
1 change: 1 addition & 0 deletions controllers/llamaCPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -2576,5 +2576,6 @@ class llamaCPP : public drogon::HttpController<llamaCPP> {
int clean_cache_threshold;
std::atomic<bool> single_queue_is_busy; // This value only used under the
// condition n_parallel is 1
std::string grammar_file_content;
};
}; // namespace inferences