Skip to content

Commit 638abcd

Browse files
refactor: simplify function
1 parent c98a2c4 commit 638abcd

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)