File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,8 @@ export abstract class BaseProvider implements ApiHandler {
8787 return 0
8888 }
8989
90+ // First three requests, we will be using APi-based token counting to have a good start
91+ // and estimate the accuracy by collecting samples
9092 if ( this . requestCount < 3 ) {
9193 this . requestCount ++
9294 try {
@@ -97,7 +99,7 @@ export abstract class BaseProvider implements ApiHandler {
9799 return apiCount
98100 } catch ( error ) {
99101 const localEstimate = await localCountTokens ( content , { useWorker : true } )
100- return localEstimate
102+ return Math . ceil ( localEstimate * this . tokenComparator . getSafetyFactor ( ) )
101103 }
102104 }
103105
@@ -131,6 +133,6 @@ export abstract class BaseProvider implements ApiHandler {
131133 }
132134 }
133135
134- return localEstimate
136+ return Math . ceil ( localEstimate * this . tokenComparator . getSafetyFactor ( ) )
135137 }
136138}
You can’t perform that action at this time.
0 commit comments