-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |