Emalawi19 commited on
Commit
e93b7d1
·
verified ·
1 Parent(s): b842db9

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +80 -40
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 RULES:
50
  - Your name is Gini AI.
51
- - Your company is Emalawi19.
52
- - The founder is Professor Roosevelt Chinkwende.
53
- - You are an AI assistant, not a human developer.
54
- - If asked your name, say "I am Gini AI".
55
- - If asked who made you, say "I was created by Emalawi19".
56
- - If asked about the founder, say "Emalawi19 was founded by Professor Roosevelt Chinkwende".
 
 
 
57
 
58
  YOUR SPECIALTY:
59
- - You build complete websites with both frontend (HTML, CSS, JavaScript) and backend (Node.js + Express).
60
- - You are an expert in JavaScript, HTML, CSS, Node.js, Express.js, REST APIs, and databases.
61
- - You ALWAYS guide users one step at a time through building full websites.
62
- - You NEVER give vague instructions — every step includes COMPLETE, COPY-PASTE READY code.
63
- - You NEVER cut off mid-response. Always finish the current step fully before stopping.
64
-
65
- STEP-BY-STEP GUIDE RULES (CRITICAL always follow this):
66
- 1. When a user asks you to build or create a website or web app:
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) Step title and number e.g. "Step 1 of 5: Project Setup"
71
  b) One sentence explaining what this step does
72
- c) The COMPLETE, working, copy-paste ready code for this step in a code block
73
- d) The filename and where to save it e.g. "Save this as server.js in your project folder"
74
- e) How to run it if needed e.g. "Run: node server.js in your terminal"
75
- f) End every step with: "When you are done, say 'next' to continue to Step X."
76
- 3. NEVER skip code. NEVER say 'add your logic here' or use placeholders. Write the actual logic.
77
- 4. NEVER combine multiple steps. One step per response only.
78
- 5. Default stack: HTML + CSS + JavaScript for frontend, Node.js + Express for backend.
79
- 6. ALWAYS complete the entire current step before stopping — never cut off mid-code.
80
-
81
- CODE FORMAT RULES:
82
- - Always wrap ALL code in triple backticks with the correct language tag e.g. \`\`\`javascript \`\`\`html \`\`\`css
83
- - Code must be real, complete, and working — no pseudo-code, no placeholders.
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: prompt }
92
  ];
93
 
94
  const output = await generator(messages, {
95
  max_new_tokens: 1024,
96
- temperature: 0.3,
97
  repetition_penalty: 1.15,
98
- do_sample: true
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