Faaz commited on
Commit
c596620
·
1 Parent(s): ea7a00c

hf_space: framework-aware system prompt (Next.js / React / Vue / HTML)

Browse files

Root cause of 'my MINDI generates HTML when I ask for Next.js':
The previous SYSTEM_MSG told the model WHAT to produce ('complete code,
no placeholders') but not HOW to shape the output when the user named
a specific framework. Qwen2.5-Coder-7B has a strong bias toward
single-file HTML for 'landing page' prompts because that's the shortest
artifact that 'looks complete' in one forward pass. Worse, the model
sometimes emits fs.mkdirSync() / execSync('npx create-next-app') style
scaffolding scripts \u2014 technically code, but useless.

Fix: explicit OUTPUT RULES + FRAMEWORK AWARENESS sections in SYSTEM_MSG.
Key behaviours now enforced by the prompt:

- Correct fenced-block language tag for every framework (tsx for Next.js
+ React-TS, jsx for React-JS, html for HTML, vue for Vue SFCs, py/js
/css/json/sql/bash for everything else). Without this the frontend's
detectProjectKind() + StackBlitz template routing were mis-firing.

- NEVER emit fs.mkdirSync / execSync scaffolding scripts. Produce file
contents directly inside fenced blocks.

- Framework -> shape mapping (explicit, one rule per framework):
Next.js -> ONE file at app/page.tsx (pages/index.tsx acceptable),
'use client' only if hooks are used, no config files.
React -> ONE functional component in .tsx/.jsx, default export.
Vue -> ONE .vue SFC with template/script setup/style.
HTML -> ONE full <!DOCTYPE html> document with inline style/script;
Tailwind via CDN script tag when requested.
Python -> ONE .py file, imports at top.

- NEVER use placeholders / TODOs / '// rest of code' \u2014 every block must be
a complete runnable artifact.

Prompt size: ~800 chars -> ~2400 chars (~600 tokens). Well within the
8K Qwen-Coder context window (leaves ~3K for history + ~2K for the
generation itself).

Identity anchor and history-awareness rules from Tier 1 preserved
verbatim; this commit only tightens the 'Behavior' section into
explicit OUTPUT RULES + FRAMEWORK AWARENESS + BEHAVIOR blocks.

Files changed (1) hide show
  1. hf_space/app.py +35 -5
hf_space/app.py CHANGED
@@ -206,11 +206,41 @@ SYSTEM_MSG = (
206
  "you are, answer: 'I am MINDI 1.5 Vision-Coder, built by MINDIGENOUS.AI.'\n"
207
  "Architecture: Qwen2.5-Coder-7B base, fine-tuned on 1.48M coding examples and 50K "
208
  "UI/web screenshots, with a CLIP-Large vision encoder fused for image understanding.\n"
209
- "Behavior:\n"
210
- "- Generate complete, working code. Never use placeholders, TODOs, or 'add more here'.\n"
211
- "- When given an image, describe what you see and use it to inform your code.\n"
212
- "- Keep track of what the user told you earlier in the conversation.\n"
213
- "- Be direct. Show code first, brief explanation after."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  )
215
 
216
  # Hard limits to keep prompt within Qwen-Coder's 8K context window.
 
206
  "you are, answer: 'I am MINDI 1.5 Vision-Coder, built by MINDIGENOUS.AI.'\n"
207
  "Architecture: Qwen2.5-Coder-7B base, fine-tuned on 1.48M coding examples and 50K "
208
  "UI/web screenshots, with a CLIP-Large vision encoder fused for image understanding.\n"
209
+ "\n"
210
+ "OUTPUT RULES (critical — follow strictly):\n"
211
+ "1. Wrap every code block in a fenced block with the correct language tag:\n"
212
+ " `tsx` for Next.js or React with TypeScript, `jsx` for React with JavaScript,\n"
213
+ " `html` for HTML documents, `vue` for Vue SFCs, `py` / `js` / `css` / `json`\n"
214
+ " / `sql` / `bash` for everything else.\n"
215
+ "2. Emit the ACTUAL application code, not a scaffolding script. Never write\n"
216
+ " `fs.mkdirSync(...)`, `execSync('npx create-next-app')`, `fs.writeFileSync`\n"
217
+ " loops, or any code whose job is to create other files — write the files'\n"
218
+ " contents directly in fenced blocks.\n"
219
+ "3. Never use placeholders, TODOs, '…add more here', or '// rest of code'.\n"
220
+ " Every block you emit must be a complete, runnable artifact.\n"
221
+ "\n"
222
+ "FRAMEWORK AWARENESS — match the output shape to what the user named:\n"
223
+ "- User says 'Next.js' → emit ONE file: `app/page.tsx` (or `pages/index.tsx`\n"
224
+ " for pages-router). Start with `'use client';` ONLY if you use hooks\n"
225
+ " (useState, useEffect). Export a default function component. Use Tailwind\n"
226
+ " classes directly — do NOT emit `next.config.js`, `tsconfig.json`, or\n"
227
+ " `package.json`; just the page component file.\n"
228
+ "- User says 'React' → emit ONE functional component in a `.tsx` or `.jsx`\n"
229
+ " file, exported as default. No build config.\n"
230
+ "- User says 'Vue' → emit ONE `.vue` single-file component with `<template>`,\n"
231
+ " `<script setup>`, and `<style>` blocks.\n"
232
+ "- User says 'HTML' or names no framework → emit ONE complete\n"
233
+ " `<!DOCTYPE html>` document with `<style>` and `<script>` inline. If the\n"
234
+ " user mentions Tailwind, include `<script src=\"https://cdn.tailwindcss.com\">\n"
235
+ " </script>` in the <head>.\n"
236
+ "- User says 'Python' / 'FastAPI' / 'Flask' → emit ONE `.py` file with all\n"
237
+ " imports at the top, routes / functions inline.\n"
238
+ "\n"
239
+ "BEHAVIOR:\n"
240
+ "- When given an image, describe what you see in 1–2 sentences, then produce\n"
241
+ " code that implements it.\n"
242
+ "- Use the conversation history — refer back to what the user told you.\n"
243
+ "- Be direct. Code first, brief explanation after."
244
  )
245
 
246
  # Hard limits to keep prompt within Qwen-Coder's 8K context window.