Skip to content

Conversation

@andrew-aladev
Copy link
Contributor

I've implemented non-interactive mode for CLI in the following way:

  1. Copied is_stdin_a_terminal and is_stdout_a_terminal functions from run.
  2. Disabled conversation mode when stdin or stdout is not a tty.
  3. Used <think> and </think> tags for marking think output.
  4. Removed console::log messages from output in non-interactive mode.
  5. Disabled the infinite loop case when it is not possible to get a new message in non-interactive mode.

Now it is possible to use the following commands: cli <<< 'input', echo 'input' | cli, cli > output.

This PR is a draft; please discuss.

@andrew-aladev andrew-aladev marked this pull request as draft December 19, 2025 12:06
Comment on lines +270 to +259
if (is_interactive) {
console::log("\n");
console::log("%s\n", LLAMA_ASCII_LOGO);
console::log("build : %s\n", inf.build_info.c_str());
console::log("model : %s\n", inf.model_name.c_str());
console::log("modalities : %s\n", modalities.c_str());

if (!params.system_prompt.empty()) {
console::log("using custom system prompt\n");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this (and most of the other things, like spinner etc) should be output regardless, but to stderr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok to output everything to stdout. Other CLI apps like claude code / ollama / gemini do that.

In most cases, outputting to a file via -o should be enough. I don't think we should recommend the use case of piping output from CLI to another application, it is just too error-prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you; tomorrow I will implement it.

@ngxson
Copy link
Collaborator

ngxson commented Dec 19, 2025

Now it is possible to use the following commands: cli <<< 'input', echo 'input' | cli, cli > output.

IMO we should stop supporting this use case by default as it make the code extremely error-prone. Any contributors in the future may add more debugging / formatting to the output which will definitely break your use case.

Instead, specify the input / output via proper arguments:

  • -f for input prompt from file
  • -o for output generation file

--no-conversation, --no-cnv can be use for disabling multi-turn. there is no need to auto exit if the output is not a tty

@CISC
Copy link
Collaborator

CISC commented Dec 19, 2025

--no-conversation, --no-cnv can be use for disabling multi-turn. there is no need to auto exit if the output is not a tty

You mean --single-turn, -no-cnv is not supported I think?

@ngxson
Copy link
Collaborator

ngxson commented Dec 19, 2025

Yes I mean --single-turn, -no-cnv

It is not yet supported in the new CLI, but adding it is easy (feel free to open a PR to add them back)

@andrew-aladev andrew-aladev force-pushed the feature/non-interactive-mode-for-cli branch from 9910b08 to 6c840fe Compare December 21, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants