Skip to content

Commit

Permalink
Merge pull request #818 from CyanideByte/active-block-unbound
Browse files Browse the repository at this point in the history
Fixes crash UnboundLocalError active_block
  • Loading branch information
KillianLucas authored Dec 14, 2023
2 parents 690efeb + e4dbe5f commit 4639d71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion interpreter/core/respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def respond(interpreter):
raise Exception(
f"{output}\n\nThere might be an issue with your API key(s).\n\nTo reset your API key (we'll use OPENAI_API_KEY for this example, but you may need to reset your ANTHROPIC_API_KEY, HUGGINGFACE_API_KEY, etc):\n Mac/Linux: 'export OPENAI_API_KEY=your-key-here',\n Windows: 'setx OPENAI_API_KEY your-key-here' then restart terminal.\n\n"
)
elif interpreter.local == False and "access" in str(e).lower():
elif interpreter.local == False and "not have access" in str(e).lower():
response = input(
f" You do not have access to {interpreter.model}. You will need to add a payment method and purchase credits for the OpenAI API billing page (different from ChatGPT) to use `GPT-4`.\n\nhttps://platform.openai.com/account/billing/overview\n\nWould you like to try GPT-3.5-TURBO instead? (y/n)\n\n "
)
Expand Down
16 changes: 9 additions & 7 deletions interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,11 @@ def terminal_interface(interpreter, message):
active_block.refresh(cursor=render_cursor)

# (Sometimes -- like if they CTRL-C quickly -- active_block is still None here)
if active_block:
active_block.end()
active_block = None
time.sleep(0.1)
if "active_block" in locals():
if active_block:
active_block.end()
active_block = None
time.sleep(0.1)

if not interactive:
# Don't loop
Expand All @@ -390,9 +391,10 @@ def terminal_interface(interpreter, message):
just_pressed_ctrl_c = True

# Exit gracefully
if active_block:
active_block.end()
active_block = None
if "active_block" in locals():
if active_block:
active_block.end()
active_block = None

if interactive:
# (this cancels LLM, returns to the interactive "> " input)
Expand Down

0 comments on commit 4639d71

Please sign in to comment.