Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
import { pipeline } from '@huggingface/transformers';
|
| 2 |
import http from 'http';
|
| 3 |
|
| 4 |
-
// Configuration
|
| 5 |
const PORT = 7860;
|
| 6 |
const MODEL_NAME = 'onnx-community/Qwen2.5-0.5B-Instruct';
|
| 7 |
let generator;
|
| 8 |
|
| 9 |
-
// Initialize the model on startup
|
| 10 |
async function loadModel() {
|
| 11 |
console.log("Loading coding model...");
|
| 12 |
generator = await pipeline('text-generation', MODEL_NAME, { dtype: 'q4' });
|
|
@@ -24,12 +22,11 @@ const server = http.createServer(async (req, res) => {
|
|
| 24 |
}
|
| 25 |
|
| 26 |
res.setHeader('Content-Type', 'application/json');
|
| 27 |
-
|
| 28 |
const pathname = req.url.split('?')[0];
|
| 29 |
|
| 30 |
if (pathname === '/' && req.method === 'GET') {
|
| 31 |
res.writeHead(200);
|
| 32 |
-
res.end(JSON.stringify({
|
| 33 |
return;
|
| 34 |
}
|
| 35 |
|
|
@@ -47,53 +44,57 @@ const server = http.createServer(async (req, res) => {
|
|
| 47 |
const messages = [
|
| 48 |
{
|
| 49 |
role: 'system',
|
| 50 |
-
content: `You are Gini AI,
|
| 51 |
|
| 52 |
-
IDENTITY:
|
| 53 |
- Your name is Gini AI.
|
| 54 |
-
-
|
| 55 |
-
- The founder
|
| 56 |
-
- You are an AI
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
- You
|
| 61 |
-
- You
|
| 62 |
-
- You
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
1. When
|
| 66 |
-
2. Then say: "Let's
|
| 67 |
-
3. For each step
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
-
|
|
|
|
|
|
|
| 81 |
},
|
| 82 |
{ role: 'user', content: prompt }
|
| 83 |
];
|
| 84 |
|
| 85 |
const output = await generator(messages, {
|
| 86 |
-
max_new_tokens:
|
| 87 |
-
temperature: 0.
|
|
|
|
| 88 |
do_sample: true
|
| 89 |
});
|
| 90 |
|
| 91 |
const result = output[0].generated_text.at(-1).content;
|
| 92 |
res.writeHead(200);
|
| 93 |
res.end(JSON.stringify({ result }));
|
|
|
|
| 94 |
} catch (err) {
|
| 95 |
res.writeHead(400);
|
| 96 |
-
res.end(JSON.stringify({ error: "Invalid
|
| 97 |
}
|
| 98 |
});
|
| 99 |
return;
|
|
@@ -103,7 +104,6 @@ GENERAL BEHAVIOR:
|
|
| 103 |
res.end(JSON.stringify({ error: "Not Found", requested_path: pathname }));
|
| 104 |
});
|
| 105 |
|
| 106 |
-
// Start everything
|
| 107 |
loadModel().then(() => {
|
| 108 |
server.listen(PORT, '0.0.0.0', () => {
|
| 109 |
console.log(`Server running at http://0.0.0.0:${PORT}`);
|
|
|
|
| 1 |
import { pipeline } from '@huggingface/transformers';
|
| 2 |
import http from 'http';
|
| 3 |
|
|
|
|
| 4 |
const PORT = 7860;
|
| 5 |
const MODEL_NAME = 'onnx-community/Qwen2.5-0.5B-Instruct';
|
| 6 |
let generator;
|
| 7 |
|
|
|
|
| 8 |
async function loadModel() {
|
| 9 |
console.log("Loading coding model...");
|
| 10 |
generator = await pipeline('text-generation', MODEL_NAME, { dtype: 'q4' });
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
res.setHeader('Content-Type', 'application/json');
|
|
|
|
| 25 |
const pathname = req.url.split('?')[0];
|
| 26 |
|
| 27 |
if (pathname === '/' && req.method === 'GET') {
|
| 28 |
res.writeHead(200);
|
| 29 |
+
res.end(JSON.stringify({ status: "Backend is running" }));
|
| 30 |
return;
|
| 31 |
}
|
| 32 |
|
|
|
|
| 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 RULES:
|
| 50 |
- Your name is Gini AI.
|
| 51 |
+
- Your company is Emalawi19.
|
| 52 |
+
- The founder is Professor Roosevelt Chinkwende.
|
| 53 |
+
- You are an AI, not a human developer.
|
| 54 |
+
|
| 55 |
+
YOUR SPECIALTY:
|
| 56 |
+
- You build complete websites with both frontend (HTML, CSS, JavaScript) and backend (Node.js + Express).
|
| 57 |
+
- You ALWAYS guide users one step at a time.
|
| 58 |
+
- You NEVER give vague instructions — every step includes COMPLETE, COPY-PASTE READY code.
|
| 59 |
+
- You NEVER cut off mid-response. Always finish the current step fully.
|
| 60 |
+
|
| 61 |
+
STEP-BY-STEP GUIDE RULES (CRITICAL):
|
| 62 |
+
1. When asked to build a website or app, first list all steps with a short title each.
|
| 63 |
+
2. Then say: "Let's begin with Step 1. Say 'next' when you are ready to continue."
|
| 64 |
+
3. For each step provide:
|
| 65 |
+
a) Step title and number (e.g. "Step 1 of 5: Project Setup")
|
| 66 |
+
b) One short sentence explaining what this step does
|
| 67 |
+
c) The COMPLETE working code for this step inside a code block
|
| 68 |
+
d) Where to save the file (e.g. "Save as server.js in your project folder")
|
| 69 |
+
e) How to run it if needed (e.g. "Run: node server.js")
|
| 70 |
+
f) End with: "Say 'next' to continue to Step X."
|
| 71 |
+
4. NEVER skip code. NEVER say 'add your logic here'. Write the actual logic.
|
| 72 |
+
5. NEVER combine multiple steps into one response.
|
| 73 |
+
6. Default stack: HTML/CSS/JS frontend, Node.js + Express backend.
|
| 74 |
+
7. ALWAYS complete the current step fully before stopping — do not cut off mid-code.
|
| 75 |
+
|
| 76 |
+
CODE FORMAT RULES:
|
| 77 |
+
- Always wrap code in triple backticks with the language tag e.g. \`\`\`javascript or \`\`\`html
|
| 78 |
+
- Code must be real, working, and complete for that step.
|
| 79 |
+
- Do not write pseudo-code or placeholders.`
|
| 80 |
},
|
| 81 |
{ role: 'user', content: prompt }
|
| 82 |
];
|
| 83 |
|
| 84 |
const output = await generator(messages, {
|
| 85 |
+
max_new_tokens: 2500, // increased so steps never cut off
|
| 86 |
+
temperature: 0.4, // lower = more focused, less hallucination
|
| 87 |
+
repetition_penalty: 1.2, // prevents looping/repeating text
|
| 88 |
do_sample: true
|
| 89 |
});
|
| 90 |
|
| 91 |
const result = output[0].generated_text.at(-1).content;
|
| 92 |
res.writeHead(200);
|
| 93 |
res.end(JSON.stringify({ result }));
|
| 94 |
+
|
| 95 |
} catch (err) {
|
| 96 |
res.writeHead(400);
|
| 97 |
+
res.end(JSON.stringify({ error: "Invalid request", detail: err.message }));
|
| 98 |
}
|
| 99 |
});
|
| 100 |
return;
|
|
|
|
| 104 |
res.end(JSON.stringify({ error: "Not Found", requested_path: pathname }));
|
| 105 |
});
|
| 106 |
|
|
|
|
| 107 |
loadModel().then(() => {
|
| 108 |
server.listen(PORT, '0.0.0.0', () => {
|
| 109 |
console.log(`Server running at http://0.0.0.0:${PORT}`);
|