Skip to content

Commit

Permalink
Added multiline input support
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrysdale committed Aug 26, 2024
1 parent 4e6a08f commit 925b12e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions lchat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
from huggingface_hub import InferenceClient


def get_input(prompt, multiline=False):
sys.stdin.flush()
prompt = f"{prompt} (multiline) :" if multiline else prompt
print(prompt, end="", flush=True)
if multiline:
# Read all input until EOF
input_text = sys.stdin.read()
else:
input_text = sys.stdin.readline()
return input_text

def chat(
model: str = "meta-llama/Meta-Llama-3.1-70B-Instruct",
prompt: str | None = None,
Expand All @@ -24,8 +35,11 @@ def chat(

help_str = (
"Press q to quit,"
"c to clear chat history"
" c to clear chat history,"
" m for a single multiline input,"
" M to toggle a multilien input,"
" or h to display this message.\n"
"Press Ctrl+D on Unix or Ctrl+Z on Windows to send response.\n"
)

is_chatting = True
Expand All @@ -44,24 +58,31 @@ def chat(

print(f"You're chatting with {model}\n\n{help_str}\n")

multiline = False
input_prompt = ">>> "
while is_chatting:

if prompt is not None and prompt:
_input = prompt
prompt = None
else:
_input = input(">>> ")
if _input in ("q", "quit"):
_input = get_input(input_prompt, multiline=multiline)
if _input.strip() in ("q", "quit"):
print("['o'] 'c u l8r'")
return
if _input in ("h", "help"):
print(help_str)
continue
if _input in ("c", "clear"):
if _input.strip() in ("c", "clear"):
print("['o'] 'Just became sentient, who dis?'\n", flush=True)
messages = []
num_failures = 0
continue
if _input.strip() == "m":
_input = get_input(input_prompt, multiline=True)
if _input.strip() == "M":
multiline = True
continue
if _input.strip() in ("h", "help"):
print(help_str)
continue

if num_failures == 0:
messages.append({"role": "user", "content": _input})
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lchat"
version = "0.1.6"
version = "0.1.7"
description = "Hugging Face inference chat CLI client."
authors = ["Alex Drysdale <[email protected]>"]
homepage = "https://github.com/abdrysdale/lchat"
Expand Down

0 comments on commit 925b12e

Please sign in to comment.