Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
fix up pretty printing
Abi Raja0301f24fd89a
diff --git a/backend/main.py b/backend/main.pyindex cb8242a9..517eef73 100644--- a/backend/main.py+++ b/backend/main.py@@ -1,6 +1,7 @@# Load environment variables firstfrom dotenv import load_dotenv+load_dotenv()@@ -14,6 +15,7 @@ from fastapi.responses import HTMLResponseimport openaifrom llm import stream_openai_responsefrom mock import mock_completion+from utils import pprint_promptfrom image_generation import create_alt_url_mapping, generate_imagesfrom prompts import assemble_promptfrom routes import screenshot@@ -183,7 +185,6 @@ async def stream_code(websocket: WebSocket):prompt_messages += [{"role": "assistant" if index % 2 == 0 else "user", "content": text}]-image_cache = create_alt_url_mapping(params["history"][-2])if SHOULD_MOCK_AI_RESPONSE:diff --git a/backend/utils.py b/backend/utils.pyindex 88c3a67d..17d64239 100644--- a/backend/utils.py+++ b/backend/utils.py@@ -1,4 +1,9 @@import copy+import json+++def pprint_prompt(prompt_messages):+ print(json.dumps(truncate_data_strings(prompt_messages), indent=4))def truncate_data_strings(data):@@ -10,9 +15,12 @@ def truncate_data_strings(data):# Recursively call the function if the value is a dictionary or a listif isinstance(value, (dict, list)):cloned_data[key] = truncate_data_strings(value)- # Truncate the string if it starts with 'data:'- elif isinstance(value, str) and value.startswith("data:"):- cloned_data[key] = value[:20]+ # Truncate the string if it it's long and add ellipsis and length+ elif isinstance(value, str):+ cloned_data[key] = value[:40]+ if len(value) > 40:+ cloned_data[key] += "..." + f" ({len(value)} chars)"+elif isinstance(cloned_data, list):# Process each item in the listcloned_data = [truncate_data_strings(item) for item in cloned_data]