zhlajiex
commited on
Commit
·
da1e4a6
1
Parent(s):
13c6122
Deployment: Complete Theme Sync and Gradio Core v3.0 with Zenith limits
Browse files- backend/controllers/ai.js +8 -7
- backend/server.js +6 -1
backend/controllers/ai.js
CHANGED
|
@@ -15,8 +15,8 @@ const MODELS = {
|
|
| 15 |
'Codex Fabrica': 'zai-glm-4.7',
|
| 16 |
'Codex Ratio': 'llama-3.3-70b',
|
| 17 |
'Codex Nexus': 'deepseek-v3.2',
|
| 18 |
-
'Codex Fero': 'Qwen/
|
| 19 |
-
'Codex Zenith': 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B'
|
| 20 |
};
|
| 21 |
|
| 22 |
const PROVIDERS = {
|
|
@@ -51,6 +51,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 51 |
const { message, sessionId, model } = req.body;
|
| 52 |
const user = req.user;
|
| 53 |
|
|
|
|
| 54 |
if (user.usage.requestsToday >= 150 && user.role !== 'owner') {
|
| 55 |
return next(new ErrorResponse('DAILY_PROTOCOL_LIMIT_EXCEEDED', 429));
|
| 56 |
}
|
|
@@ -66,7 +67,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 66 |
user.zenithUsage = {
|
| 67 |
lastUsedDate: today,
|
| 68 |
accessStartTime: now,
|
| 69 |
-
accessExpiryTime: new Date(now.getTime() + 20 * 60000)
|
| 70 |
};
|
| 71 |
await user.save();
|
| 72 |
} else {
|
|
@@ -87,7 +88,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 87 |
if (!session) {
|
| 88 |
session = await ChatSession.create({
|
| 89 |
userId: user._id,
|
| 90 |
-
title: message ? message.substring(0, 30) : "
|
| 91 |
model: activeModelName
|
| 92 |
});
|
| 93 |
}
|
|
@@ -108,7 +109,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 108 |
// 3. Build History
|
| 109 |
const history = await Message.find({ sessionId: session._id }).sort({ createdAt: 1 }).limit(10);
|
| 110 |
const availableModelsList = Object.keys(MODELS).join(', ');
|
| 111 |
-
const specialization = SPECIALIZATIONS[activeModelName];
|
| 112 |
|
| 113 |
const apiMessages = [
|
| 114 |
{
|
|
@@ -139,7 +140,7 @@ exports.chat = asyncHandler(async (req, res, next) => {
|
|
| 139 |
const hfToken = process.env.HF_TOKEN;
|
| 140 |
const client = await Client.connect(spaceName, { auth: hfToken });
|
| 141 |
|
| 142 |
-
const gradioModelName = activeModelName
|
| 143 |
|
| 144 |
const submission = client.submit("/chat", [
|
| 145 |
finalInput,
|
|
@@ -242,4 +243,4 @@ exports.clearHistory = asyncHandler(async (req, res, next) => {
|
|
| 242 |
await Message.deleteMany({ sessionId: { $in: sessionIds } });
|
| 243 |
await ChatSession.deleteMany({ userId: req.user.id });
|
| 244 |
res.status(200).json({ success: true, data: {} });
|
| 245 |
-
});
|
|
|
|
| 15 |
'Codex Fabrica': 'zai-glm-4.7',
|
| 16 |
'Codex Ratio': 'llama-3.3-70b',
|
| 17 |
'Codex Nexus': 'deepseek-v3.2',
|
| 18 |
+
'Codex Fero': 'Qwen/Qwen2.5-Coder-32B-Instruct', // Matched with aimodel
|
| 19 |
+
'Codex Zenith': 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B' // Matched with aimodel
|
| 20 |
};
|
| 21 |
|
| 22 |
const PROVIDERS = {
|
|
|
|
| 51 |
const { message, sessionId, model } = req.body;
|
| 52 |
const user = req.user;
|
| 53 |
|
| 54 |
+
// Global Daily Limit
|
| 55 |
if (user.usage.requestsToday >= 150 && user.role !== 'owner') {
|
| 56 |
return next(new ErrorResponse('DAILY_PROTOCOL_LIMIT_EXCEEDED', 429));
|
| 57 |
}
|
|
|
|
| 67 |
user.zenithUsage = {
|
| 68 |
lastUsedDate: today,
|
| 69 |
accessStartTime: now,
|
| 70 |
+
accessExpiryTime: new Date(now.getTime() + 20 * 60000)
|
| 71 |
};
|
| 72 |
await user.save();
|
| 73 |
} else {
|
|
|
|
| 88 |
if (!session) {
|
| 89 |
session = await ChatSession.create({
|
| 90 |
userId: user._id,
|
| 91 |
+
title: message ? message.substring(0, 30) : "New_Link_Established",
|
| 92 |
model: activeModelName
|
| 93 |
});
|
| 94 |
}
|
|
|
|
| 109 |
// 3. Build History
|
| 110 |
const history = await Message.find({ sessionId: session._id }).sort({ createdAt: 1 }).limit(10);
|
| 111 |
const availableModelsList = Object.keys(MODELS).join(', ');
|
| 112 |
+
const specialization = SPECIALIZATIONS[activeModelName] || SPECIALIZATIONS['Codex Velox'];
|
| 113 |
|
| 114 |
const apiMessages = [
|
| 115 |
{
|
|
|
|
| 140 |
const hfToken = process.env.HF_TOKEN;
|
| 141 |
const client = await Client.connect(spaceName, { auth: hfToken });
|
| 142 |
|
| 143 |
+
const gradioModelName = activeModelName; // 'Codex Fero' or 'Codex Zenith'
|
| 144 |
|
| 145 |
const submission = client.submit("/chat", [
|
| 146 |
finalInput,
|
|
|
|
| 243 |
await Message.deleteMany({ sessionId: { $in: sessionIds } });
|
| 244 |
await ChatSession.deleteMany({ userId: req.user.id });
|
| 245 |
res.status(200).json({ success: true, data: {} });
|
| 246 |
+
});
|
backend/server.js
CHANGED
|
@@ -131,7 +131,12 @@ app.post('/api/announcements', async (req, res) => {
|
|
| 131 |
const { message, startTime, endTime } = req.body;
|
| 132 |
// Verification: In a production build, we would use JWT.
|
| 133 |
// For now, we will allow the creation and let the frontend handle Architect-level auth.
|
| 134 |
-
const announcement = await Announcement.create({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
res.json({ success: true, data: announcement });
|
| 136 |
});
|
| 137 |
|
|
|
|
| 131 |
const { message, startTime, endTime } = req.body;
|
| 132 |
// Verification: In a production build, we would use JWT.
|
| 133 |
// For now, we will allow the creation and let the frontend handle Architect-level auth.
|
| 134 |
+
const announcement = await Announcement.create({
|
| 135 |
+
message,
|
| 136 |
+
startTime: new Date(startTime),
|
| 137 |
+
endTime: new Date(endTime),
|
| 138 |
+
isActive: true
|
| 139 |
+
});
|
| 140 |
res.json({ success: true, data: announcement });
|
| 141 |
});
|
| 142 |
|