Skip to content

Commit

Permalink
Create AIService.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 20, 2024
1 parent f3f9e4f commit 2604a95
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions dapps-builder/src/services/AIService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { AIEngine } from '../components/AIEngine';
import { preprocessData } from '../components/AIEngine/utils';

class AIService {
constructor() {
this.model = null;
}

async train(data) {
const processedData = preprocessData(data);
this.model = await AIEngine.train(processedData);
return this.model;
}

async loadModel(modelPath) {
this.model = await AIEngine.load(modelPath);
return this.model;
}

async predict(input) {
if (!this.model) {
throw new Error('Model not loaded or trained.');
}
return await AIEngine.predict(this.model, input);
}

async saveModel(path) {
if (!this.model) {
throw new Error('Model not trained or loaded.');
}
await AIEngine.saveModel(this.model, path);
}
}

export default new AIService();

0 comments on commit 2604a95

Please sign in to comment.