Skip to content

Commit

Permalink
Added: keyboard interrupt support in chat (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Apr 2, 2023
1 parent 80fef37 commit d871c1a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions gptty/gptty.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,21 @@ async def create_chat_room(configs=get_config_data(), log_responses:bool=True, c

# Continuously send and receive messages
while True:

# Get user input
i = await session.prompt_async(ANSI(f"{CYAN}> {RESET}"))
try:
i = await session.prompt_async(ANSI(f"{CYAN}> "))
# i = await ainput(f"{CYAN}> ")
tag,question = get_tag_from_text(i)
prompt_length = len(question)

# i = await ainput(f"{CYAN}> ")
tag,question = get_tag_from_text(i)
prompt_length = len(question)
# handle keyboard interrupt
except KeyboardInterrupt:
i = None

if prompt_length < 1:
if not i:
continue
elif prompt_length < 1:
click.echo('\nPlease provide an actual prompt.\n')
continue
elif i.strip() in [':help',':h']:
Expand Down

0 comments on commit d871c1a

Please sign in to comment.