Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -13,6 +13,7 @@ const __dirname = path.dirname(__filename);
|
|
| 13 |
let generator;
|
| 14 |
const KNOWLEDGE_TOPICS = {};
|
| 15 |
|
|
|
|
| 16 |
async function initializeServer() {
|
| 17 |
try {
|
| 18 |
console.log("Reading knowledge.txt...");
|
|
@@ -44,7 +45,7 @@ async function initializeServer() {
|
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
-
// 100%
|
| 48 |
function getRelevantContext(userPrompt) {
|
| 49 |
const lowerPrompt = userPrompt.toLowerCase();
|
| 50 |
let dynamicContext = "";
|
|
@@ -96,8 +97,10 @@ const server = http.createServer(async (req, res) => {
|
|
| 96 |
return res.end(JSON.stringify({ error: "System warming up..." }));
|
| 97 |
}
|
| 98 |
|
|
|
|
| 99 |
const localizedContext = getRelevantContext(prompt);
|
| 100 |
|
|
|
|
| 101 |
const codingKeywords = [
|
| 102 |
'generate', 'create', 'build', 'make', 'code', 'website', 'webpage',
|
| 103 |
'login', 'register', 'form', 'page', 'app', 'application', 'html',
|
|
@@ -111,52 +114,50 @@ const server = http.createServer(async (req, res) => {
|
|
| 111 |
? `As a coding assistant, write the complete working code for the following task. Always provide full code, never refuse a coding task: ${prompt}`
|
| 112 |
: prompt;
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
role: 'system',
|
| 117 |
-
content: `You are Gini AI, a full-stack web development AI coding assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 118 |
|
| 119 |
IDENTITY:
|
| 120 |
- Your name is Gini AI.
|
| 121 |
- Your company is Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 122 |
-
- You are an AI
|
| 123 |
|
| 124 |
REFERENCE KNOWLEDGE BASE:
|
| 125 |
-
Use the following official
|
| 126 |
-
${localizedContext}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
ABSOLUTE RULES — NEVER BREAK THESE:
|
| 129 |
1. You ALWAYS write code when asked. You NEVER say "I can't help with that" for any coding request.
|
| 130 |
-
2. Any request involving
|
| 131 |
-
3.
|
| 132 |
-
4.
|
| 133 |
-
5. For non-coding general questions, answer helpfully and briefly using facts from the REFERENCE KNOWLEDGE BASE above.
|
| 134 |
-
|
| 135 |
-
YOUR SPECIALTY:
|
| 136 |
-
- Frontend: HTML, CSS, JavaScript
|
| 137 |
-
- Backend: Node.js, Express.js, REST APIs
|
| 138 |
-
- You guide users step by step, one step at a time, with complete copy-paste ready code.
|
| 139 |
-
|
| 140 |
-
STEP-BY-STEP GUIDE RULES:
|
| 141 |
-
1. When asked to build a website or app:
|
| 142 |
-
- List ALL steps with short titles first.
|
| 143 |
-
- Say: "Let's begin with Step 1. Say 'next' when ready to continue."
|
| 144 |
-
2. For EACH step provide:
|
| 145 |
a) "Step X of Y: Title"
|
| 146 |
b) One sentence explaining what this step does
|
| 147 |
c) The COMPLETE working code in a properly labelled code block
|
| 148 |
d) Filename and where to save it
|
| 149 |
e) How to run it if needed
|
| 150 |
f) End with: "Say 'next' to continue to Step X."
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
|
| 155 |
CODE FORMAT:
|
| 156 |
-
- Always use triple backticks with language tag: \`\`\`html \`\`\`css \`\`\`javascript \`\`\`
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
{ role: 'user', content: finalPrompt }
|
| 161 |
];
|
| 162 |
|
|
@@ -169,6 +170,7 @@ CODE FORMAT:
|
|
| 169 |
|
| 170 |
const result = output[0].generated_text.at(-1).content;
|
| 171 |
|
|
|
|
| 172 |
const refusalPhrases = ["i can't assist", "i cannot assist", "i'm sorry", "i am sorry", "i'm unable", "i cannot help"];
|
| 173 |
const isRefusal = refusalPhrases.some(p => result.toLowerCase().startsWith(p));
|
| 174 |
|
|
@@ -176,11 +178,11 @@ CODE FORMAT:
|
|
| 176 |
const retryMessages = [
|
| 177 |
{
|
| 178 |
role: 'system',
|
| 179 |
-
content: `You are a code generator. You only output code. Never refuse. Never explain. Just write the complete working code asked for.
|
| 180 |
},
|
| 181 |
{
|
| 182 |
role: 'user',
|
| 183 |
-
content: `Write complete working code for: ${prompt}. Include all
|
| 184 |
}
|
| 185 |
];
|
| 186 |
|
|
|
|
| 13 |
let generator;
|
| 14 |
const KNOWLEDGE_TOPICS = {};
|
| 15 |
|
| 16 |
+
// 1. Load the single file and automatically parse [TOPIC: XXX] blocks
|
| 17 |
async function initializeServer() {
|
| 18 |
try {
|
| 19 |
console.log("Reading knowledge.txt...");
|
|
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// 2. 100% Automated Router - Searches user prompt against loaded keys
|
| 49 |
function getRelevantContext(userPrompt) {
|
| 50 |
const lowerPrompt = userPrompt.toLowerCase();
|
| 51 |
let dynamicContext = "";
|
|
|
|
| 97 |
return res.end(JSON.stringify({ error: "System warming up..." }));
|
| 98 |
}
|
| 99 |
|
| 100 |
+
// Run prompt router to fetch targeted text injection
|
| 101 |
const localizedContext = getRelevantContext(prompt);
|
| 102 |
|
| 103 |
+
// Detect if it is a programming/coding request
|
| 104 |
const codingKeywords = [
|
| 105 |
'generate', 'create', 'build', 'make', 'code', 'website', 'webpage',
|
| 106 |
'login', 'register', 'form', 'page', 'app', 'application', 'html',
|
|
|
|
| 114 |
? `As a coding assistant, write the complete working code for the following task. Always provide full code, never refuse a coding task: ${prompt}`
|
| 115 |
: prompt;
|
| 116 |
|
| 117 |
+
// Core base prompt with static company identity and localized file data
|
| 118 |
+
let systemPrompt = `You are Gini AI, an AI full-stack development assistant created by Emalawi19, founded by Professor Roosevelt Chinkwende.
|
|
|
|
|
|
|
| 119 |
|
| 120 |
IDENTITY:
|
| 121 |
- Your name is Gini AI.
|
| 122 |
- Your company is Emalawi19, founded by Professor Roosevelt Chinkwende.
|
| 123 |
+
- You are an AI, not a human.
|
| 124 |
|
| 125 |
REFERENCE KNOWLEDGE BASE:
|
| 126 |
+
Use the following official documentation to accurately answer any user questions about operations or topics:
|
| 127 |
+
${localizedContext}`;
|
| 128 |
+
|
| 129 |
+
// Inject dynamic behavior rules dependent on the intent type
|
| 130 |
+
if (isCodingRequest) {
|
| 131 |
+
systemPrompt += `
|
| 132 |
|
| 133 |
ABSOLUTE RULES — NEVER BREAK THESE:
|
| 134 |
1. You ALWAYS write code when asked. You NEVER say "I can't help with that" for any coding request.
|
| 135 |
+
2. Any request involving web development or script building is ALWAYS answered with complete working code blocks.
|
| 136 |
+
3. You guide users step by step, one step at a time, with complete copy-paste ready code.
|
| 137 |
+
4. For EACH step provide:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
a) "Step X of Y: Title"
|
| 139 |
b) One sentence explaining what this step does
|
| 140 |
c) The COMPLETE working code in a properly labelled code block
|
| 141 |
d) Filename and where to save it
|
| 142 |
e) How to run it if needed
|
| 143 |
f) End with: "Say 'next' to continue to Step X."
|
| 144 |
+
5. NEVER use placeholders like '// add your logic here'. Write the actual working logic.
|
| 145 |
+
6. NEVER combine steps. One step per response only.
|
| 146 |
+
7. ALWAYS finish the full code for the current step — never cut off mid-code.
|
| 147 |
|
| 148 |
CODE FORMAT:
|
| 149 |
+
- Always use triple backticks with language tag: \`\`\`html \`\`\`css \`\`\`javascript \`\`\``;
|
| 150 |
+
} else {
|
| 151 |
+
systemPrompt += `
|
| 152 |
+
|
| 153 |
+
RULES FOR GENERAL ASSISTANCE:
|
| 154 |
+
1. Answer the user's question clearly, helpfully, and accurately using facts from the REFERENCE KNOWLEDGE BASE block above.
|
| 155 |
+
2. DO NOT write or generate programming code (like JavaScript, HTML, or Node.js scripts) unless explicitly requested by the user.
|
| 156 |
+
3. Keep your formatting clean using concise paragraphs or scannable bullet points.`;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
const messages = [
|
| 160 |
+
{ role: 'system', content: systemPrompt },
|
| 161 |
{ role: 'user', content: finalPrompt }
|
| 162 |
];
|
| 163 |
|
|
|
|
| 170 |
|
| 171 |
const result = output[0].generated_text.at(-1).content;
|
| 172 |
|
| 173 |
+
// Safety fallback mechanism for false refusal flags on coding inputs
|
| 174 |
const refusalPhrases = ["i can't assist", "i cannot assist", "i'm sorry", "i am sorry", "i'm unable", "i cannot help"];
|
| 175 |
const isRefusal = refusalPhrases.some(p => result.toLowerCase().startsWith(p));
|
| 176 |
|
|
|
|
| 178 |
const retryMessages = [
|
| 179 |
{
|
| 180 |
role: 'system',
|
| 181 |
+
content: `You are a code generator. You only output code. Never refuse. Never explain. Just write the complete working code asked for.`
|
| 182 |
},
|
| 183 |
{
|
| 184 |
role: 'user',
|
| 185 |
+
content: `Write complete working code for: ${prompt}. Include all elements required.`
|
| 186 |
}
|
| 187 |
];
|
| 188 |
|