From ed42154c78d7d7a63c092684deaa47d22750d796 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 19 Apr 2025 05:32:36 -0700 Subject: [PATCH] Revert "llama.cpp: close the connection immediately on 'Stop'" This reverts commit 5fdebc554b7ca46afb9695babf89397635e9f91d. --- modules/llama_cpp_server.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/llama_cpp_server.py b/modules/llama_cpp_server.py index 3025aa7d..5071c40c 100644 --- a/modules/llama_cpp_server.py +++ b/modules/llama_cpp_server.py @@ -141,24 +141,16 @@ class LlamaServer: print() # Make a direct request with streaming enabled using a context manager - with self.session.post(url, json=payload, stream=True, timeout=(5, 0.1)) as response: + with self.session.post(url, json=payload, stream=True) as response: response.raise_for_status() # Raise an exception for HTTP errors full_text = "" - iterator = response.iter_lines(decode_unicode=True) - while True: + # Process the streaming response + for line in response.iter_lines(decode_unicode=True): if shared.stop_everything: break - try: - line = next(iterator) - except requests.exceptions.Timeout: - # Check stop flag again on timeout - continue - except StopIteration: - break - if line: try: # Check if the line starts with "data: " and remove it