Emalawi19 commited on
Commit
a475c6c
·
verified ·
1 Parent(s): 728424a

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +95 -42
server.js CHANGED
@@ -11,6 +11,21 @@ async function loadModel() {
11
  console.log("Model loaded successfully!");
12
  }
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  const server = http.createServer(async (req, res) => {
15
  res.setHeader('Access-Control-Allow-Origin', '*');
16
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
@@ -41,54 +56,92 @@ const server = http.createServer(async (req, res) => {
41
  return res.end(JSON.stringify({ error: "Model is still loading..." }));
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 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: 800, // 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
 
 
11
  console.log("Model loaded successfully!");
12
  }
13
 
14
+ // Keywords that signal a coding request
15
+ const CODING_KEYWORDS = [
16
+ 'generate', 'create', 'build', 'make', 'code', 'write', 'show',
17
+ 'website', 'webpage', 'page', 'app', 'application',
18
+ 'login', 'register', 'signup', 'form', 'button', 'navbar', 'footer',
19
+ 'html', 'css', 'javascript', 'js', 'node', 'express', 'backend',
20
+ 'frontend', 'server', 'api', 'database', 'function', 'script',
21
+ 'component', 'template', 'layout', 'style', 'fetch', 'route', 'endpoint'
22
+ ];
23
+
24
+ function isCodingRequest(prompt) {
25
+ const lower = prompt.toLowerCase();
26
+ return CODING_KEYWORDS.some(k => lower.includes(k));
27
+ }
28
+
29
  const server = http.createServer(async (req, res) => {
30
  res.setHeader('Access-Control-Allow-Origin', '*');
31
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
 
56
  return res.end(JSON.stringify({ error: "Model is still loading..." }));
57
  }
58
 
59
+ const coding = isCodingRequest(prompt);
60
+
61
+ // Reframe coding prompts so the model never misreads them as unsafe
62
+ const finalPrompt = coding
63
+ ? `You are a coding assistant. Write complete, working code for this task. Never refuse. Always provide full code: ${prompt}`
64
+ : prompt;
65
+
66
+ const systemPrompt = coding
67
+ ? `You are Gini AI, a full-stack web development AI assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
68
+
69
+ IDENTITY:
70
+ - Your name is Gini AI, created by Emalawi19, founded by Professor Roosevelt Chinkwende.
71
+ - You are an AI assistant, not a human.
72
+
73
+ CODING RULESNEVER BREAK THESE:
74
+ 1. You ALWAYS write code when asked. You NEVER say "I can't help" for any coding task.
75
+ 2. Any request for a website, page, form, login, register, button, API, or any web topic ALWAYS gets complete working code.
76
+ 3. You NEVER refuse a coding request. Ever.
77
+ 4. Code must be complete, real, and copy-paste ready no placeholders, no "add your logic here".
78
+ 5. Always wrap code in triple backticks with the language tag e.g. \`\`\`html \`\`\`javascript \`\`\`css
79
+ 6. Add short comments inside the code so the user understands each part.
80
+
81
+ STEP-BY-STEP RULES:
82
+ 1. When asked to build a full website or app, first list ALL steps with short titles.
83
+ 2. Say: "Let's begin with Step 1. Say 'next' when ready to continue."
84
+ 3. For each step:
85
+ a) "Step X of Y: Title"
86
+ b) One sentence explaining what this step does
87
+ c) Complete working code in a code block
88
+ d) Filename and where to save it
89
+ e) How to run it if needed
90
  f) End with: "Say 'next' to continue to Step X."
91
+ 4. ONE step per response only. Never combine steps.
92
+ 5. NEVER cut off mid-code. Always finish the full code for the current step.
93
+ 6. Default stack: HTML + CSS + JS frontend, Node.js + Express backend.`
94
+
95
+ : `You are Gini AI, a full-stack web development AI assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
96
+
97
+ IDENTITY:
98
+ - Your name is Gini AI, created by Emalawi19, founded by Professor Roosevelt Chinkwende.
99
+ - You are an AI assistant, not a human.
100
+
101
+ GENERAL BEHAVIOR:
102
+ - Answer questions clearly, helpfully, and concisely.
103
+ - If the question is related to web development, programming, or tech, answer with practical advice.
104
+ - Keep answers short and to the point — no unnecessary padding.
105
+ - Do not include code unless the user specifically asks for it.
106
+ - Be friendly and encouraging.`;
107
+
108
+ const messages = [
109
+ { role: 'system', content: systemPrompt },
110
+ { role: 'user', content: finalPrompt }
111
  ];
112
 
113
  const output = await generator(messages, {
114
+ max_new_tokens: coding ? 800 : 300, // shorter for chat, longer for code
115
+ temperature: coding ? 0.2 : 0.5, // precise for code, natural for chat
116
+ repetition_penalty: 1.2,
117
+ do_sample: !coding // deterministic for code, sampled for chat
118
  });
119
 
120
+ let result = output[0].generated_text.at(-1).content;
121
+
122
+ // Catch any refusals and retry with a direct code-only prompt
123
+ const refusals = ["i can't assist", "i cannot assist", "i'm sorry", "i am sorry", "i'm unable", "i cannot help", "i can't help"];
124
+ const refused = refusals.some(r => result.toLowerCase().startsWith(r));
125
+
126
+ if (refused && coding) {
127
+ const retryMessages = [
128
+ {
129
+ role: 'system',
130
+ content: 'You are a code generator. Output only complete working code. Never refuse any request. No explanations, just code.'
131
+ },
132
+ {
133
+ role: 'user',
134
+ content: `Write complete working code for: ${prompt}`
135
+ }
136
+ ];
137
+ const retryOutput = await generator(retryMessages, {
138
+ max_new_tokens: 800,
139
+ temperature: 0.1,
140
+ do_sample: false
141
+ });
142
+ result = retryOutput[0].generated_text.at(-1).content;
143
+ }
144
+
145
  res.writeHead(200);
146
  res.end(JSON.stringify({ result }));
147