Skip to content

Commit

Permalink
Added %debug mode mid-chat, experimenting with Llama-2
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Aug 23, 2023
1 parent 1ed362c commit 59536e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
39 changes: 33 additions & 6 deletions interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
# Message for when users don't have an OpenAI API key.
# `---` is at the bottom for aesthetic reasons.
missing_api_key_message = """
**OpenAI API key not found.** You can [get one here](https://platform.openai.com/account/api-keys).
🔑 **OpenAI API key not found.**
To use Open Interpreter in your terminal, set the environment variable using `export OPENAI_API_KEY=your_api_key` on Unix-based systems, or `setx OPENAI_API_KEY your_api_key` on Windows.
To use `GPT-4` (recommended) please provide an OpenAI API key. You can [get one here](https://platform.openai.com/account/api-keys).
To use `Llama-2`, which is slower (~1 word/minute on average systems) but free, run `interpreter --local`.
To use `Llama-2` (free but less capable) press `enter`.
---
"""
Expand Down Expand Up @@ -142,7 +142,9 @@ def chat(self, message=None, return_messages=False):
if not self.local:
# GPT-4
self.verify_api_key()
elif self.local:

# ^ verify_api_key may set self.local to True, so we run this as an 'if', not 'elif':
if self.local:
# Llama-2
if self.llama_instance == None:

Expand Down Expand Up @@ -204,6 +206,13 @@ def chat(self, message=None, return_messages=False):

# Add the user message to self.messages
self.messages.append({"role": "user", "content": user_input})

# Let the user turn on debug mode mid-chat
if user_input == "%debug":
print('', Markdown("> Entered debug mode"), '')
print(self.messages)
self.debug_mode = True
continue

# Respond, but gracefully handle CTRL-C / KeyboardInterrupt
try:
Expand All @@ -229,8 +238,26 @@ def verify_api_key(self):
else:
# Print message with newlines on either side (aesthetic choice)
print('', Markdown(missing_api_key_message), '')
self.api_key = input("Enter an OpenAI API key for this session:\n")

response = input("OpenAI API key: ")
import time

if response == "":
# User pressed `enter`, requesting Llama-2
self.local = True

print('', Markdown("Tip: Run `interpreter --local` to automatically use `Llama-2`."), '')
time.sleep(1)
assert False
return

else:
self.api_key = response
print(Markdown("> Model set to `gpt-4`"))
# time.sleep(1)
print('', Markdown("To save this key for later, run `export OPENAI_API_KEY=your_api_key` on Mac/Linux or `setx OPENAI_API_KEY your_api_key` on Windows."), '')
time.sleep(3)
print(Markdown("---"))

openai.api_key = self.api_key

def end_active_block(self):
Expand Down
5 changes: 3 additions & 2 deletions interpreter/llama_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_llama_2_instance():
else:
# If the file was not found, ask for confirmation to download it
download_path = os.path.join(default_path, file_name)
message = f"Llama-2 not found. Would you like to download the `6.9GB` file to `{download_path}`?"
message = f"Llama-2 not found. Would you like to download the `3GB` file to `{download_path}`?"
if confirm_action(message):
url = "https://huggingface.co/TheBloke/Llama-2-7B-chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q2_K.bin"
subprocess.run(f"curl -L '{url}' -o '{download_path}'", shell=True)
Expand All @@ -61,7 +61,8 @@ def get_llama_2_instance():

# Initialize and return Llama-2
llama_2 = Llama(model_path=model_path)
print("\n✅ Llama-2 loaded.", '')

# print("\n✅ Llama-2 loaded.", '')

return llama_2

Expand Down

0 comments on commit 59536e2

Please sign in to comment.