Fix linting

This commit is contained in:
Enzo Martin
2023-06-18 10:34:35 +02:00
parent 2f2fef50fe
commit 8b3862d94d
3 changed files with 20 additions and 17 deletions

View File

@@ -1,15 +1,17 @@
import re import re
def parse_chat(chat):# -> List[Tuple[str, str]]:
# Split the chat into sections by the '*CODEBLOCKSBELOW*' token
split_chat = chat.split('*CODEBLOCKSBELOW*')
# Check if the '*CODEBLOCKSBELOW*' token was found def parse_chat(chat): # -> List[Tuple[str, str]]:
# Split the chat into sections by the "*CODEBLOCKSBELOW*" token
split_chat = chat.split("*CODEBLOCKSBELOW*")
# Check if the "*CODEBLOCKSBELOW*" token was found
is_token_found = len(split_chat) > 1 is_token_found = len(split_chat) > 1
# If the '*CODEBLOCKSBELOW*' token is found, use the first part as README and second part as code blocks. # If the "*CODEBLOCKSBELOW*" token is found, use the first part as README
# Otherwise, treat README as optional and proceed with empty README and the entire chat as code blocks # and second part as code blocks. Otherwise, treat README as optional and
readme = split_chat[0].strip() if is_token_found else 'No readme' # proceed with empty README and the entire chat as code blocks
readme = split_chat[0].strip() if is_token_found else "No readme"
code_blocks = split_chat[1] if is_token_found else chat code_blocks = split_chat[1] if is_token_found else chat
# Get all ``` blocks and preceding filenames # Get all ``` blocks and preceding filenames
@@ -19,7 +21,7 @@ def parse_chat(chat):# -> List[Tuple[str, str]]:
files = [] files = []
for match in matches: for match in matches:
# Strip the filename of any non-allowed characters and convert / to \ # Strip the filename of any non-allowed characters and convert / to \
path = re.sub(r'[<>"|?*]', '', match.group(1)) path = re.sub(r'[<>"|?*]', "", match.group(1))
# Get the code # Get the code
code = match.group(2) code = match.group(2)
@@ -28,14 +30,14 @@ def parse_chat(chat):# -> List[Tuple[str, str]]:
files.append((path, code)) files.append((path, code))
# Add README to the list # Add README to the list
files.append(('README.txt', readme)) files.append(("README.txt", readme))
# Return the files # Return the files
return files return files
def to_files(chat, workspace): def to_files(chat, workspace):
workspace['all_output.txt'] = chat workspace["all_output.txt"] = chat
files = parse_chat(chat) files = parse_chat(chat)
for file_name, file_content in files: for file_name, file_content in files:

View File

@@ -1,6 +1,7 @@
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
# This class represents a simple database that stores its data as files in a directory. # This class represents a simple database that stores its data as files in a directory.
# It supports both text and binary files, and can handle directory structures. # It supports both text and binary files, and can handle directory structures.
class DB: class DB:
@@ -18,7 +19,7 @@ class DB:
# Check if the file exists before trying to open it. # Check if the file exists before trying to open it.
if full_path.is_file(): if full_path.is_file():
# Open the file in text mode and return its content. # Open the file in text mode and return its content.
with full_path.open('r') as f: with full_path.open("r") as f:
return f.read() return f.read()
else: else:
# If the file doesn't exist, raise an error. # If the file doesn't exist, raise an error.

View File

@@ -1,14 +1,13 @@
import os
import json import json
import os
import pathlib import pathlib
import typer
import shutil import shutil
import typer
from gpt_engineer.ai import AI from gpt_engineer.ai import AI
from gpt_engineer.steps import STEPS
from gpt_engineer.db import DB, DBs from gpt_engineer.db import DB, DBs
from gpt_engineer.steps import STEPS
app = typer.Typer() app = typer.Typer()
@@ -30,7 +29,7 @@ def chat(
memory_path = input_path / (run_prefix + "memory") memory_path = input_path / (run_prefix + "memory")
workspace_path = input_path / (run_prefix + "workspace") workspace_path = input_path / (run_prefix + "workspace")
if delete_existing == 'true': if delete_existing == "true":
# Delete files and subdirectories in paths # Delete files and subdirectories in paths
shutil.rmtree(memory_path, ignore_errors=True) shutil.rmtree(memory_path, ignore_errors=True)
shutil.rmtree(workspace_path, ignore_errors=True) shutil.rmtree(workspace_path, ignore_errors=True)
@@ -52,5 +51,6 @@ def chat(
messages = step(ai, dbs) messages = step(ai, dbs)
dbs.logs[step.__name__] = json.dumps(messages) dbs.logs[step.__name__] = json.dumps(messages)
if __name__ == "__main__": if __name__ == "__main__":
app() app()