From 2604a951186dec155d6211ffc346187c939e946e Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 20 Nov 2024 19:27:29 +0700 Subject: [PATCH] Create AIService.js --- dapps-builder/src/services/AIService.js | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dapps-builder/src/services/AIService.js diff --git a/dapps-builder/src/services/AIService.js b/dapps-builder/src/services/AIService.js new file mode 100644 index 000000000..1b0e519df --- /dev/null +++ b/dapps-builder/src/services/AIService.js @@ -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();