Skip to content

Commit

Permalink
To let users know that multiple keys can be used.
Browse files Browse the repository at this point in the history
I also removed one point with unnecessary code duplication.
  • Loading branch information
palandovalex committed Mar 8, 2024
1 parent e50a15d commit a8bde88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion memgpt/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def quickstart(
api_key = os.getenv("OPENAI_API_KEY")
while api_key is None or len(api_key) == 0:
# Ask for API key as input
api_key = questionary.password("Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):").ask()
api_key = questionary.password("Enter your OpenAI API key, or separated by comma keys (starts with 'sk-', see https://platform.openai.com/api-keys):").ask()
credentials.openai_key = api_key
credentials.save()

Expand Down
34 changes: 11 additions & 23 deletions memgpt/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
app = typer.Typer()


ENTER_OPENAI_KEY = "Enter your OpenAI API key, or separated by comma keys\n"\
"(starts with 'sk-', see https://platform.openai.com/api-keys):"


def get_azure_credentials():
creds = dict(
azure_key=os.getenv("AZURE_OPENAI_KEY"),
Expand Down Expand Up @@ -76,9 +80,7 @@ def configure_llm_endpoint(config: MemGPTConfig, credentials: MemGPTCredentials)
if openai_api_key is None:
while openai_api_key is None or len(openai_api_key) == 0:
# Ask for API key as input
openai_api_key = questionary.password(
"Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):"
).ask()
openai_api_key = questionary.password(ENTER_OPENAI_KEY).ask()
if openai_api_key is None:
raise KeyboardInterrupt
credentials.openai_key = openai_api_key
Expand All @@ -89,10 +91,7 @@ def configure_llm_endpoint(config: MemGPTConfig, credentials: MemGPTCredentials)
default_input = (
shorten_key_middle(credentials.openai_key) if credentials.openai_key.startswith("sk-") else credentials.openai_key
)
openai_api_key = questionary.password(
"Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):",
default=default_input,
).ask()
openai_api_key = questionary.password(ENTER_OPENAI_KEY, default=default_input).ask()
if openai_api_key is None:
raise KeyboardInterrupt
# If the user modified it, use the new one
Expand Down Expand Up @@ -330,24 +329,15 @@ def configure_model(config: MemGPTConfig, credentials: MemGPTCredentials, model_
if model is None:
raise KeyboardInterrupt

# If we got custom input, ask for raw input
if model == other_option_str:
model = questionary.text(
"Enter HuggingFace model tag (e.g. ehartford/dolphin-2.2.1-mistral-7b):",
default=default_model,
).ask()
if model is None:
raise KeyboardInterrupt
# TODO allow empty string for input?
model = None if len(model) == 0 else model

else:
# If we got custom input, ask for raw input
if model_options is None or model == other_option_str:
model = questionary.text(
"Enter HuggingFace model tag (e.g. ehartford/dolphin-2.2.1-mistral-7b):",
default=default_model,
).ask()
if model is None:
raise KeyboardInterrupt
# TODO allow empty string for input?
model = None if len(model) == 0 else model

# model wrapper
Expand Down Expand Up @@ -376,7 +366,7 @@ def configure_model(config: MemGPTConfig, credentials: MemGPTCredentials, model_
if local_auth_type is None:
raise KeyboardInterrupt
local_auth_key = questionary.password(
"Enter your authentication key:",
"Enter your authentication key, or separated by comma keys:",
).ask()
if local_auth_key is None:
raise KeyboardInterrupt
Expand Down Expand Up @@ -444,9 +434,7 @@ def configure_embedding_endpoint(config: MemGPTConfig, credentials: MemGPTCreden
# if we still can't find it, ask for it as input
while openai_api_key is None or len(openai_api_key) == 0:
# Ask for API key as input
openai_api_key = questionary.password(
"Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):"
).ask()
openai_api_key = questionary.password(ENTER_OPENAI_KEY).ask()
if openai_api_key is None:
raise KeyboardInterrupt
credentials.openai_key = openai_api_key
Expand Down

0 comments on commit a8bde88

Please sign in to comment.