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 2 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
65 changes: 65 additions & 0 deletions src/controllers/modelController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export default class ModelController {
private static instance: ModelController | undefined;
constructor() {
if(ModelController.instance) return ModelController.instance;
ModelController.instance = this;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫 생성 시에 this가 정상적으로 할당될 수 있는지 잘 모르겠습니다.
static인 instance는 constructor로 초기화하지 않고 static getInstance() 함수를 통해서 받아올 수 있도록 할 수 있을 것 같습니다.

class ModelController {
  private static instance: ModelController;
  static getInstance() {
    if (!ModelController.instance)
      ModelController.instance = new ModelContoller();
    return ModelController.instance;
  }
  ...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우에 instance는 ModelController.getInstance() 로 가져올 수 있습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 좋은 것 같습니다.
수정했습니다.

}

//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 = new ModelController();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 방식으로 호출하면 ModelController 안에 instance가 없어도 될 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new를 하면 modelController에서 instance를 넘깁니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modelController의 constructor에서 instance가 이미 생성되었다면, if를 통해 instance를 넘깁니다.

}
//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;
}
}