ai-utils.js
Version:
Build AI applications, chatbots, and agents with JavaScript and TypeScript.
35 lines (34 loc) • 1.08 kB
JavaScript
export class Cost {
constructor({ costInMillicents, hasUnknownCost, callsWithUnknownCost, }) {
Object.defineProperty(this, "costInMillicents", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "hasUnknownCost", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "callsWithUnknownCost", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.costInMillicents = costInMillicents;
this.hasUnknownCost = hasUnknownCost;
this.callsWithUnknownCost = callsWithUnknownCost;
}
get costInCent() {
return this.costInMillicents / 1000;
}
get costInDollar() {
return this.costInCent / 100;
}
formatAsDollarAmount({ decimals = 2 } = {}) {
return `$${this.costInDollar.toFixed(decimals)}`;
}
}