Skip to content

Commit 4d2ead6

Browse files
committed
fix: do Math.ceil to have only integers in the token counts
1 parent 400fc43 commit 4d2ead6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/api/providers/base-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export abstract class BaseProvider implements ApiHandler {
9797
return apiCount
9898
} catch (error) {
9999
const localEstimate = await localCountTokens(content, { useWorker: true })
100-
return localEstimate
100+
return Math.ceil(localEstimate * this.tokenComparator.getSafetyFactor())
101101
}
102102
}
103103

@@ -106,7 +106,7 @@ export abstract class BaseProvider implements ApiHandler {
106106
const { info } = this.getModel()
107107
const contextWindow = info.contextWindow
108108
const allowedTokens = getAllowedTokens(contextWindow, options.maxTokens)
109-
const projectedTokens = options.totalTokens + localEstimate * this.tokenComparator.getSafetyFactor()
109+
const projectedTokens = options.totalTokens + Math.ceil(localEstimate * this.tokenComparator.getSafetyFactor())
110110

111111
// Checking if we're at 90% of effective threshold for earlier API-based counting
112112
const effectiveThreshold = options.effectiveThreshold ?? 100
@@ -131,6 +131,6 @@ export abstract class BaseProvider implements ApiHandler {
131131
}
132132
}
133133

134-
return localEstimate
134+
return Math.ceil(localEstimate * this.tokenComparator.getSafetyFactor())
135135
}
136136
}

0 commit comments

Comments
 (0)