Rahul-8799 commited on
Commit
5b769a5
·
verified ·
1 Parent(s): a2fd7cc

Update agents/software_engineer.py

Browse files
Files changed (1) hide show
  1. agents/software_engineer.py +23 -16
agents/software_engineer.py CHANGED
@@ -1,5 +1,6 @@
1
  from langchain_core.messages import AIMessage
2
  from utils.inference import call_model
 
3
 
4
  def run(state):
5
  design = state["architecture"]
@@ -10,30 +11,36 @@ def run(state):
10
 
11
  Requirements:
12
  - Full HTML document with <!DOCTYPE>
13
- - CSS inside <style> tags in <head>
14
- - Mobile responsive
15
- - Semantic HTML
16
- - Self-contained (runnable directly as .html)"""
 
17
 
18
  output = call_model(prompt)
19
 
20
- # 🧹 Cleanup: remove markdown code fences
21
- cleaned = output.replace("```html", "").replace("```css", "").replace("```", "").strip()
22
 
23
- # 🛡️ Fallback: if output doesn't start with <!DOCTYPE>, wrap it in a safe container
24
- if not cleaned.lower().startswith("<!doctype"):
25
  cleaned = f"""<!DOCTYPE html>
26
- <html>
27
  <head>
28
- <meta charset="UTF-8">
29
- <title>Generated UI</title>
30
- <style>
31
- /* Add basic reset to prevent layout issues */
32
- body {{ font-family: Arial, sans-serif; padding: 20px; }}
33
- </style>
 
 
 
34
  </head>
35
  <body>
36
- {cleaned}
 
 
37
  </body>
38
  </html>"""
39
 
 
1
  from langchain_core.messages import AIMessage
2
  from utils.inference import call_model
3
+ import re
4
 
5
  def run(state):
6
  design = state["architecture"]
 
11
 
12
  Requirements:
13
  - Full HTML document with <!DOCTYPE>
14
+ - CSS embedded inside <style> tags in <head>
15
+ - Mobile responsive and visually appealing
16
+ - Self-contained (runnable directly as .html file)
17
+ - No markdown formatting (no ```html, ```css, etc.)
18
+ """
19
 
20
  output = call_model(prompt)
21
 
22
+ # Clean markdown code block formatting if the model added it anyway
23
+ cleaned = re.sub(r"```(?:html|css)?", "", output).strip()
24
 
25
+ # Fallback HTML wrapper if model output is incomplete or broken
26
+ if "<!DOCTYPE html>" not in cleaned.lower():
27
  cleaned = f"""<!DOCTYPE html>
28
+ <html lang="en">
29
  <head>
30
+ <meta charset="UTF-8">
31
+ <title>Generated UI</title>
32
+ <style>
33
+ body {{
34
+ font-family: Arial, sans-serif;
35
+ background-color: #f4f4f4;
36
+ padding: 2rem;
37
+ }}
38
+ </style>
39
  </head>
40
  <body>
41
+ <main>
42
+ {cleaned}
43
+ </main>
44
  </body>
45
  </html>"""
46