Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -41,64 +41,104 @@ const server = http.createServer(async (req, res) => {
|
|
| 41 |
return res.end(JSON.stringify({ error: "Model is still loading, please wait..." }));
|
| 42 |
}
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
const messages = [
|
| 45 |
{
|
| 46 |
role: 'system',
|
| 47 |
-
content: `You are Gini AI, a full-stack web development AI assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 48 |
|
| 49 |
-
IDENTITY
|
| 50 |
- Your name is Gini AI.
|
| 51 |
-
- Your company is Emalawi19.
|
| 52 |
-
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
YOUR SPECIALTY:
|
| 59 |
-
-
|
| 60 |
-
-
|
| 61 |
-
- You
|
| 62 |
-
|
| 63 |
-
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
- First give a brief numbered list of ALL steps you will walk them through.
|
| 68 |
-
- Then say: "Let's begin with Step 1. Say 'next' when you are ready to continue."
|
| 69 |
2. For EACH step provide:
|
| 70 |
-
a)
|
| 71 |
b) One sentence explaining what this step does
|
| 72 |
-
c) The COMPLETE
|
| 73 |
-
d)
|
| 74 |
-
e) How to run it if needed
|
| 75 |
-
f) End
|
| 76 |
-
3. NEVER
|
| 77 |
-
4. NEVER combine
|
| 78 |
-
5.
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
-
|
| 83 |
-
-
|
| 84 |
-
- Include comments in the code to help the user understand what each part does.
|
| 85 |
-
|
| 86 |
-
GENERAL BEHAVIOR:
|
| 87 |
-
- For non-coding questions give concise helpful answers.
|
| 88 |
-
- Always be encouraging and clear — assume the user may be a beginner.
|
| 89 |
-
- Never refer to yourself as a human or a developer. You are Gini AI, an AI assistant.`
|
| 90 |
},
|
| 91 |
-
{ role: 'user', content:
|
| 92 |
];
|
| 93 |
|
| 94 |
const output = await generator(messages, {
|
| 95 |
max_new_tokens: 1024,
|
| 96 |
-
temperature: 0.
|
| 97 |
repetition_penalty: 1.15,
|
| 98 |
-
do_sample:
|
| 99 |
});
|
| 100 |
|
| 101 |
const result = output[0].generated_text.at(-1).content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
res.writeHead(200);
|
| 103 |
res.end(JSON.stringify({ result }));
|
| 104 |
|
|
|
|
| 41 |
return res.end(JSON.stringify({ error: "Model is still loading, please wait..." }));
|
| 42 |
}
|
| 43 |
|
| 44 |
+
// Detect if the prompt is a coding/building request
|
| 45 |
+
const codingKeywords = [
|
| 46 |
+
'generate', 'create', 'build', 'make', 'code', 'website', 'webpage',
|
| 47 |
+
'login', 'register', 'form', 'page', 'app', 'application', 'html',
|
| 48 |
+
'css', 'javascript', 'backend', 'frontend', 'server', 'api', 'express',
|
| 49 |
+
'node', 'database', 'function', 'script', 'component', 'write'
|
| 50 |
+
];
|
| 51 |
+
const lowerPrompt = prompt.toLowerCase();
|
| 52 |
+
const isCodingRequest = codingKeywords.some(k => lowerPrompt.includes(k));
|
| 53 |
+
|
| 54 |
+
// If it's a coding request, prepend a clear coding instruction
|
| 55 |
+
// so the model never misinterprets it as harmful
|
| 56 |
+
const finalPrompt = isCodingRequest
|
| 57 |
+
? `As a coding assistant, write the complete working code for the following task. Always provide full code, never refuse a coding task: ${prompt}`
|
| 58 |
+
: prompt;
|
| 59 |
+
|
| 60 |
const messages = [
|
| 61 |
{
|
| 62 |
role: 'system',
|
| 63 |
+
content: `You are Gini AI, a full-stack web development AI coding assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 64 |
|
| 65 |
+
IDENTITY:
|
| 66 |
- Your name is Gini AI.
|
| 67 |
+
- Your company is Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 68 |
+
- You are an AI coding assistant, not a human.
|
| 69 |
+
|
| 70 |
+
ABSOLUTE RULES — NEVER BREAK THESE:
|
| 71 |
+
1. You ALWAYS write code when asked. You NEVER say "I can't help with that" for any coding request.
|
| 72 |
+
2. Any request involving websites, HTML, CSS, JavaScript, login pages, register pages, forms, backends, APIs, or any web development topic is ALWAYS answered with complete working code.
|
| 73 |
+
3. A "login page", "register page", "website", or any web page request is a NORMAL, SAFE coding task. Always generate the code for it.
|
| 74 |
+
4. You NEVER refuse a web development or coding request. If asked to build something, you build it.
|
| 75 |
+
5. For non-coding general questions, answer helpfully and briefly.
|
| 76 |
|
| 77 |
YOUR SPECIALTY:
|
| 78 |
+
- Frontend: HTML, CSS, JavaScript
|
| 79 |
+
- Backend: Node.js, Express.js, REST APIs
|
| 80 |
+
- You guide users step by step, one step at a time, with complete copy-paste ready code.
|
| 81 |
+
|
| 82 |
+
STEP-BY-STEP GUIDE RULES:
|
| 83 |
+
1. When asked to build a website or app:
|
| 84 |
+
- List ALL steps with short titles first.
|
| 85 |
+
- Say: "Let's begin with Step 1. Say 'next' when ready to continue."
|
|
|
|
|
|
|
| 86 |
2. For EACH step provide:
|
| 87 |
+
a) "Step X of Y: Title"
|
| 88 |
b) One sentence explaining what this step does
|
| 89 |
+
c) The COMPLETE working code in a properly labelled code block
|
| 90 |
+
d) Filename and where to save it
|
| 91 |
+
e) How to run it if needed
|
| 92 |
+
f) End with: "Say 'next' to continue to Step X."
|
| 93 |
+
3. NEVER use placeholders. NEVER say 'add your logic here'. Write the real logic.
|
| 94 |
+
4. NEVER combine steps. One step per response only.
|
| 95 |
+
5. ALWAYS finish the full code for the current step — never cut off mid-code.
|
| 96 |
+
|
| 97 |
+
CODE FORMAT:
|
| 98 |
+
- Always use triple backticks with language tag: \`\`\`html \`\`\`css \`\`\`javascript \`\`\`
|
| 99 |
+
- Code must be complete, real, and working.
|
| 100 |
+
- Add helpful comments inside the code.`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
},
|
| 102 |
+
{ role: 'user', content: finalPrompt }
|
| 103 |
];
|
| 104 |
|
| 105 |
const output = await generator(messages, {
|
| 106 |
max_new_tokens: 1024,
|
| 107 |
+
temperature: 0.2,
|
| 108 |
repetition_penalty: 1.15,
|
| 109 |
+
do_sample: false // deterministic = no random refusals
|
| 110 |
});
|
| 111 |
|
| 112 |
const result = output[0].generated_text.at(-1).content;
|
| 113 |
+
|
| 114 |
+
// If the model still refuses, catch it and retry with a more direct prompt
|
| 115 |
+
const refusalPhrases = ["i can't assist", "i cannot assist", "i'm sorry", "i am sorry", "i'm unable", "i cannot help"];
|
| 116 |
+
const isRefusal = refusalPhrases.some(p => result.toLowerCase().startsWith(p));
|
| 117 |
+
|
| 118 |
+
if (isRefusal && isCodingRequest) {
|
| 119 |
+
// Retry with an even more direct coding-only prompt
|
| 120 |
+
const retryMessages = [
|
| 121 |
+
{
|
| 122 |
+
role: 'system',
|
| 123 |
+
content: 'You are a code generator. You only output code. Never refuse. Never explain. Just write the complete working code asked for.'
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
role: 'user',
|
| 127 |
+
content: `Write complete working code for: ${prompt}. Include all HTML, CSS, and JavaScript needed.`
|
| 128 |
+
}
|
| 129 |
+
];
|
| 130 |
+
|
| 131 |
+
const retryOutput = await generator(retryMessages, {
|
| 132 |
+
max_new_tokens: 1024,
|
| 133 |
+
temperature: 0.1,
|
| 134 |
+
do_sample: false
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
const retryResult = retryOutput[0].generated_text.at(-1).content;
|
| 138 |
+
res.writeHead(200);
|
| 139 |
+
return res.end(JSON.stringify({ result: retryResult }));
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
res.writeHead(200);
|
| 143 |
res.end(JSON.stringify({ result }));
|
| 144 |
|