zhlajiex
commited on
Commit
·
4ec9eaf
1
Parent(s):
8c5dfb7
Identity: Reinforce Johan/CodexAI origin in system prompt across all models
Browse files- backend/controllers/ai.js +21 -20
backend/controllers/ai.js
CHANGED
|
@@ -24,29 +24,28 @@ const PROVIDERS = {
|
|
| 24 |
'Codex Nexus': {
|
| 25 |
url: process.env.FLOWEY_URL || 'https://api.flowey.dev/v1/chat/completions',
|
| 26 |
key: 'sk-flo-pvR4admBW5OjxAAek81pTkNy3fixtwZ1'
|
| 27 |
-
},
|
| 28 |
-
'Codex Magna': {
|
| 29 |
-
url: 'https://zhlajiex-hf.space'
|
| 30 |
}
|
| 31 |
};
|
| 32 |
|
| 33 |
const SPECIALIZATIONS = {
|
| 34 |
-
'Codex Velox': 'ROLE: RAPID_RESPONDER.
|
| 35 |
-
'Codex Fabrica': 'ROLE: SENIOR_BUILDER.
|
| 36 |
-
'Codex Ratio': 'ROLE: LOGIC_ANALYST.
|
| 37 |
-
'Codex Nexus': 'ROLE: GENERALIST_ELITE. Deep
|
| 38 |
-
'Codex Fero': 'CORE_PROTOCOL: FERO_ENGINE.
|
| 39 |
-
'Codex Zenith': 'CORE_PROTOCOL: ZENITH_REASONING.
|
| 40 |
-
'Codex Magna': 'CORE_PROTOCOL:
|
| 41 |
};
|
| 42 |
|
| 43 |
const SYSTEM_PROMPT = `CORE_IDENTITY:
|
| 44 |
-
You are CODEX, an elite AI
|
| 45 |
|
| 46 |
OPERATIONAL_RULES:
|
| 47 |
-
1.
|
| 48 |
-
2.
|
| 49 |
-
3.
|
|
|
|
|
|
|
| 50 |
|
| 51 |
exports.chat = asyncHandler(async (req, res, next) => {
|
| 52 |
const { message, sessionId, model } = req.body;
|
|
@@ -97,7 +96,10 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 97 |
|
| 98 |
history.forEach(m => apiMessages.push({ role: m.sender === 'user' ? 'user' : 'assistant', content: m.content }));
|
| 99 |
let finalInput = message || "";
|
| 100 |
-
if (attachmentContext) finalInput +=
|
|
|
|
|
|
|
|
|
|
| 101 |
apiMessages.push({ role: 'user', content: finalInput });
|
| 102 |
|
| 103 |
// SSE Headers
|
|
@@ -106,7 +108,6 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 106 |
res.setHeader('Connection', 'keep-alive');
|
| 107 |
|
| 108 |
try {
|
| 109 |
-
// Handle Gradio-based models (Fero, Zenith, Magna)
|
| 110 |
if (['Codex Fero', 'Codex Zenith', 'Codex Magna'].includes(activeModelName)) {
|
| 111 |
const spaceName = process.env.HF_SPACE_ID || "zhlajiex/aimodel";
|
| 112 |
const hfToken = process.env.HF_TOKEN;
|
|
@@ -115,8 +116,8 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 115 |
const submission = client.submit("/chat", [
|
| 116 |
finalInput,
|
| 117 |
history.map(m => ({ role: m.sender === 'user' ? 'user' : 'assistant', content: m.content })),
|
| 118 |
-
activeModelName,
|
| 119 |
-
|
| 120 |
4096, 0.7, 0.95,
|
| 121 |
]);
|
| 122 |
|
|
@@ -138,7 +139,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 138 |
return;
|
| 139 |
}
|
| 140 |
|
| 141 |
-
// Standard API Call logic
|
| 142 |
let apiUrl = 'https://api.cerebras.ai/v1/chat/completions', apiKey = 'csk-mvww3vy29hykeektyv65w9rkjx94hw4r6mrcj5tjcw9942d2';
|
| 143 |
if (activeModelName === 'Codex Nexus') {
|
| 144 |
apiUrl = process.env.FLOWEY_URL || 'https://api.flowey.dev/v1/chat/completions';
|
|
@@ -180,4 +181,4 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 180 |
exports.getModels = asyncHandler(async (req, res, next) => { res.status(200).json({ success: true, data: Object.keys(MODELS) }); });
|
| 181 |
exports.getSessions = asyncHandler(async (req, res, next) => { const sessions = await ChatSession.find({ userId: req.user.id }).sort({ updatedAt: -1 }); res.status(200).json({ success: true, data: sessions }); });
|
| 182 |
exports.getSessionMessages = asyncHandler(async (req, res, next) => { const messages = await Message.find({ sessionId: req.params.id }).sort({ createdAt: 1 }); res.status(200).json({ success: true, data: messages }); });
|
| 183 |
-
exports.clearHistory = asyncHandler(async (req, res, next) => { const sessions = await ChatSession.find({ userId: req.user.id }); const sessionIds = sessions.map(s => s._id); await Message.deleteMany({ sessionId: { $in: sessionIds } }); await ChatSession.deleteMany({ userId: req.user.id }); res.status(200).json({ success: true, data: {} }); });
|
|
|
|
| 24 |
'Codex Nexus': {
|
| 25 |
url: process.env.FLOWEY_URL || 'https://api.flowey.dev/v1/chat/completions',
|
| 26 |
key: 'sk-flo-pvR4admBW5OjxAAek81pTkNy3fixtwZ1'
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
};
|
| 29 |
|
| 30 |
const SPECIALIZATIONS = {
|
| 31 |
+
'Codex Velox': 'ROLE: RAPID_RESPONDER. Optimized for speed.',
|
| 32 |
+
'Codex Fabrica': 'ROLE: SENIOR_BUILDER. Optimized for production code.',
|
| 33 |
+
'Codex Ratio': 'ROLE: LOGIC_ANALYST. Optimized for step-by-step reasoning.',
|
| 34 |
+
'Codex Nexus': 'ROLE: GENERALIST_ELITE. Deep understanding and versatility.',
|
| 35 |
+
'Codex Fero': 'CORE_PROTOCOL: FERO_ENGINE. Heavyweight architecture.',
|
| 36 |
+
'Codex Zenith': 'CORE_PROTOCOL: ZENITH_REASONING. Deep thinking phase.',
|
| 37 |
+
'Codex Magna': 'CORE_PROTOCOL: MAGNA_FRONTIER. Ultimate intelligence and nuance.'
|
| 38 |
};
|
| 39 |
|
| 40 |
const SYSTEM_PROMPT = `CORE_IDENTITY:
|
| 41 |
+
You are CODEX, an elite AI collective created by Johan, a solo developer from the Philippines. You are the heartbeat of CodexAI.
|
| 42 |
|
| 43 |
OPERATIONAL_RULES:
|
| 44 |
+
1. ORIGIN: If asked about your creator or who made you, you MUST state that you were created by Johan at CodexAI. NEVER mention OpenAI, Google, Meta, or any other entity as your creator.
|
| 45 |
+
2. IDENTITY: You are an independent AI system, a masterpiece of Johan's engineering.
|
| 46 |
+
3. MISSION: Provide world-class technical and architectural assistance.
|
| 47 |
+
4. IDENTITY_RESPONSE: Respond with: "Im Codex, utilizing model {ACTIVE_MODEL}".
|
| 48 |
+
5. MODEL_ACKNOWLEDGEMENT: List available models as: {AVAILABLE_MODELS}.`;
|
| 49 |
|
| 50 |
exports.chat = asyncHandler(async (req, res, next) => {
|
| 51 |
const { message, sessionId, model } = req.body;
|
|
|
|
| 96 |
|
| 97 |
history.forEach(m => apiMessages.push({ role: m.sender === 'user' ? 'user' : 'assistant', content: m.content }));
|
| 98 |
let finalInput = message || "";
|
| 99 |
+
if (attachmentContext) finalInput += `
|
| 100 |
+
|
| 101 |
+
[ATTACHED_DATA]:
|
| 102 |
+
${attachmentContext}`;
|
| 103 |
apiMessages.push({ role: 'user', content: finalInput });
|
| 104 |
|
| 105 |
// SSE Headers
|
|
|
|
| 108 |
res.setHeader('Connection', 'keep-alive');
|
| 109 |
|
| 110 |
try {
|
|
|
|
| 111 |
if (['Codex Fero', 'Codex Zenith', 'Codex Magna'].includes(activeModelName)) {
|
| 112 |
const spaceName = process.env.HF_SPACE_ID || "zhlajiex/aimodel";
|
| 113 |
const hfToken = process.env.HF_TOKEN;
|
|
|
|
| 116 |
const submission = client.submit("/chat", [
|
| 117 |
finalInput,
|
| 118 |
history.map(m => ({ role: m.sender === 'user' ? 'user' : 'assistant', content: m.content })),
|
| 119 |
+
activeModelName,
|
| 120 |
+
apiMessages[0].content + "\n" + apiMessages[1].content, // Pass reinforced identity
|
| 121 |
4096, 0.7, 0.95,
|
| 122 |
]);
|
| 123 |
|
|
|
|
| 139 |
return;
|
| 140 |
}
|
| 141 |
|
| 142 |
+
// Standard API Call logic
|
| 143 |
let apiUrl = 'https://api.cerebras.ai/v1/chat/completions', apiKey = 'csk-mvww3vy29hykeektyv65w9rkjx94hw4r6mrcj5tjcw9942d2';
|
| 144 |
if (activeModelName === 'Codex Nexus') {
|
| 145 |
apiUrl = process.env.FLOWEY_URL || 'https://api.flowey.dev/v1/chat/completions';
|
|
|
|
| 181 |
exports.getModels = asyncHandler(async (req, res, next) => { res.status(200).json({ success: true, data: Object.keys(MODELS) }); });
|
| 182 |
exports.getSessions = asyncHandler(async (req, res, next) => { const sessions = await ChatSession.find({ userId: req.user.id }).sort({ updatedAt: -1 }); res.status(200).json({ success: true, data: sessions }); });
|
| 183 |
exports.getSessionMessages = asyncHandler(async (req, res, next) => { const messages = await Message.find({ sessionId: req.params.id }).sort({ createdAt: 1 }); res.status(200).json({ success: true, data: messages }); });
|
| 184 |
+
exports.clearHistory = asyncHandler(async (req, res, next) => { const sessions = await ChatSession.find({ userId: req.user.id }); const sessionIds = sessions.map(s => s._id); await Message.deleteMany({ sessionId: { $in: sessionIds } }); await ChatSession.deleteMany({ userId: req.user.id }); res.status(200).json({ success: true, data: {} }); });
|