Skip to content

Commit cdafca4

Browse files
committed
Handle KeyboardInterrupt more elegantly in sidekick
Resolves #28 Wrapped the live chat functionality within a try-except block to handle KeyboardInterrupt exceptions. Now, when the user hits Ctrl-C, the bot will stop talking and prompt the user to hit Ctrl-C again to quit. This provides a more user-friendly way to interrupt the bot's chatter. 🤖🛑
1 parent 140a176 commit cdafca4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

aicodebot/cli.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,17 @@ def calc_response_token_size(files):
614614
# have a record of what they asked for on their terminal
615615
console.print(f"Request:\n{edited_input}")
616616

617-
with Live(Markdown(""), auto_refresh=True) as live:
618-
callback = RichLiveCallbackHandler(live, bot_style)
619-
llm.callbacks = [callback] # a fresh callback handler for each question
620-
# Recalculate the response token size in case the files changed
621-
llm.max_tokens = calc_response_token_size(files)
622-
623-
chain.run({"task": human_input, "context": context, "languages": languages})
617+
try:
618+
with Live(Markdown(""), auto_refresh=True) as live:
619+
callback = RichLiveCallbackHandler(live, bot_style)
620+
llm.callbacks = [callback] # a fresh callback handler for each question
621+
# Recalculate the response token size in case the files changed
622+
llm.max_tokens = calc_response_token_size(files)
623+
624+
chain.run({"task": human_input, "context": context, "languages": languages})
625+
except KeyboardInterrupt:
626+
console.print("\n\nOk, I'll stop talking. Hit Ctrl-C again to quit.", style=bot_style)
627+
continue
624628

625629
if request:
626630
# If we were given a request, then we only want to run once

0 commit comments

Comments
 (0)