cyberforge-models / ml_client.js
Che237's picture
Update CyberForge ML models and deployment artifacts
a17163e verified
/**
* CyberForge ML Client
* Integration with mlService.js
*/
const axios = require('axios');
class CyberForgeMLClient {
constructor(baseUrl = 'http://localhost:8001') {
this.baseUrl = baseUrl;
this.client = axios.create({
baseURL: baseUrl,
timeout: 5000,
headers: { 'Content-Type': 'application/json' }
});
}
/**
* Get prediction from ML model
* @param {string} modelName - Name of the model
* @param {Object} features - Feature dictionary
* @returns {Promise<Object>} Prediction result
*/
async predict(modelName, features) {
try {
const response = await this.client.post('/predict', {
model_name: modelName,
features: features
});
return response.data;
} catch (error) {
console.error('ML prediction error:', error.message);
throw error;
}
}
/**
* Analyze website for threats
* @param {string} url - URL to analyze
* @param {Object} scrapedData - Data from WebScraperAPIService
* @returns {Promise<Object>} Threat analysis result
*/
async analyzeWebsite(url, scrapedData) {
try {
const response = await this.client.post('/analyze', {
url: url,
data: scrapedData
});
return response.data;
} catch (error) {
console.error('Website analysis error:', error.message);
throw error;
}
}
/**
* List available models
* @returns {Promise<Array>} List of model names
*/
async listModels() {
const response = await this.client.get('/models');
return response.data.models;
}
/**
* Get model information
* @param {string} modelName - Name of the model
* @returns {Promise<Object>} Model metadata
*/
async getModelInfo(modelName) {
const response = await this.client.get(`/models/${modelName}`);
return response.data;
}
}
module.exports = CyberForgeMLClient;