From 32c72b7965585c5b54909a6eb08ae4c66e39bc02 Mon Sep 17 00:00:00 2001 From: Gianluca Truda Date: Thu, 12 Sep 2024 20:14:48 +0100 Subject: [PATCH] Patched weird control flow bug. --- llm/cli.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/llm/cli.py b/llm/cli.py index 0bd1d8d8..32e3afdf 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -1660,18 +1660,19 @@ def logs_on(): def print_response(response, stream=True, rich=False): - - if stream and rich: - md = "" - with Live(Markdown(""), console=console) as live: + # These nested ifs are necessary!? Only way this works. + if stream: + if rich: + md = "" + with Live(Markdown(""), console=console) as live: + for chunk in response: + md += chunk + live.update(Markdown(md)) + else: for chunk in response: - md += chunk - live.update(Markdown(md)) - if stream and not rich: - for chunk in response: - console.print(chunk, end="") - sys.stdout.flush() - console.print() + console.print(chunk, end="") + sys.stdout.flush() + console.print() else: if rich: console.print(Markdown(response.text()))