Skip to content

Commit

Permalink
Patched weird control flow bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
gianlucatruda committed Sep 12, 2024
1 parent 7e13952 commit 32c72b7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 32c72b7

Please sign in to comment.