Elffuss BraidHub

kikocis/continue public

3ff29c567dd0 · 523 BRawPermalink
1import { ILLM } from "../..";
2import { countTokensAsync } from "../../llm/countTokens";
3
4export async function throwIfFileExceedsHalfOfContext(
5 filepath: string,
6 content: string,
7 model: ILLM | null,
8) {
9 if (model) {
10 const tokens = await countTokensAsync(content, model.title);
11 const tokenLimit = model.contextLength / 2;
12 if (tokens > tokenLimit) {
13 throw new Error(
14 `File ${filepath} is too large (${tokens} tokens vs ${tokenLimit} token limit). Try another approach`,
15 );
16 }
17 }
18}