Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit c1817e6

Browse files
committed
fix parameter issues and add pre prompt
1 parent a56f33d commit c1817e6

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

controllers/llamaCPP.cc

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,20 @@ void llamaCPP::chatCompletion(
7676
std::function<void(const HttpResponsePtr &)> &&callback) {
7777

7878
const auto &jsonBody = req->getJsonObject();
79-
std::string formatted_output =
80-
"Below is a conversation between an AI system named " + ai_prompt +
81-
" and " + user_prompt + "\n";
79+
std::string formatted_output = pre_prompt;
8280

8381
json data;
8482
json stopWords;
8583
// To set default value
8684
data["stream"] = true;
87-
data["n_predict"] = 30;
8885

8986
if (jsonBody) {
90-
data["n_predict"] = (*jsonBody)["max_tokens"].asInt();
91-
data["top_p"] = (*jsonBody)["top_p"].asFloat();
92-
data["temperature"] = (*jsonBody)["temperature"].asFloat();
93-
data["frequency_penalty"] = (*jsonBody)["frequency_penalty"].asFloat();
94-
data["presence_penalty"] = (*jsonBody)["presence_penalty"].asFloat();
87+
data["n_predict"] = (*jsonBody).get("max_tokens", 500).asInt();
88+
data["top_p"] = (*jsonBody).get("top_p", 0.95).asFloat();
89+
data["temperature"] = (*jsonBody).get("temperature", 0.8).asFloat();
90+
data["frequency_penalty"] =
91+
(*jsonBody).get("frequency_penalty", 0).asFloat();
92+
data["presence_penalty"] = (*jsonBody).get("presence_penalty", 0).asFloat();
9593

9694
const Json::Value &messages = (*jsonBody)["messages"];
9795
for (const auto &message : messages) {
@@ -109,7 +107,7 @@ void llamaCPP::chatCompletion(
109107
std::string content = message["content"].asString();
110108
formatted_output += role + content + "\n";
111109
}
112-
formatted_output += "assistant:";
110+
formatted_output += ai_prompt;
113111

114112
data["prompt"] = formatted_output;
115113
for (const auto &stop_word : (*jsonBody)["stop"]) {
@@ -225,6 +223,13 @@ void llamaCPP::loadModel(
225223
this->ai_prompt = (*jsonBody).get("ai_prompt", "ASSISTANT: ").asString();
226224
this->system_prompt =
227225
(*jsonBody).get("system_prompt", "ASSISTANT's RULE: ").asString();
226+
this->pre_prompt =
227+
(*jsonBody)
228+
.get("pre_prompt",
229+
"A chat between a curious user and an artificial intelligence "
230+
"assistant. The assistant follows the given rules no matter "
231+
"what.\\n")
232+
.asString();
228233
}
229234
#ifdef GGML_USE_CUBLAS
230235
LOG_INFO << "Setting up GGML CUBLAS PARAMS";

0 commit comments

Comments
 (0)