Skip to content

Commit

Permalink
Merge pull request #9 from akarshanbiswas/remove_frames
Browse files Browse the repository at this point in the history
Remove frames
  • Loading branch information
qnixsynapse authored Mar 14, 2024
2 parents 87ce78a + 9946e5e commit f65db09
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions source/rich-chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from rich.console import Console
from rich.live import Live
from rich.markdown import Markdown
from rich.panel import Panel


def remove_lines_console(num_lines):
Expand All @@ -29,7 +28,7 @@ def estimate_lines(text):


def handle_console_input(session: PromptSession) -> str:
return session.prompt("(Prompt: ⌥ + ⏎) | (Exit: ⌘ + c):\n", multiline=True).strip()
return session.prompt("(Prompt: ⌥ + ⏎) | (Exit: ⌘ + c): ", multiline=True).strip()


class conchat:
Expand Down Expand Up @@ -129,26 +128,20 @@ def get_model_name(self):
print(f"SlotsError: {e}")

def handle_streaming(self, prompt):
self.console.print(Markdown("**>**"), end=" ")
text = ""
block = "█ "
with Live(
console=self.console,
) as live:
for token in self.chat_generator(prompt=prompt):
# print(token)
if "content" in token["choices"][0]["delta"]:
text = text + token["choices"][0]["delta"]["content"]
if token["choices"][0]["finish_reason"] is not None:
# finish_reason = token["choices"][0]["finish_reason"]
block = ""
markdown = Markdown(text + block)
live.update(
Panel(
markdown,
title=self.model_name,
title_align="left",
border_style=self.model_frame_color,
),
markdown,
refresh=True,
)
self.chat_history.append({"role": "assistant", "content": text})
Expand All @@ -160,10 +153,6 @@ def chat(self):
while True:
try:
user_m = handle_console_input(self.session)
remove_lines_console(estimate_lines(text=user_m))
self.console.print(
Panel(Markdown(user_m), title="HUMAN", title_align="left")
)
self.handle_streaming(prompt=user_m)

# NOTE: Ctrl + c (keyboard) or Ctrl + d (eof) to exit
Expand Down

0 comments on commit f65db09

Please sign in to comment.