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

Commit 44bdc65

Browse files
authored
fix: cortex chat is a non-interactive request (#1331)
1 parent 3320218 commit 44bdc65

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

engine/commands/chat_cmd.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ void ChatCmd::Exec(const std::string& host, int port,
7171
return;
7272
}
7373

74+
// Interactive mode or not
75+
bool interactive = msg.empty();
76+
7477
// Some instruction for user here
75-
std::cout << "Inorder to exit, type `exit()`" << std::endl;
78+
if (interactive) {
79+
std::cout << "Inorder to exit, type `exit()`" << std::endl;
80+
}
7681
// Model is loaded, start to chat
7782
{
78-
while (true) {
83+
do {
7984
std::string user_input = std::move(msg);
80-
std::cout << "> ";
8185
if (user_input.empty()) {
86+
std::cout << "> ";
8287
std::getline(std::cin, user_input);
8388
}
8489
if (user_input == kExitChat) {
@@ -128,7 +133,7 @@ void ChatCmd::Exec(const std::string& host, int port,
128133
histories_.push_back(std::move(ai_res));
129134
}
130135
// std::cout << "ok Done" << std::endl;
131-
}
136+
} while (interactive);
132137
}
133138
}
134139

engine/controllers/command_line_parser.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ void CommandLineParser::SetupCommonCommands() {
122122
auto chat_cmd = app_.add_subcommand("chat", "Send a chat completion request");
123123
chat_cmd->group(kCommonCommandsGroup);
124124
chat_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
125-
" chat [model_id] [options]");
125+
" chat [model_id] -m [msg]");
126126
chat_cmd->add_option("model_id", cml_data_.model_id, "");
127127
chat_cmd->add_option("-m,--message", cml_data_.msg,
128128
"Message to chat with model");
129129
chat_cmd->callback([this, chat_cmd] {
130-
if (cml_data_.model_id.empty()) {
131-
CLI_LOG("[model_id] is required\n");
130+
if (cml_data_.model_id.empty() || cml_data_.msg.empty()) {
131+
CLI_LOG("[model_id] and [msg] are required\n");
132132
CLI_LOG(chat_cmd->help());
133133
return;
134134
}
135135

136136
commands::ChatCmd().Exec(cml_data_.config.apiServerHost,
137-
std::stoi(cml_data_.config.apiServerPort), cml_data_.model_id,
138-
cml_data_.msg);
137+
std::stoi(cml_data_.config.apiServerPort),
138+
cml_data_.model_id, cml_data_.msg);
139139
});
140140
}
141141

0 commit comments

Comments
 (0)