Skip to content

Commit

Permalink
modelController
Browse files Browse the repository at this point in the history
  • Loading branch information
akastercomcom committed Sep 19, 2023
1 parent 48672b2 commit 9734673
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/controllers/modelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ export default class ModelController {

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

//TODO(woojae): implement this
async calculateCost(modelName: string, requestData: string) {
return await 0.3;
const billingConfig = await this.ain.getValue(Path.app(modelName).billingConfig());
const token = requestData.split(' ').length;
let cost = token * billingConfig.costPerToken;
if (billingConfig.minCost && cost < billingConfig.minCost) {
cost = billingConfig.minCost;
} else if (billingConfig.maxCost && cost > billingConfig.maxCost) {
cost = billingConfig.maxCost;
}
return cost;
}

async chargeCredit(modelName: string, amount: number) {
Expand All @@ -49,14 +56,18 @@ export default class ModelController {
return await true;
}

//TODO(woojae): implement this
async getCreditBalance(modelName: string) {
return await 0.3;
this.isLoggedIn();
const userAddress = this.ain.getDefaultAccount()!.address;
const balancePath = Path.app(modelName).balanceOfUser(userAddress);
return await this.ain.getValue(balancePath);
}

//TODO(woojae): implement this
async getCreditHistory(modelName: string) {
return await true;
this.isLoggedIn();
const userAddress = this.ain.getDefaultAccount()!.address;
const creditHistoryPath = Path.app(modelName).historyOfUser(userAddress);
return await this.ain.getValue(creditHistoryPath);
}

//TODO(woojae): connect with handler
Expand Down

0 comments on commit 9734673

Please sign in to comment.