From 4a19124cb7ca0f502733f57f4512f9d96c441ad5 Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Sat, 15 Apr 2023 16:40:12 -0500 Subject: [PATCH] Blacked. --- autogpt/json_fixes/auto_fix.py | 12 +++++++----- autogpt/llm_utils.py | 14 ++++++++------ autogpt/permanent_memory/sqlite3_store.py | 12 +++++++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/autogpt/json_fixes/auto_fix.py b/autogpt/json_fixes/auto_fix.py index 030e8aa7..9fcf909a 100644 --- a/autogpt/json_fixes/auto_fix.py +++ b/autogpt/json_fixes/auto_fix.py @@ -21,12 +21,14 @@ def fix_json(json_string: str, schema: str) -> str: # Try to fix the JSON using GPT: function_string = "def fix_json(json_string: str, schema:str=None) -> str:" args = [f"'''{json_string}'''", f"'''{schema}'''"] - description_string = "This function takes a JSON string and ensures that it"\ - " is parseable and fully compliant with the provided schema. If an object"\ - " or field specified in the schema isn't contained within the correct JSON,"\ - " it is omitted. The function also escapes any double quotes within JSON"\ - " string values to ensure that they are valid. If the JSON string contains"\ + description_string = ( + "This function takes a JSON string and ensures that it" + " is parseable and fully compliant with the provided schema. If an object" + " or field specified in the schema isn't contained within the correct JSON," + " it is omitted. The function also escapes any double quotes within JSON" + " string values to ensure that they are valid. If the JSON string contains" " any None or NaN values, they are replaced with null before being parsed." + ) # If it doesn't already start with a "`", add one: if not json_string.startswith("`"): diff --git a/autogpt/llm_utils.py b/autogpt/llm_utils.py index a8ac2cdb..43739009 100644 --- a/autogpt/llm_utils.py +++ b/autogpt/llm_utils.py @@ -126,13 +126,16 @@ def create_embedding_with_ada(text) -> list: backoff = 2 ** (attempt + 2) try: if CFG.use_azure: - return openai.Embedding.create(input=[text], - engine=CFG.get_azure_deployment_id_for_model("text-embedding-ada-002"), + return openai.Embedding.create( + input=[text], + engine=CFG.get_azure_deployment_id_for_model( + "text-embedding-ada-002" + ), )["data"][0]["embedding"] else: - return openai.Embedding.create(input=[text], model="text-embedding-ada-002")[ - "data" - ][0]["embedding"] + return openai.Embedding.create( + input=[text], model="text-embedding-ada-002" + )["data"][0]["embedding"] except RateLimitError: pass except APIError as e: @@ -148,4 +151,3 @@ def create_embedding_with_ada(text) -> list: f"API Bad gateway. Waiting {backoff} seconds..." + Fore.RESET, ) time.sleep(backoff) - diff --git a/autogpt/permanent_memory/sqlite3_store.py b/autogpt/permanent_memory/sqlite3_store.py index 57b29f6d..ecbc944a 100644 --- a/autogpt/permanent_memory/sqlite3_store.py +++ b/autogpt/permanent_memory/sqlite3_store.py @@ -18,11 +18,13 @@ class MemoryDB: # As last resort, open in dynamic memory. Won't be persistent. self.db_file = ":memory:" self.cnx = sqlite3.connect(self.db_file) - self.cnx.execute("CREATE VIRTUAL TABLE \ + self.cnx.execute( + "CREATE VIRTUAL TABLE \ IF NOT EXISTS text USING FTS5 \ (session, \ key, \ - block);") + block);" + ) self.session_id = int(self.get_max_session_id()) + 1 self.cnx.commit() @@ -66,7 +68,7 @@ class MemoryDB: cnx = self.get_cnx() cnx.execute(cmd_str, (session_id, key, text)) cnx.commit() - + # Overwrite text at key. def overwrite(self, key, text): self.delete_memory(key) @@ -76,8 +78,8 @@ class MemoryDB: cnx = self.get_cnx() cnx.execute(cmd_str, (session_id, key, text)) cnx.commit() - - def delete_memory(self, key, session_id = None): + + def delete_memory(self, key, session_id=None): session = session_id if session is None: session = self.session_id