Spaces:
Sleeping
Sleeping
File size: 1,828 Bytes
3a93fb9 18daf48 3a93fb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | const mlService = require('../services/mlService');
const dbService = require('../services/dbService');
const predict = async (req, res, next) => {
try {
const { text, sessionId } = req.body;
// Call FastAPI service
const predictionResult = await mlService.predict(text);
// Persist this prediction using Prisma
await dbService.savePrediction(sessionId, text, predictionResult);
// Return standardized response back to frontend
res.json(predictionResult);
} catch (error) {
next(error);
}
};
const getHistory = async (req, res, next) => {
try {
const { sessionId } = req.params;
const history = await dbService.getSessionHistory(sessionId);
res.json({ history });
} catch (error) {
next(error);
}
};
const getModels = async (req, res, next) => {
try {
const models = await mlService.getModels();
res.json(models);
} catch (error) {
next(error);
}
};
const getMetrics = async (req, res, next) => {
try {
const metrics = await dbService.getModelMetrics();
const serializedMetrics = metrics.map(m => ({
...m,
sizeBytes: m.sizeBytes.toString()
}));
res.json(serializedMetrics);
} catch (error) {
next(error);
}
};
const getHealth = async (req, res, next) => {
try {
const mlHealth = await mlService.getHealth();
res.json({
status: "healthy",
backend: true,
ml_service: !!mlHealth,
database: true,
models_loaded: mlHealth?.models_loaded || {
logistic_regression: false,
lstm: false,
bert: false
},
load_errors: mlHealth?.load_errors || {},
version: "1.0.0"
});
} catch (error) {
next(error);
}
};
module.exports = {
predict,
getHistory,
getModels,
getMetrics,
getHealth
};
|