mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-18 05:05:16 +01:00
Fix the errors with parsing
This commit is contained in:
@@ -55,6 +55,7 @@ class AI:
|
||||
msg = delta.get("content", "")
|
||||
print(msg, end="")
|
||||
chat.append(msg)
|
||||
print()
|
||||
messages = messages + [{"role": "assistant", "content": "".join(chat)}]
|
||||
logger.debug(f"Chat completion finished: {messages}")
|
||||
return messages
|
||||
|
||||
@@ -2,21 +2,9 @@ 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
|
||||
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. Otherwise, treat README as optional and
|
||||
# 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
|
||||
|
||||
# Get all ``` blocks and preceding filenames
|
||||
regex = r"(\S+?)\n```\S+\n(.+?)```"
|
||||
matches = re.finditer(regex, code_blocks, re.DOTALL)
|
||||
matches = re.finditer(regex, chat, re.DOTALL)
|
||||
|
||||
files = []
|
||||
for match in matches:
|
||||
@@ -29,8 +17,9 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:
|
||||
# Add the file to the list
|
||||
files.append((path, code))
|
||||
|
||||
# Add README to the list
|
||||
files.append(("README.txt", readme))
|
||||
# Get all the text before the first ``` block
|
||||
readme = chat.split("```")[0]
|
||||
files.append(("README.md", readme))
|
||||
|
||||
# Return the files
|
||||
return files
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
from gpt_engineer.ai import AI
|
||||
from gpt_engineer.chat_to_files import parse_chat, to_files
|
||||
from gpt_engineer.chat_to_files import to_files
|
||||
from gpt_engineer.db import DBs
|
||||
|
||||
|
||||
@@ -169,15 +170,9 @@ def gen_entrypoint(ai, dbs):
|
||||
)
|
||||
print()
|
||||
|
||||
blocks = parse_chat(messages[-1]["content"])
|
||||
for lang, _ in blocks:
|
||||
assert lang in [
|
||||
"",
|
||||
"bash",
|
||||
"sh",
|
||||
], "Generated entrypoint command that was not bash"
|
||||
|
||||
dbs.workspace["run.sh"] = "\n".join(block for lang, block in blocks)
|
||||
regex = r"```\S*\n(.+?)```"
|
||||
matches = re.finditer(regex, messages[-1]["content"], re.DOTALL)
|
||||
dbs.workspace["run.sh"] = "\n".join(match.group(1) for match in matches)
|
||||
return messages
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user