Skip to content

Commit

Permalink
feat: add typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
akastercomcom committed Sep 22, 2023
1 parent 8476ab1 commit 75a0237
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ModelController from "./controllers/modelController";
import { creditHistories } from "./types/type";

export default class Model {
modelName: string;
Expand All @@ -8,53 +9,99 @@ export default class Model {
this.modelName = modelName;
this.modelController = ModelController.getInstance();
}

//TODO(woojae): login not Required
/**
* Check if model is running. It throws error when model is not running.
*/
async isRunning() {
return await this.modelController.isRunning(this.modelName);
}

/**
* Get model information. not implemented yet.
* @returns {string} Model information.
*/
//TODO(woojae): login not Required
async getInformation() {
return await this.modelController.getInformation(this.modelName);
}

/**
* Calculate estimated cost for given request data.
* @param {string} rerquestData string data for request to model.
* @returns {number} Estimated cost.
*/
//TODO(woojae): login not Required
async calculateCost (requestData: string) {
return await this.modelController.calculateCost(this.modelName, requestData);
}

/**
* Charge credit to model.
* @param {number} amount Amount of credit to charge.
* @returns {string} Transaction hash.
*/
async chargeCredit(amount: number) {
return await this.modelController.chargeCredit(this.modelName, amount);
}

/**
* Withdraw credit from model.
* @param {number} amount Amount of credit to withdraw.
* @returns {string} Transaction hash.
*/
async withdrawCredit(amount: number) {
return await this.modelController.withdrawCredit(this.modelName, amount);
}

/**
* Get credit balance of model.
* @returns {number} Amount of credit balance.
*/
async getCreditBalance() {
return await this.modelController.getCreditBalance(this.modelName);
}

/**
* Get credit history of model.
* @returns {creditHistories} Histories of credit deposit and usage.
*/
async getCreditHistory() {
return await this.modelController.getCreditHistory(this.modelName);
}

/**
* Use model with given request data.
* @param {string} requestData String data for request to model.
* @returns {string} Response data from model.
*/
async use(requestData: string) {
return await this.modelController.use(this.modelName, requestData);
}

/**
* Change status of AI model container to Running. Need to be admin. Not implemented yet.
*/
//NOTE(woojae): need admin
async run() {
await this.isAdmin();
return await this.modelController.run(this.modelName);
}

/**
* Change status of AI model container to Stopped. Need to be admin. Not implemented yet.
*/
//NOTE(woojae): need admin
async stop() {
await this.isAdmin();
return await this.modelController.stop(this.modelName);
}

/**
* Change model configuration. Need to be admin. Not implemented yet.
* @param {any} config Configuration to change. Not implemented yet.
*/
//NOTE(woojae): need admin
async changeModelInfo(config: any) {
await this.isAdmin();
Expand Down
11 changes: 11 additions & 0 deletions src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export enum HISTORY_TYPE {
USAGE = "USAGE",
}

export type creditHistories = {
[timestamp: string]: creditHistory;
}

export type creditHistory = {
type: HISTORY_TYPE;
amount: number;
transferKey?: string;
requestTimestamp?: string;
}

export type opResult = {
code: number;
bandwidth_gas_amount: number;
Expand Down

0 comments on commit 75a0237

Please sign in to comment.