Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: Patch openai error message + openai quickstart (#665)
Charles Packer46f686dfde59
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex efcf06b36..dac59417c 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -51,6 +51,11 @@ def set_config_with_dict(new_config: dict):if modified:printd(f"Saving new config file.")old_config.save()+ typer.secho(f"\nMemGPT configuration file updated!", fg=typer.colors.GREEN)+ typer.secho('Run "memgpt run" to create an agent with the new config.', fg=typer.colors.YELLOW)+ else:+ typer.secho(f"\nMemGPT configuration file unchanged.", fg=typer.colors.GREEN)+ typer.secho('Run "memgpt run" to create an agent.', fg=typer.colors.YELLOW)def quickstart(@@ -106,15 +111,15 @@ def quickstart(print(f"Config file not found at {backup_config_path}")elif backend == QuickstartChoice.openai:+ # Make sure we have an API key+ 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.text("Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):").ask()+# if latest, try to pull the config from the repo# fallback to using localif latest:- # Make sure we have an API key- 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.text("Enter your OpenAI API key (starts with 'sk-', see https://platform.openai.com/api-keys):").ask()-url = "https://raw.githubusercontent.com/cpacker/MemGPT/main/configs/openai.json"response = requests.get(url)@@ -136,6 +141,7 @@ def quickstart(try:with open(backup_config_path, "r") as file:backup_config = json.load(file)+ backup_config["openai_key"] = api_keyprint("Loaded backup config file successfully.")set_config_with_dict(backup_config)except FileNotFoundError:@@ -147,6 +153,7 @@ def quickstart(try:with open(backup_config_path, "r") as file:backup_config = json.load(file)+ backup_config["openai_key"] = api_keyprint("Loaded config file successfully.")set_config_with_dict(backup_config)except FileNotFoundError:diff --git a/memgpt/openai_tools.py b/memgpt/openai_tools.pyindex 9b2811b78..1744d2cb8 100644--- a/memgpt/openai_tools.py+++ b/memgpt/openai_tools.py@@ -1,9 +1,7 @@import random-import osimport timeimport requestsimport time-from typing import Callable, TypeVarimport urllibfrom box import Box@@ -109,27 +107,15 @@ def openai_chat_completions_request(url, api_key, data):return responseexcept requests.exceptions.HTTPError as http_err:# Handle HTTP errors (e.g., response 4XX, 5XX)- try:- response = response.json()- except:- pass- printd(f"Got HTTPError, exception={http_err}, payload={data}, response={response}")+ printd(f"Got HTTPError, exception={http_err}, payload={data}")raise http_errexcept requests.exceptions.RequestException as req_err:# Handle other requests-related errors (e.g., connection error)- try:- response = response.json()- except:- pass- printd(f"Got RequestException, exception={req_err}, response={response}")+ printd(f"Got RequestException, exception={req_err}")raise req_errexcept Exception as e:# Handle other potential errors- try:- response = response.json()- except:- pass- printd(f"Got unknown Exception, exception={e}, response={response}")+ printd(f"Got unknown Exception, exception={e}")raise e@@ -150,27 +136,15 @@ def openai_embeddings_request(url, api_key, data):return responseexcept requests.exceptions.HTTPError as http_err:# Handle HTTP errors (e.g., response 4XX, 5XX)- try:- response = response.json()- except:- pass- printd(f"Got HTTPError, exception={http_err}, response={response}")+ printd(f"Got HTTPError, exception={http_err}, payload={data}")raise http_errexcept requests.exceptions.RequestException as req_err:# Handle other requests-related errors (e.g., connection error)- try:- response = response.json()- except:- pass- printd(f"Got RequestException, exception={req_err}, response={response}")+ printd(f"Got RequestException, exception={req_err}")raise req_errexcept Exception as e:# Handle other potential errors- try:- response = response.json()- except:- pass- printd(f"Got unknown Exception, exception={e}, response={response}")+ printd(f"Got unknown Exception, exception={e}")raise e@@ -200,27 +174,15 @@ def azure_openai_chat_completions_request(resource_name, deployment_id, api_versreturn responseexcept requests.exceptions.HTTPError as http_err:# Handle HTTP errors (e.g., response 4XX, 5XX)- try:- response = response.json()- except:- pass- printd(f"Got HTTPError, exception={http_err}, response={response}")+ printd(f"Got HTTPError, exception={http_err}, payload={data}")raise http_errexcept requests.exceptions.RequestException as req_err:# Handle other requests-related errors (e.g., connection error)- try:- response = response.json()- except:- pass- printd(f"Got RequestException, exception={req_err}, response={response}")+ printd(f"Got RequestException, exception={req_err}")raise req_errexcept Exception as e:# Handle other potential errors- try:- response = response.json()- except:- pass- printd(f"Got unknown Exception, exception={e}, response={response}")+ printd(f"Got unknown Exception, exception={e}")raise e@@ -242,27 +204,15 @@ def azure_openai_embeddings_request(resource_name, deployment_id, api_version, areturn responseexcept requests.exceptions.HTTPError as http_err:# Handle HTTP errors (e.g., response 4XX, 5XX)- try:- response = response.json()- except:- pass- printd(f"Got HTTPError, exception={http_err}, response={response}")+ printd(f"Got HTTPError, exception={http_err}, payload={data}")raise http_errexcept requests.exceptions.RequestException as req_err:# Handle other requests-related errors (e.g., connection error)- try:- response = response.json()- except:- pass- printd(f"Got RequestException, exception={req_err}, response={response}")+ printd(f"Got RequestException, exception={req_err}")raise req_errexcept Exception as e:# Handle other potential errors- try:- response = response.json()- except:- pass- printd(f"Got unknown Exception, exception={e}, response={response}")+ printd(f"Got unknown Exception, exception={e}")raise e