Skip to content

Commit 72c177c

Browse files
authored
fix system prompt handling (#7153)
1 parent 5a41992 commit 72c177c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

examples/server/server.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,6 @@ struct server_context {
651651
std::string system_prompt;
652652
std::vector<llama_token> system_tokens;
653653

654-
std::string name_user; // this should be the antiprompt
655-
std::string name_assistant;
656-
657654
// slots / clients
658655
std::vector<server_slot> slots;
659656
json default_generation_settings_for_props;
@@ -1100,15 +1097,11 @@ struct server_context {
11001097
system_need_update = false;
11011098
}
11021099

1103-
void system_prompt_set(const json & sys_props) {
1104-
system_prompt = sys_props.value("prompt", "");
1105-
name_user = sys_props.value("anti_prompt", "");
1106-
name_assistant = sys_props.value("assistant_name", "");
1100+
bool system_prompt_set(const std::string & sys_prompt) {
1101+
system_prompt = sys_prompt;
11071102

11081103
LOG_VERBOSE("system prompt process", {
11091104
{"system_prompt", system_prompt},
1110-
{"name_user", name_user},
1111-
{"name_assistant", name_assistant},
11121105
});
11131106

11141107
// release all slots
@@ -1117,6 +1110,7 @@ struct server_context {
11171110
}
11181111

11191112
system_need_update = true;
1113+
return true;
11201114
}
11211115

11221116
bool process_token(completion_token_output & result, server_slot & slot) {
@@ -1536,7 +1530,8 @@ struct server_context {
15361530
}
15371531

15381532
if (task.data.contains("system_prompt")) {
1539-
system_prompt_set(task.data.at("system_prompt"));
1533+
std::string sys_prompt = json_value(task.data, "system_prompt", std::string());
1534+
system_prompt_set(sys_prompt);
15401535

15411536
for (server_slot & slot : slots) {
15421537
slot.n_past = 0;
@@ -2920,7 +2915,7 @@ int main(int argc, char ** argv) {
29202915
server_params_parse(argc, argv, sparams, params);
29212916

29222917
if (!sparams.system_prompt.empty()) {
2923-
ctx_server.system_prompt_set(json::parse(sparams.system_prompt));
2918+
ctx_server.system_prompt_set(sparams.system_prompt);
29242919
}
29252920

29262921
if (params.model_alias == "unknown") {
@@ -3409,8 +3404,7 @@ int main(int argc, char ** argv) {
34093404
const auto handle_props = [&ctx_server](const httplib::Request & req, httplib::Response & res) {
34103405
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
34113406
json data = {
3412-
{ "user_name", ctx_server.name_user.c_str() },
3413-
{ "assistant_name", ctx_server.name_assistant.c_str() },
3407+
{ "system_prompt", ctx_server.system_prompt.c_str() },
34143408
{ "default_generation_settings", ctx_server.default_generation_settings_for_props },
34153409
{ "total_slots", ctx_server.params.n_parallel }
34163410
};

0 commit comments

Comments
 (0)