File size: 2,123 Bytes
a17163e | 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 |
/**
* 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;
|