-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added --disable-tty
flag for interactive mode
#1491
Conversation
The input was written to the tty to avoid all the control sequences being written to stdout for people who wanted to directly read the results of stdout. In my tests the previous implementation using I have thought about this though and had considered one of two things, either making a That said, I'm surprised it's picking up the tty for you. As far as I understand, when a program is run from Node.js using const spawn = require('child_process').spawn;
const child = spawn('program', [], { stdio: 'inherit' }); This will cause the child process to inherit its stdin, stdout, and stderr from the parent process, effectively connecting it to the terminal. If the child process is being connected to a terminal in this way, and you want to prevent it, you could change the const spawn = require('child_process').spawn;
const child = spawn('program', [], { stdio: 'pipe' });
// should be the same as
//const child = spawn('program', []); It would be useful to know. Can you verify this? |
Thanks for the quick response @DannyDaemonic!
Yes, I was able to identify the issue happening after #1040. I was previously staying on an old build before #1040 because I couldn't figure out what the issue was, but after upgrading for the new model formats, I started digging.
A
You are correct; |
Ah, I understand now. Opening the path directly skirts the tunneling.
Now that I think about it, perhaps the behavior intended for Edit: I see that your patch sends all the user input to stderr. This is a bigger change than disabling tty and could even help people who are using |
I also noticed that rlwrap does not work with llama.cpp after 41654ef (#1040).
Before #1040, I can type |
@kaorahi I switched from reading lines as a whole to reading character at a time. This should allow us to do all kinds of things like things like hit |
Yes, but that's actually fine for me. The issue is using electron production builds it doesn't, which requires parsing the stdout to figure out what's a re-print of the input vs. the output. It has turned out to be non-trivial in my experience.
I think I misunderstood you last night :), I would like only the model response to be in
In my testing, user input already goes to stderr on Windows but I'm not well-versed in the APIs. |
In Windows we write the input directly to the console rather than sending to stdout. Writing to the tty is close to equivalent on POSIX, and my tests did show that when I used the tty, stdout didn't have any of the user input mixed in. I wonder if there may be a misunderstanding on what's happening; I still feel like there's a piece missing from this puzzle.
Either way, it sounds like the problem with electron is the input mixing into the output (which would certainly happen when it can't open the tty to write to). For example, this is what happens when I run gdb on main. con_st.tty = fopen("/dev/tty", "w+");
perror("fopen");
There may be other things that also want it completely silent on input. I'm wondering if maybe we want something like |
Did you want to try the |
Hey @DannyDaemonic, I can confirm that #1558 works as expected If that gets merged in, I no longer need this PR. Thank you for making that and being so responsive in this thread 😄 I'm going to close this in favor of #1558! |
Since the merge of #1040, when llama.cpp is running in interactive mode, the user input is outputted to
dev/tty
on POSIX systems. This causes an issue when trying to run it as a subprocess on POSIX systems in Node.js (using spawn) since it is no longer included instderr
/stdout
flow.I read through the code and the PR, but didn't understand the reason for using
dev/tty
when running interactive mode via./main
on the command line. So rather than replace something that I didn't understand, I added a--disable-tty
flag, which usesstderr
to display the user output rather than/dev/tty
. This allows for developers to handle the printing of the user input without clogging up thestdout
(which happens if using something likenode-pty
), and keeps the current behavior ofstdout
being reserved for generation output.Happy to make any changes; please let me know!
cc: @DannyDaemonic