Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

catch prompt assembly error

Abi Raja414d83c458b4
diff --git a/backend/main.py b/backend/main.py
index eac04b02..108c4dc7 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -137,12 +137,23 @@ async def stream_code(websocket: WebSocket):
async def process_chunk(content):
await websocket.send_json({"type": "chunk", "value": content})
- if params.get("resultImage") and params["resultImage"]:
- prompt_messages = assemble_prompt(
- params["image"], generated_code_config, params["resultImage"]
+ # Assemble the prompt
+ try:
+ if params.get("resultImage") and params["resultImage"]:
+ prompt_messages = assemble_prompt(
+ params["image"], generated_code_config, params["resultImage"]
+ )
+ else:
+ prompt_messages = assemble_prompt(params["image"], generated_code_config)
+ except:
+ await websocket.send_json(
+ {
+ "type": "error",
+ "value": "Error assembling prompt. Contact support at [email protected]",
+ }
)
- else:
- prompt_messages = assemble_prompt(params["image"], generated_code_config)
+ await websocket.close()
+ return
# Image cache for updates so that we don't have to regenerate images
image_cache = {}