File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -104,14 +104,13 @@ export function approximateMaxTokenSize({
104104 /** The maximum number of tokens to generate in the reply. 1000 tokens are roughly 750 English words. */
105105 maxTokensInResponse ?: number
106106} ) {
107- // Not using GPT tokenizer here because it will explode the bundle size
108- // const tokens = encode(prompt)
109- const tokenSize = approximateTokenSize ( prompt )
110- const maxTokens = getModelContextSize ( modelName )
111-
112107 // Ensure that the sum of the prompt tokens and the response tokens
113108 // doesn't exceed the model's limit
114- const remainingTokens = maxTokens - tokenSize - maxTokensInResponse
109+ const remainingTokens
110+ = getModelContextSize ( modelName )
111+ // Not using GPT tokenizer here because it will explode the bundle size
112+ - approximateTokenSize ( prompt )
113+ - maxTokensInResponse
115114
116115 return Math . max ( 0 , remainingTokens )
117116}
You can’t perform that action at this time.
0 commit comments