Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modelSkeleton #38

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DepositService from "./modules/service/depositService";
import UseService from "./modules/service/useService";
import Service from "./modules/service";
import Admin from "./modules/admin";
import Model from "./model";
export default class Ainize {
private cache: NodeCache;
ain: Ain;
Expand All @@ -33,6 +34,9 @@ export default class Ainize {
this.admin = new Admin(this, depositService, useService);
}

model(modelName: string) {
return new Model(modelName);
}
test() {
console.log("test");
}
Expand Down
67 changes: 67 additions & 0 deletions src/controllers/modelController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export default class ModelController {
private static instance: ModelController | undefined;
static getInstance() {
if(!ModelController.instance){
ModelController.instance = new ModelController();
}
return ModelController.instance;
}

//TODO(woojae): implement this
async isRunning(modelName: string) {
return await true;
}

//TODO(woojae): implement this
async getInformation(modelName: string) {
return await true;
}

//TODO(woojae): implement this
async calculateCost(modelName: string, requestData: string) {
return await 0.3;
}

//TODO(woojae): implement this
async chargeCredit(modelName: string, amount: number) {
return await true;
}

//TODO(woojae): implement this
async withdrawCredit(modelName: string, amount: number) {
return await true;
}

//TODO(woojae): implement this
async getCreditBalance(modelName: string) {
return await 0.3;
}

//TODO(woojae): implement this
async getCreditHistory(modelName: string) {
return await true;
}

//TODO(woojae): implement this
async use(modelName: string, requestData: string) {
return await true;
}

//TODO(woojae): implement this
//NOTE(woojae): need admin
async run(modelName: string) {
return await true;
}

//TODO(woojae): implement this
//NOTE:(woojae): need admin
async stop(modelName: string) {
return await true;
}

//TODO:(woojae): implement this
//NOTE:(woojae): need admin
async changeModelInfo(modelName: string, config: any) {
return await true;
}
}
68 changes: 68 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import ModelController from "./controllers/modelController";

export default class Model {
modelName: string;
modelController: ModelController;

constructor(modelName: string) {
this.modelName = modelName;
this.modelController = ModelController.getInstance();
}
//TODO(woojae): login not Required
async isRunning() {
return await this.modelController.isRunning(this.modelName);
}

//TODO(woojae): login not Required
async getInformation() {
return await this.modelController.getInformation(this.modelName);
}

//TODO(woojae): login not Required
async calculateCost (requestData: string) {
return await this.modelController.calculateCost(this.modelName, requestData);
}

async chargeCredit(amount: number) {
return await this.modelController.chargeCredit(this.modelName, amount);
}

async withdrawCredit(amount: number) {
return await this.modelController.withdrawCredit(this.modelName, amount);
}

async getCreditBalance() {
return await this.modelController.getCreditBalance(this.modelName);
}

async getCreditHistory() {
return await this.modelController.getCreditHistory(this.modelName);
}

async use(requestData: string) {
return await this.modelController.use(this.modelName, requestData);
}

//NOTE(woojae): need admin
async run() {
await this.isAdmin();
return await this.modelController.run(this.modelName);
}

//NOTE(woojae): need admin
async stop() {
await this.isAdmin();
return await this.modelController.stop(this.modelName);
}

//NOTE(woojae): need admin
async changeModelInfo(config: any) {
await this.isAdmin();
return await this.modelController.changeModelInfo(this.modelName, config);
}

//TODO(woojae): implement this
private async isAdmin() {
return true;
}
}