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

Commit 4e691b1

Browse files
authored
fix: chat completion parameters (#1440)
1 parent 1b6e1d0 commit 4e691b1

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

engine/commands/chat_completion_cmd.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,21 @@ void ChatCompletionCmd::Exec(const std::string& host, int port,
107107

108108
if (!user_input.empty()) {
109109
httplib::Client cli(address);
110-
nlohmann::json json_data;
111-
nlohmann::json new_data;
110+
Json::Value json_data = mc.ToJson();
111+
Json::Value new_data;
112112
new_data["role"] = kUser;
113113
new_data["content"] = user_input;
114114
histories_.push_back(std::move(new_data));
115115
json_data["engine"] = mc.engine;
116-
json_data["messages"] = histories_;
116+
Json::Value msgs_array(Json::arrayValue);
117+
for (const auto& m : histories_) {
118+
msgs_array.append(m);
119+
}
120+
json_data["messages"] = msgs_array;
117121
json_data["model"] = model_handle;
118122
//TODO: support non-stream
119123
json_data["stream"] = true;
120-
json_data["stop"] = mc.stop;
121-
auto data_str = json_data.dump();
124+
auto data_str = json_data.toStyledString();
122125
// std::cout << data_str << std::endl;
123126
cli.set_read_timeout(std::chrono::seconds(60));
124127
// std::cout << "> ";
@@ -142,7 +145,7 @@ void ChatCompletionCmd::Exec(const std::string& host, int port,
142145
};
143146
cli.send(req);
144147

145-
nlohmann::json ai_res;
148+
Json::Value ai_res;
146149
ai_res["role"] = kAssistant;
147150
ai_res["content"] = ai_chat;
148151
histories_.push_back(std::move(ai_res));

engine/commands/chat_completion_cmd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class ChatCompletionCmd {
1313
const config::ModelConfig& mc, std::string msg);
1414

1515
private:
16-
std::vector<nlohmann::json> histories_;
16+
std::vector<Json::Value> histories_;
1717
};
1818
} // namespace commands

0 commit comments

Comments
 (0)