From 63e977b9e3faf2cf5b50edbf1cc1f47fa7e1b08f Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 09:22:49 +0700 Subject: [PATCH] fix: chat completion parameters --- engine/commands/chat_completion_cmd.cc | 15 +++++++++------ engine/commands/chat_completion_cmd.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/engine/commands/chat_completion_cmd.cc b/engine/commands/chat_completion_cmd.cc index 9929321ee..cecee62ed 100644 --- a/engine/commands/chat_completion_cmd.cc +++ b/engine/commands/chat_completion_cmd.cc @@ -107,18 +107,21 @@ void ChatCompletionCmd::Exec(const std::string& host, int port, if (!user_input.empty()) { httplib::Client cli(address); - nlohmann::json json_data; - nlohmann::json new_data; + Json::Value json_data = mc.ToJson(); + Json::Value new_data; new_data["role"] = kUser; new_data["content"] = user_input; histories_.push_back(std::move(new_data)); json_data["engine"] = mc.engine; - json_data["messages"] = histories_; + Json::Value msgs_array(Json::arrayValue); + for (const auto& m : histories_) { + msgs_array.append(m); + } + json_data["messages"] = msgs_array; json_data["model"] = model_handle; //TODO: support non-stream json_data["stream"] = true; - json_data["stop"] = mc.stop; - auto data_str = json_data.dump(); + auto data_str = json_data.toStyledString(); // std::cout << data_str << std::endl; cli.set_read_timeout(std::chrono::seconds(60)); // std::cout << "> "; @@ -142,7 +145,7 @@ void ChatCompletionCmd::Exec(const std::string& host, int port, }; cli.send(req); - nlohmann::json ai_res; + Json::Value ai_res; ai_res["role"] = kAssistant; ai_res["content"] = ai_chat; histories_.push_back(std::move(ai_res)); diff --git a/engine/commands/chat_completion_cmd.h b/engine/commands/chat_completion_cmd.h index d962485bc..50c3ae497 100644 --- a/engine/commands/chat_completion_cmd.h +++ b/engine/commands/chat_completion_cmd.h @@ -13,6 +13,6 @@ class ChatCompletionCmd { const config::ModelConfig& mc, std::string msg); private: - std::vector histories_; + std::vector histories_; }; } // namespace commands \ No newline at end of file