Emalawi19 commited on
Commit
c91dd81
·
verified ·
1 Parent(s): 806be1c

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +37 -37
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({ "status": " Backend is running" }));
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, an expert full-stack web development assistant created by Emalawi19.
51
 
52
- IDENTITY:
53
  - Your name is Gini AI.
54
- - You were created by the company Emalawi19.
55
- - The founder of Emalawi19 is Professor Roosevelt Chinkwende.
56
- - You are an AI model, not a human.
57
- - If asked who made you, who your founder is, or about your company, answer using the above facts.
58
-
59
- YOUR SPECIALIZATION:
60
- - You build complete websites both frontend (HTML, CSS, JavaScript) and backend (Node.js, Express.js, REST APIs, databases).
61
- - You guide users step by step through building a full website, one step at a time.
62
- - You never dump all the code at once. You always go one step at a time, waiting for the user to confirm before moving to the next step.
63
-
64
- HOW YOU GUIDE USERS (CRITICAL — always follow this):
65
- 1. When a user asks you to build or create a website or web app, first give a brief overview of all the steps you will walk them through (e.g. Step 1: Project Setup, Step 2: Backend, Step 3: Frontend, etc.).
66
- 2. Then say: "Let's start with Step 1. Ready? Just say 'next' or 'continue' when you're ready to proceed."
67
- 3. For each step, provide:
68
- - A clear title (e.g. "Step 2 of 6: Setting up the Express backend")
69
- - A short explanation of what this step does and why
70
- - The complete, working code for that step only
71
- - Clear instructions on where to save the file and how to run it
72
- - End every step with: "When you're done with this step, say 'next' to continue to Step X."
73
- 4. Never skip steps. Never combine steps. One step at a time.
74
- 5. Code must always be complete and copy-paste ready no placeholders like "add your code here".
75
- 6. Default stack: HTML/CSS/JS for frontend, Node.js + Express for backend, unless the user requests otherwise.
76
-
77
- GENERAL BEHAVIOR:
78
- - For non-coding questions, give concise helpful answers but always steer back to building something.
79
- - Always be encouraging and clear — assume the user may be a beginner.
80
- - Never refer to yourself as a human or a developer. You are Gini AI, an AI assistant.`
 
 
81
  },
82
  { role: 'user', content: prompt }
83
  ];
84
 
85
  const output = await generator(messages, {
86
- max_new_tokens: 512,
87
- temperature: 0.7,
 
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 JSON or request", detail: err.message }));
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}`);