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
13 changes: 9 additions & 4 deletions engine/commands/chat_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ void ChatCmd::Exec(const std::string& host, int port,
return;
}

// Interactive mode or not
bool interactive = msg.empty();

// Some instruction for user here
std::cout << "Inorder to exit, type `exit()`" << std::endl;
if (interactive) {
std::cout << "Inorder to exit, type `exit()`" << std::endl;
}
// Model is loaded, start to chat
{
while (true) {
do {
std::string user_input = std::move(msg);
std::cout << "> ";
if (user_input.empty()) {
std::cout << "> ";
std::getline(std::cin, user_input);
}
if (user_input == kExitChat) {
Expand Down Expand Up @@ -128,7 +133,7 @@ void ChatCmd::Exec(const std::string& host, int port,
histories_.push_back(std::move(ai_res));
}
// std::cout << "ok Done" << std::endl;
}
} while (interactive);
}
}

Expand Down
10 changes: 5 additions & 5 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ void CommandLineParser::SetupCommonCommands() {
auto chat_cmd = app_.add_subcommand("chat", "Send a chat completion request");
chat_cmd->group(kCommonCommandsGroup);
chat_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
" chat [model_id] [options]");
" chat [model_id] -m [msg]");
chat_cmd->add_option("model_id", cml_data_.model_id, "");
chat_cmd->add_option("-m,--message", cml_data_.msg,
"Message to chat with model");
chat_cmd->callback([this, chat_cmd] {
if (cml_data_.model_id.empty()) {
CLI_LOG("[model_id] is required\n");
if (cml_data_.model_id.empty() || cml_data_.msg.empty()) {
CLI_LOG("[model_id] and [msg] are required\n");
CLI_LOG(chat_cmd->help());
return;
}

commands::ChatCmd().Exec(cml_data_.config.apiServerHost,
std::stoi(cml_data_.config.apiServerPort), cml_data_.model_id,
cml_data_.msg);
std::stoi(cml_data_.config.apiServerPort),
cml_data_.model_id, cml_data_.msg);
});
}

Expand Down