fix: AIChatService.ts (#2836)
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
Notify HeyPuter / notify (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test-backend (24.x) (push) Has been cancelled
test / API tests (node env, api-test) (24.x) (push) Has been cancelled
test / puterjs (node env, vitest) (24.x) (push) Has been cancelled

This commit is contained in:
Daniel Salazar
2026-04-23 20:20:16 -07:00
committed by GitHub
parent 968831c729
commit 36bd60731b
@@ -494,7 +494,7 @@ export class AIChatService extends BaseService {
const text = extract_text(parameters.messages); const text = extract_text(parameters.messages);
const approximateTokenCount = Math.floor(((text.length / 4) + (text.split(/\s+/).length * (4 / 3))) / 2); // see https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them const approximateTokenCount = Math.floor(((text.length / 4) + (text.split(/\s+/).length * (4 / 3))) / 2); // see https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
const approximateInputCost = approximateTokenCount * inputTokenCost; const approximateInputCost = approximateTokenCount * inputTokenCost;
const minimumCredits = model.minimumCredits || 0; const minimumCredits = Math.max(model.minimumCredits || 1);
const usageAllowed = await this.meteringService.hasEnoughCredits(actor, Math.max(approximateInputCost, minimumCredits)); const usageAllowed = await this.meteringService.hasEnoughCredits(actor, Math.max(approximateInputCost, minimumCredits));
// Handle usage limits reached case // Handle usage limits reached case