From 2db7745cbde543d7e1abd81c0389c544c84621db Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 1 Jun 2025 22:12:24 -0700 Subject: [PATCH] Show llama.cpp prompt processing on one line instead of many lines --- modules/llama_cpp_server.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/llama_cpp_server.py b/modules/llama_cpp_server.py index d695c74e..aa712541 100644 --- a/modules/llama_cpp_server.py +++ b/modules/llama_cpp_server.py @@ -409,14 +409,31 @@ class LlamaServer: def filter_stderr_with_progress(process_stderr): progress_pattern = re.compile(r'slot update_slots: id.*progress = (\d+\.\d+)') + last_was_progress = False + try: for line in iter(process_stderr.readline, ''): + line = line.rstrip('\n\r') # Remove existing newlines progress_match = progress_pattern.search(line) + if progress_match: - sys.stderr.write(line) + if last_was_progress: + # Overwrite the previous progress line using carriage return + sys.stderr.write(f'\r{line}') + else: + # First progress line - print normally + sys.stderr.write(line) sys.stderr.flush() + last_was_progress = True elif not line.startswith(('srv ', 'slot ')) and 'log_server_r: request: GET /health' not in line: - sys.stderr.write(line) + if last_was_progress: + # Finish the progress line with a newline, then print the new line + sys.stderr.write(f'\n{line}\n') + else: + # Normal line - print with newline + sys.stderr.write(f'{line}\n') sys.stderr.flush() + last_was_progress = False + # For filtered lines, don't change last_was_progress state except (ValueError, IOError): pass